Mercurial > hg > beaglert
comparison core/Utilities.cpp @ 67:472e892c6e41
Merge newapi into default
author | Andrew McPherson <a.mcpherson@qmul.ac.uk> |
---|---|
date | Fri, 17 Jul 2015 15:28:18 +0100 |
parents | a6d223473ea2 |
children | d837fb676977 |
comparison
equal
deleted
inserted
replaced
21:0d80ff9e2227 | 67:472e892c6e41 |
---|---|
4 * Created on: Oct 27, 2014 | 4 * Created on: Oct 27, 2014 |
5 * Author: parallels | 5 * Author: parallels |
6 */ | 6 */ |
7 | 7 |
8 #include "../include/Utilities.h" | 8 #include "../include/Utilities.h" |
9 | |
10 // analogReadFrame() | |
11 // | |
12 // Returns the value of the given analog input at the given frame number. | |
13 float analogReadFrame(BeagleRTContext *context, int frame, int channel) { | |
14 return context->analogIn[frame * context->analogChannels + channel]; | |
15 } | |
16 | |
17 // analogWriteFrame() | |
18 // | |
19 // Sets a given channel to a value for the current frame and, if persistent outputs are | |
20 // enabled, for all subsequent frames | |
21 void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value) { | |
22 if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { | |
23 for(unsigned int f = frame; f < context->analogFrames; f++) | |
24 context->analogOut[frame * context->analogChannels + channel] = value; | |
25 } | |
26 else | |
27 context->analogOut[frame * context->analogChannels + channel] = value; | |
28 } | |
29 | |
30 // analogWriteFrameOnce() | |
31 // | |
32 // Sets a given channel to a value for only the current frame | |
33 void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value) { | |
34 context->analogOut[frame * context->analogChannels + channel] = value; | |
35 } | |
36 | |
37 // digitalReadFrame() | |
38 // | |
39 // Returns the value of a given digital input at the given frame number | |
40 int digitalReadFrame(BeagleRTContext *context, int frame, int channel) { | |
41 return getBit(context->digital[frame], channel + 16); | |
42 } | |
43 | |
44 // digitalWriteFrame() | |
45 // | |
46 // Sets a given digital output channel to a value for the current frame and all subsequent frames | |
47 void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value) { | |
48 for(unsigned int f = frame; f < context->digitalFrames; f++) { | |
49 if(value) | |
50 context->digital[f] |= 1 << (channel + 16); | |
51 else | |
52 context->digital[f] &= ~(1 << (channel + 16)); | |
53 } | |
54 } | |
55 | |
56 // digitalWriteFrameOnce() | |
57 // | |
58 // Sets a given digital output channel to a value for the current frame only | |
59 void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value) { | |
60 if(value) | |
61 context->digital[frame] |= 1 << (channel + 16); | |
62 else | |
63 context->digital[frame] &= ~(1 << (channel + 16)); | |
64 } | |
65 | |
66 // pinModeFrame() | |
67 // | |
68 // Sets the direction of a digital pin for the current frame and all subsequent frames | |
69 void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode) { | |
70 for(unsigned int f = frame; f < context->digitalFrames; f++) { | |
71 if(mode) | |
72 context->digital[f] |= (1 << channel); | |
73 else | |
74 context->digital[f] &= ~(1 << channel); | |
75 } | |
76 } | |
77 | |
78 // pinModeFrameOnce() | |
79 // | |
80 // Sets the direction of a digital pin for the current frame only | |
81 void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode) { | |
82 if(mode) | |
83 context->digital[frame] |= (1 << channel); | |
84 else | |
85 context->digital[frame] &= ~(1 << channel); | |
86 } | |
9 | 87 |
10 // map() | 88 // map() |
11 // | 89 // |
12 // Scale an input value from one range to another. Works like its Wiring language equivalent. | 90 // Scale an input value from one range to another. Works like its Wiring language equivalent. |
13 // x is the value to scale; in_min and in_max are the input range; out_min and out_max | 91 // x is the value to scale; in_min and in_max are the input range; out_min and out_max |