Mercurial > hg > beaglert
diff core/Utilities.cpp @ 108:3068421c0737 ultra-staging
Merged default into ultra-staging
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 18 Aug 2015 00:35:15 +0100 |
parents | 8bd351ca8b46 |
children | f1012082f142 |
line wrap: on
line diff
--- a/core/Utilities.cpp Mon Jun 08 01:07:48 2015 +0100 +++ b/core/Utilities.cpp Tue Aug 18 00:35:15 2015 +0100 @@ -7,6 +7,84 @@ #include "../include/Utilities.h" +// analogReadFrame() +// +// Returns the value of the given analog input at the given frame number. +float analogReadFrame(BeagleRTContext *context, int frame, int channel) { + return context->analogIn[frame * context->analogChannels + channel]; +} + +// analogWriteFrame() +// +// Sets a given channel to a value for the current frame and, if persistent outputs are +// enabled, for all subsequent frames +void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value) { + if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { + for(unsigned int f = frame; f < context->analogFrames; f++) + context->analogOut[frame * context->analogChannels + channel] = value; + } + else + context->analogOut[frame * context->analogChannels + channel] = value; +} + +// analogWriteFrameOnce() +// +// Sets a given channel to a value for only the current frame +void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value) { + context->analogOut[frame * context->analogChannels + channel] = value; +} + +// digitalReadFrame() +// +// Returns the value of a given digital input at the given frame number +int digitalReadFrame(BeagleRTContext *context, int frame, int channel) { + return getBit(context->digital[frame], channel + 16); +} + +// digitalWriteFrame() +// +// Sets a given digital output channel to a value for the current frame and all subsequent frames +void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value) { + for(unsigned int f = frame; f < context->digitalFrames; f++) { + if(value) + context->digital[f] |= 1 << (channel + 16); + else + context->digital[f] &= ~(1 << (channel + 16)); + } +} + +// digitalWriteFrameOnce() +// +// Sets a given digital output channel to a value for the current frame only +void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value) { + if(value) + context->digital[frame] |= 1 << (channel + 16); + else + context->digital[frame] &= ~(1 << (channel + 16)); +} + +// pinModeFrame() +// +// Sets the direction of a digital pin for the current frame and all subsequent frames +void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode) { + for(unsigned int f = frame; f < context->digitalFrames; f++) { + if(mode == INPUT) + context->digital[f] |= (1 << channel); + else + context->digital[f] &= ~(1 << channel); + } +} + +// pinModeFrameOnce() +// +// Sets the direction of a digital pin for the current frame only +void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode) { + if(mode == INPUT) + context->digital[frame] |= (1 << channel); + else + context->digital[frame] &= ~(1 << channel); +} + // map() // // Scale an input value from one range to another. Works like its Wiring language equivalent.