Revision 1087
Fixed whitespace at the end of eeprom.h
Implemented binary orb settings
lights.c | ||
---|---|---|
23 | 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
24 | 24 |
**/ |
25 | 25 |
|
26 |
|
|
27 | 26 |
/** |
28 | 27 |
* @file ligths.c |
29 | 28 |
* @brief Orbs |
... | ... | |
31 | 30 |
* Implemenation for the orbs (tri-colored LEDs) |
32 | 31 |
* |
33 | 32 |
* @author Colony Project, CMU Robotics Club |
34 |
* @bug Colors are incorrect, seems to not work with wireless library
|
|
33 |
* @bug Unfinished
|
|
35 | 34 |
**/ |
36 | 35 |
|
37 | 36 |
/* |
38 | 37 |
lights.c |
39 |
Controls orb1 and orb2. Also contains the framework for a software PWM that may be used for servos in the future. |
|
38 |
Controls orb1 and orb2. Can be extended for a software PWM that may be used |
|
39 |
for servos in the future. |
|
40 | 40 |
|
41 | 41 |
author: CMU Robotics Club, Colony Project |
42 | 42 |
|
43 | 43 |
Change Log: |
44 |
2.4.07 - Aaron |
|
45 |
Revamped orb code so it works. Need to check interaction with rtc, and tweak some colors. |
|
46 |
|
|
47 |
2.1.07 - James |
|
48 |
Modified sort_buffer() to prune for repeats. PWM now uses orb_buf_size for the number of orb values in orb_time_arr[]. |
|
49 |
Changed sorting algorithm used in sort_buffer() to selection sort (faster). And it works now. |
|
50 |
|
|
51 |
1.25.07 - KWoo |
|
52 |
Deleted old FF+ code to make it cleaner. Commented code. This all works. Note however that if you ever plan to use the |
|
53 |
software PWM (which is this) you will need to change the implementation of orb_enable() and orb_disable() to not |
|
54 |
shutdown the PWM. |
|
55 |
|
|
44 |
3/31/2009 - Martin |
|
45 |
Rewritten from scratch (mostly), fixes some code duplication, long ISRs, |
|
46 |
bugs, unnecessary synchronized code, memory waste |
|
56 | 47 |
*/ |
57 | 48 |
|
58 | 49 |
#include "lights.h" |
50 |
#include <avr/interrupt.h> |
|
59 | 51 |
#include "dragonfly_lib.h" |
60 |
#include <avr/interrupt.h> |
|
61 | 52 |
|
62 |
#define ORB_RESET 1025 |
|
63 |
#define ORBPORT PORTC |
|
64 |
#define ORBDDR DDRC |
|
65 |
#define ORBMASK 0x77 |
|
66 | 53 |
|
67 |
/***** Port and Pin Definitions ****/ |
|
54 |
// ********* |
|
55 |
// ** I/O ** |
|
56 |
// ********* |
|
68 | 57 |
|
69 |
//Orb Ports and Registers |
|
70 |
#define ORB_PORT PORTC |
|
71 |
#define ORB_DDR DDRC |
|
58 |
#define NUM_ORBS 2 // Number or orbs |
|
59 |
#define NUM_COLORS 3 // Number of colors per orb |
|
72 | 60 |
|
73 |
//Orb Pins |
|
74 |
#define ORB1_RED 0x00 |
|
75 |
#define ORB1_GREEN 0x01 |
|
76 |
#define ORB1_BLUE 0x02 |
|
77 |
#define ORB2_RED 0x04 |
|
78 |
#define ORB2_GREEN 0x05 |
|
79 |
#define ORB2_BLUE 0x06 |
|
61 |
// Orb port |
|
62 |
#define ORBPORT PORTC |
|
63 |
#define ORBDDR DDRC |
|
80 | 64 |
|
65 |
// Orb pins |
|
66 |
#define ORB1_RED 0 |
|
67 |
#define ORB1_GREEN 1 |
|
68 |
#define ORB1_BLUE 2 |
|
69 |
#define ORB2_RED 4 |
|
70 |
#define ORB2_GREEN 5 |
|
71 |
#define ORB2_BLUE 6 |
|
81 | 72 |
|
82 |
#define ORB_COUNT 8 //please dont change this, or bad things might happen |
|
73 |
// *********** |
|
74 |
// ** Masks ** |
|
75 |
// *********** |
|
83 | 76 |
|
84 |
// an orb node |
|
85 |
struct ORB_NODE { |
|
86 |
uint8_t num; |
|
87 |
uint16_t angle; |
|
88 |
}; |
|
77 |
// Some useful bit masks. All of them are are calculated from the I/O |
|
78 |
// definitions above. The calculations should be done at compile time (even if |
|
79 |
// they are not, they are only executed once at startup). |
|
89 | 80 |
|
90 |
//the change in an orb |
|
91 |
struct ORB_CHANGE { |
|
92 |
uint16_t port_val; |
|
93 |
uint16_t split_time_period; |
|
94 |
}; |
|
81 |
// Masks for the individual LEDs |
|
82 |
#define orb1_red_mask _BV (ORB1_RED ) |
|
83 |
#define orb1_green_mask _BV (ORB1_GREEN) |
|
84 |
#define orb1_blue_mask _BV (ORB1_BLUE ) |
|
85 |
#define orb2_red_mask _BV (ORB2_RED ) |
|
86 |
#define orb2_green_mask _BV (ORB2_GREEN) |
|
87 |
#define orb2_blue_mask _BV (ORB2_BLUE ) |
|
95 | 88 |
|
96 |
// the status of an orb |
|
97 |
struct ORB_STATUS_STRUCT { |
|
98 |
struct ORB_NODE orbs[ORB_COUNT]; |
|
99 |
uint16_t orb_angles[ORB_COUNT]; |
|
100 |
struct ORB_CHANGE changes[ORB_COUNT+1]; |
|
101 |
uint8_t change_count; |
|
102 |
uint8_t new_angles; |
|
103 |
uint8_t current_orb; |
|
89 |
// Mask for all LEDs |
|
90 |
const uint8_t all_orbs_mask= |
|
91 |
orb1_red_mask | orb1_green_mask | orb1_blue_mask | |
|
92 |
orb2_red_mask | orb2_green_mask | orb2_blue_mask; |
|
104 | 93 |
|
105 |
} ORB_STATUS; |
|
94 |
// Mask for the individual LEDs, organized as an array for programmatic access. |
|
95 |
// The layout of this array is orb_mask[orb_num, color_num] |
|
96 |
const uint8_t orb_mask[2][3]= |
|
97 |
{ |
|
98 |
{ orb1_red_mask, orb1_green_mask, orb1_blue_mask }, |
|
99 |
{ orb2_red_mask, orb2_green_mask, orb2_blue_mask } |
|
100 |
}; |
|
106 | 101 |
|
107 |
void orb_sort(void); |
|
108 |
void orb_setup_pulse(void); |
|
109 | 102 |
|
110 |
SIGNAL (SIG_OUTPUT_COMPARE3C){ |
|
103 |
// ******************** |
|
104 |
// ** Initialization ** |
|
105 |
// ******************** |
|
111 | 106 |
|
112 |
//pull the correct ones down |
|
113 |
ORBPORT &= (~ORBMASK)|(ORB_STATUS.changes[ORB_STATUS.current_orb].port_val); |
|
114 |
|
|
115 |
++ORB_STATUS.current_orb; //now look at next orb transition |
|
116 |
|
|
117 |
if (ORB_STATUS.current_orb < ORB_STATUS.change_count) { //if it isnt the end... |
|
118 |
|
|
119 |
//setup timer for next pull down |
|
120 |
OCR3C = TCNT3+ORB_STATUS.changes[ORB_STATUS.current_orb].split_time_period; |
|
121 |
|
|
122 |
} |
|
123 |
else { //we are done with these pulses |
|
124 |
orb_setup_pulse(); |
|
125 |
} |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
//sets a channel to a value |
|
131 |
void orb_set_angle(int orb, int angle) { |
|
132 |
uint8_t mysreg; |
|
133 |
|
|
134 |
orb=orb&0x07; //only have 8 |
|
135 |
angle=angle&0xff; //only accept 0-255 |
|
136 |
angle=255-angle; //inverse intensity |
|
137 |
angle=angle<<2; //scale up so that we dont run it too often |
|
138 |
angle+=3; //0 values dont really work |
|
139 |
if (ORB_STATUS.orb_angles[orb] != angle) { //if the angle has changed |
|
140 |
mysreg=SREG; |
|
141 |
cli(); //disable interrupts |
|
142 |
ORB_STATUS.orb_angles[orb] = angle; //update angle |
|
143 |
ORB_STATUS.new_angles = 1; |
|
144 |
SREG=mysreg; //put interrupt status back |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
|
|
149 |
void orb_sort(void) { |
|
150 |
int done = 0, i; |
|
151 |
|
|
152 |
while (! done) { |
|
153 |
done = 1; |
|
154 |
|
|
155 |
for (i = 0; i < ORB_COUNT - 1; ++i) { //loop through all |
|
156 |
|
|
157 |
//if they are out of order, swap them |
|
158 |
if (ORB_STATUS.orbs[i].angle > ORB_STATUS.orbs[i+1].angle) { |
|
159 |
ORB_STATUS.orbs[i].angle ^= ORB_STATUS.orbs[i+1].angle; |
|
160 |
ORB_STATUS.orbs[i+1].angle ^= ORB_STATUS.orbs[i].angle; |
|
161 |
ORB_STATUS.orbs[i].angle ^= ORB_STATUS.orbs[i+1].angle; |
|
162 |
|
|
163 |
ORB_STATUS.orbs[i].num ^= ORB_STATUS.orbs[i+1].num; |
|
164 |
ORB_STATUS.orbs[i+1].num ^= ORB_STATUS.orbs[i].num; |
|
165 |
ORB_STATUS.orbs[i].num ^= ORB_STATUS.orbs[i+1].num; |
|
166 |
|
|
167 |
done = 0; |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
//calculate the split times |
|
174 |
void orb_setup_pulse(void) { |
|
175 |
int i; |
|
176 |
uint16_t my_port; |
|
177 |
uint16_t sum = 0; |
|
178 |
uint16_t split_time; |
|
179 |
|
|
180 |
my_port = 0xff; //all on |
|
181 |
|
|
182 |
if (ORB_STATUS.new_angles) { |
|
183 |
|
|
184 |
ORB_STATUS.change_count = 0; |
|
185 |
for (i = 0; i < ORB_COUNT; ++i) { //get the new values |
|
186 |
ORB_STATUS.orbs[i].angle = ORB_STATUS.orb_angles[ORB_STATUS.orbs[i].num]; |
|
187 |
} |
|
188 |
|
|
189 |
orb_sort(); //sort them |
|
190 |
ORB_STATUS.new_angles = 0; |
|
191 |
|
|
192 |
for (i = 0; i < ORB_COUNT; ++i) { //calculate split times |
|
193 |
split_time = ORB_STATUS.orbs[i].angle - sum; |
|
194 |
my_port &= ~_BV(ORB_STATUS.orbs[i].num); |
|
195 |
|
|
196 |
for (; i < ORB_COUNT - 1 && ORB_STATUS.orbs[i].angle == ORB_STATUS.orbs[i+1].angle; ++i) { |
|
197 |
my_port &= ~_BV(ORB_STATUS.orbs[i+1].num); //look for doups |
|
198 |
} |
|
199 |
|
|
200 |
ORB_STATUS.changes[ORB_STATUS.change_count].port_val = my_port; //which pins are low |
|
201 |
ORB_STATUS.changes[ORB_STATUS.change_count].split_time_period = split_time; |
|
202 |
|
|
203 |
++ORB_STATUS.change_count; |
|
204 |
|
|
205 |
sum += split_time; |
|
206 |
} |
|
207 |
|
|
208 |
ORB_STATUS.changes[ORB_STATUS.change_count].port_val = my_port; |
|
209 |
ORB_STATUS.changes[ORB_STATUS.change_count].split_time_period = ORB_RESET - sum; //get a constant period |
|
210 |
|
|
211 |
++ORB_STATUS.change_count; |
|
212 |
|
|
213 |
} |
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
ORB_STATUS.current_orb = 0; |
|
218 |
|
|
219 |
ORBPORT |= ORBMASK; //start with all high |
|
220 |
OCR3C = TCNT3 + ORB_STATUS.changes[0].split_time_period; //wait for first split |
|
221 |
|
|
222 |
} |
|
223 |
|
|
224 | 107 |
/** |
225 |
* @defgroup orbs Orbs |
|
226 |
* @brief Functions for controlling the color of the orbs. |
|
227 |
* |
|
228 |
* Functions for controlling the color and lighting of the orbs. |
|
229 |
* |
|
230 |
* @{ |
|
231 |
**/ |
|
232 |
|
|
233 |
/** |
|
234 | 108 |
* Initializes the PWM for Orb control. This must be called before |
235 | 109 |
* the orbs are used for them to function. |
236 | 110 |
**/ |
237 |
void orb_init() |
|
238 |
{ |
|
239 |
int i; |
|
240 |
uint8_t mysreg; |
|
241 |
|
|
242 |
ORBDDR |= ORBMASK; //all outputs |
|
243 |
|
|
244 |
mysreg=SREG; |
|
245 |
cli(); //turn off interrupts for now |
|
111 |
void orb_init () |
|
112 |
{ |
|
113 |
// Enable the output ports and turn off the LEDs |
|
114 |
ORBDDR |= all_orbs_mask; |
|
115 |
ORBPORT &= ~all_orbs_mask; |
|
246 | 116 |
|
247 |
//init everything |
|
117 |
// Set all orbs to "off" |
|
118 |
orb_set (0, 0, 0); |
|
248 | 119 |
|
249 |
for (i = 0; i < ORB_COUNT; ++i) { |
|
250 |
ORB_STATUS.orbs[i].num = i; |
|
251 |
ORB_STATUS.orbs[i].angle = 1023; //127 is a pretty stupid start angle, but oh well |
|
252 |
ORB_STATUS.orb_angles[i] = 1023; |
|
253 |
} |
|
120 |
// uint16_t i; |
|
121 |
// uint8_t mysreg; |
|
122 |
// |
|
123 |
// mysreg=SREG; |
|
124 |
// cli(); //turn off interrupts for now |
|
125 |
// |
|
126 |
// //init everything |
|
127 |
// |
|
128 |
// for (i = 0; i < ORB_COUNT; ++i) { |
|
129 |
// ORB_STATUS.orbs[i].num = i; |
|
130 |
// ORB_STATUS.orbs[i].angle = 1023; //127 is a pretty stupid start angle, but oh well |
|
131 |
// ORB_STATUS.orb_angles[i] = 1023; |
|
132 |
// } |
|
133 |
// |
|
134 |
// ORB_STATUS.new_angles = 1; |
|
135 |
// ORB_STATUS.change_count = 0; |
|
136 |
// |
|
137 |
// //init timer3 |
|
138 |
// TCCR3A = 0; |
|
139 |
// TCCR3B = _BV(CS31); //prescale = 8 |
|
140 |
// TCCR3C = 0; |
|
141 |
// ETIMSK |= _BV(OCIE3C); //turn on oc3c interrupt |
|
142 |
// OCR3C = TCNT3+ORB_RESET; |
|
143 |
// |
|
144 |
// SREG=mysreg; |
|
145 |
} |
|
146 |
// |
|
254 | 147 |
|
255 |
ORB_STATUS.new_angles = 1; |
|
256 |
ORB_STATUS.change_count = 0; |
|
148 |
// ************************ |
|
149 |
// ** Setting RGB colors ** |
|
150 |
// ************************ |
|
257 | 151 |
|
258 |
//init timer3 |
|
259 |
TCCR3A = 0; |
|
260 |
TCCR3B = _BV(CS31); //prescale = 8 |
|
261 |
TCCR3C = 0; |
|
262 |
ETIMSK |= _BV(OCIE3C); //turn on oc3c interrupt |
|
263 |
OCR3C = TCNT3+ORB_RESET; |
|
264 |
|
|
265 |
SREG=mysreg; |
|
152 |
static void orb_n_set (uint8_t num, uint8_t red, uint8_t green, uint8_t blue) |
|
153 |
{ |
|
154 |
// FIXME implement PWM code (this is only binary on/off) |
|
155 |
// FIXME Synchronization |
|
156 |
|
|
157 |
// Oh, and of course the outputs are inverted. |
|
158 |
if (!red) ORBPORT|=orb_mask[num][0]; else ORBPORT&=~orb_mask[num][0]; |
|
159 |
if (!green) ORBPORT|=orb_mask[num][1]; else ORBPORT&=~orb_mask[num][1]; |
|
160 |
if (!blue) ORBPORT|=orb_mask[num][2]; else ORBPORT&=~orb_mask[num][2]; |
|
266 | 161 |
} |
267 | 162 |
|
268 | 163 |
/** |
269 |
* Set both orbs to the color specified. orb_init must
|
|
270 |
* be called before this function may be used.
|
|
164 |
* Set orb1 to the color specified. orb_init must be called before this function
|
|
165 |
* may be used. |
|
271 | 166 |
* |
272 |
* @param red_led the red component of the color
|
|
273 |
* @param green_led the green component of the color
|
|
274 |
* @param blue_led the blue component of the color
|
|
167 |
* @param red the red component of the color |
|
168 |
* @param green the green component of the color |
|
169 |
* @param blue the blue component of the color |
|
275 | 170 |
* |
276 | 171 |
* @see orb_init |
277 | 172 |
**/ |
278 |
void orb_set(unsigned char red_led, unsigned char green_led, unsigned char blue_led) { |
|
279 |
orb1_set(red_led,green_led,blue_led); |
|
280 |
orb2_set(red_led,green_led,blue_led); |
|
281 |
|
|
173 |
void orb1_set (uint8_t red, uint8_t green, uint8_t blue) |
|
174 |
{ |
|
175 |
orb_n_set (0, red, green, blue); |
|
282 | 176 |
} |
283 | 177 |
|
284 | 178 |
/** |
285 |
* Set orb1 to the color specified. orb_init must
|
|
286 |
* be called before this function may be used.
|
|
179 |
* Set orb2 to the color specified. orb_init must be called before this function
|
|
180 |
* may be used. |
|
287 | 181 |
* |
288 | 182 |
* @param red_led the red component of the color |
289 | 183 |
* @param green_led the green component of the color |
... | ... | |
291 | 185 |
* |
292 | 186 |
* @see orb_init |
293 | 187 |
**/ |
294 |
void orb1_set(unsigned char red_led, unsigned char green_led, unsigned char blue_led) { |
|
295 |
orb_set_angle(0,red_led); |
|
296 |
orb_set_angle(1,green_led); |
|
297 |
orb_set_angle(2,blue_led); |
|
188 |
void orb2_set (uint8_t red, uint8_t green, uint8_t blue) |
|
189 |
{ |
|
190 |
orb_n_set (1, red, green, blue); |
|
298 | 191 |
} |
299 | 192 |
|
300 | 193 |
/** |
301 |
* Set orb2 to the color specified. orb_init must
|
|
302 |
* be called before this function may be used.
|
|
194 |
* Set both orbs to the color specified. orb_init must be called before this
|
|
195 |
* function may be used. |
|
303 | 196 |
* |
304 | 197 |
* @param red_led the red component of the color |
305 | 198 |
* @param green_led the green component of the color |
306 | 199 |
* @param blue_led the blue component of the color |
307 | 200 |
* |
308 |
* @see orb_init |
|
201 |
* @see orb_init, orb1_set, orb2_set
|
|
309 | 202 |
**/ |
310 |
void orb2_set(unsigned char red_led, unsigned char green_led, unsigned char blue_led) {
|
|
311 |
orb_set_angle(4,red_led);
|
|
312 |
orb_set_angle(5,green_led);
|
|
313 |
orb_set_angle(6,blue_led);
|
|
203 |
void orb_set (uint8_t red, uint8_t green, uint8_t blue)
|
|
204 |
{
|
|
205 |
orb1_set (red, green, blue);
|
|
206 |
orb2_set (red, green, blue);
|
|
314 | 207 |
} |
315 | 208 |
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
213 |
|
|
214 |
//#define ORB_RESET 1025 |
|
215 |
//#define ORBMASK 0x77 |
|
216 |
// |
|
217 |
///***** Port and Pin Definitions ****/ |
|
218 |
// |
|
219 |
// |
|
220 |
//// an orb node |
|
221 |
//struct ORB_NODE { |
|
222 |
// uint8_t num; |
|
223 |
// uint16_t angle; |
|
224 |
//}; |
|
225 |
// |
|
226 |
//the change in an orb |
|
227 |
//struct ORB_CHANGE { |
|
228 |
// uint16_t port_val; |
|
229 |
// uint16_t split_time_period; |
|
230 |
//}; |
|
231 |
// |
|
232 |
//// the status of an orb |
|
233 |
//struct ORB_STATUS_STRUCT { |
|
234 |
// struct ORB_NODE orbs[ORB_COUNT]; |
|
235 |
// uint16_t orb_angles[ORB_COUNT]; |
|
236 |
// struct ORB_CHANGE changes[ORB_COUNT+1]; |
|
237 |
// uint8_t change_count; |
|
238 |
// uint8_t new_angles; |
|
239 |
// uint8_t current_orb; |
|
240 |
// |
|
241 |
//} ORB_STATUS; |
|
242 |
// |
|
243 |
//void orb_sort(void); |
|
244 |
//void orb_setup_pulse(void); |
|
245 |
// |
|
246 |
//SIGNAL (SIG_OUTPUT_COMPARE3C){ |
|
247 |
// |
|
248 |
// //pull the correct ones down |
|
249 |
// ORBPORT &= (~ORBMASK)|(ORB_STATUS.changes[ORB_STATUS.current_orb].port_val); |
|
250 |
// |
|
251 |
// ++ORB_STATUS.current_orb; //now look at next orb transition |
|
252 |
// |
|
253 |
// if (ORB_STATUS.current_orb < ORB_STATUS.change_count) { //if it isnt the end... |
|
254 |
// |
|
255 |
// //setup timer for next pull down |
|
256 |
// OCR3C = TCNT3+ORB_STATUS.changes[ORB_STATUS.current_orb].split_time_period; |
|
257 |
// |
|
258 |
// } |
|
259 |
// else { //we are done with these pulses |
|
260 |
// orb_setup_pulse(); |
|
261 |
// } |
|
262 |
// |
|
263 |
//} |
|
264 |
// |
|
265 |
// |
|
266 |
////sets a channel to a value |
|
267 |
//void orb_set_angle(uint16_t orb, uint16_t angle) { |
|
268 |
// uint8_t mysreg; |
|
269 |
// |
|
270 |
// orb=orb&0x07; //only have 8 |
|
271 |
// angle=angle&0xff; //only accept 0-255 |
|
272 |
// angle=255-angle; //inverse intensity |
|
273 |
// angle=angle<<2; //scale up so that we dont run it too often |
|
274 |
// angle+=3; //0 values dont really work |
|
275 |
// if (ORB_STATUS.orb_angles[orb] != angle) { //if the angle has changed |
|
276 |
// mysreg=SREG; |
|
277 |
// cli(); //disable interrupts |
|
278 |
// ORB_STATUS.orb_angles[orb] = angle; //update angle |
|
279 |
// ORB_STATUS.new_angles = 1; |
|
280 |
// SREG=mysreg; //put interrupt status back |
|
281 |
// } |
|
282 |
//} |
|
283 |
// |
|
284 |
// |
|
285 |
//void orb_sort(void) { |
|
286 |
// uint16_t done = 0, i; |
|
287 |
// |
|
288 |
// while (! done) { |
|
289 |
// done = 1; |
|
290 |
// |
|
291 |
// for (i = 0; i < ORB_COUNT - 1; ++i) { //loop through all |
|
292 |
// |
|
293 |
// //if they are out of order, swap them |
|
294 |
// if (ORB_STATUS.orbs[i].angle > ORB_STATUS.orbs[i+1].angle) { |
|
295 |
// ORB_STATUS.orbs[i].angle ^= ORB_STATUS.orbs[i+1].angle; |
|
296 |
// ORB_STATUS.orbs[i+1].angle ^= ORB_STATUS.orbs[i].angle; |
|
297 |
// ORB_STATUS.orbs[i].angle ^= ORB_STATUS.orbs[i+1].angle; |
|
298 |
// |
|
299 |
// ORB_STATUS.orbs[i].num ^= ORB_STATUS.orbs[i+1].num; |
|
300 |
// ORB_STATUS.orbs[i+1].num ^= ORB_STATUS.orbs[i].num; |
|
301 |
// ORB_STATUS.orbs[i].num ^= ORB_STATUS.orbs[i+1].num; |
|
302 |
// |
|
303 |
// done = 0; |
|
304 |
// } |
|
305 |
// } |
|
306 |
// } |
|
307 |
//} |
|
308 |
// |
|
309 |
////calculate the split times |
|
310 |
//void orb_setup_pulse(void) { |
|
311 |
// uint16_t i; |
|
312 |
// uint16_t my_port; |
|
313 |
// uint16_t sum = 0; |
|
314 |
// uint16_t split_time; |
|
315 |
// |
|
316 |
// my_port = 0xff; //all on |
|
317 |
// |
|
318 |
// if (ORB_STATUS.new_angles) { |
|
319 |
// |
|
320 |
// ORB_STATUS.change_count = 0; |
|
321 |
// for (i = 0; i < ORB_COUNT; ++i) { //get the new values |
|
322 |
// ORB_STATUS.orbs[i].angle = ORB_STATUS.orb_angles[ORB_STATUS.orbs[i].num]; |
|
323 |
// } |
|
324 |
// |
|
325 |
// orb_sort(); //sort them |
|
326 |
// ORB_STATUS.new_angles = 0; |
|
327 |
// |
|
328 |
// for (i = 0; i < ORB_COUNT; ++i) { //calculate split times |
|
329 |
// split_time = ORB_STATUS.orbs[i].angle - sum; |
|
330 |
// my_port &= ~_BV(ORB_STATUS.orbs[i].num); |
|
331 |
// |
|
332 |
// for (; i < ORB_COUNT - 1 && ORB_STATUS.orbs[i].angle == ORB_STATUS.orbs[i+1].angle; ++i) { |
|
333 |
// my_port &= ~_BV(ORB_STATUS.orbs[i+1].num); //look for doups |
|
334 |
// } |
|
335 |
// |
|
336 |
// ORB_STATUS.changes[ORB_STATUS.change_count].port_val = my_port; //which pins are low |
|
337 |
// ORB_STATUS.changes[ORB_STATUS.change_count].split_time_period = split_time; |
|
338 |
// |
|
339 |
// ++ORB_STATUS.change_count; |
|
340 |
// |
|
341 |
// sum += split_time; |
|
342 |
// } |
|
343 |
// |
|
344 |
// ORB_STATUS.changes[ORB_STATUS.change_count].port_val = my_port; |
|
345 |
// ORB_STATUS.changes[ORB_STATUS.change_count].split_time_period = ORB_RESET - sum; //get a constant period |
|
346 |
// |
|
347 |
// ++ORB_STATUS.change_count; |
|
348 |
// |
|
349 |
// } |
|
350 |
// |
|
351 |
// |
|
352 |
// |
|
353 |
// ORB_STATUS.current_orb = 0; |
|
354 |
// |
|
355 |
// ORBPORT |= ORBMASK; //start with all high |
|
356 |
// OCR3C = TCNT3 + ORB_STATUS.changes[0].split_time_period; //wait for first split |
|
357 |
// |
|
358 |
//} |
|
359 |
// |
|
360 |
///** |
|
361 |
// * @defgroup orbs Orbs |
|
362 |
// * @brief Functions for controlling the color of the orbs. |
|
363 |
// * |
|
364 |
// * Functions for controlling the color and lighting of the orbs. |
|
365 |
// * |
|
366 |
// * @{ |
|
367 |
// **/ |
|
368 |
// |
|
369 |
|
|
316 | 370 |
/** |
317 | 371 |
* Set both orbs to the specified color. This function |
318 | 372 |
* is intended to be used with the predefined |
... | ... | |
323 | 377 |
* |
324 | 378 |
* @see orb_init |
325 | 379 |
**/ |
326 |
void orb_set_color(int col)
|
|
380 |
void orb_set_color(uint8_t col)
|
|
327 | 381 |
{ |
328 |
int red, green, blue;
|
|
329 |
|
|
330 |
red = ((col & 0xE0) >> 5) * 36; |
|
331 |
green = ((col & 0x1C) >> 2) * 36; |
|
332 |
blue = (col & 0x03) * 85; |
|
333 |
|
|
334 |
orb_set(red, green, blue); |
|
382 |
// uint16_t red, green, blue;
|
|
383 |
// |
|
384 |
// red = ((col & 0xE0) >> 5) * 36;
|
|
385 |
// green = ((col & 0x1C) >> 2) * 36;
|
|
386 |
// blue = (col & 0x03) * 85;
|
|
387 |
// |
|
388 |
// orb_set(red, green, blue);
|
|
335 | 389 |
} |
336 | 390 |
|
337 | 391 |
/** |
... | ... | |
344 | 398 |
* |
345 | 399 |
* @see orb_init |
346 | 400 |
**/ |
347 |
void orb1_set_color(int col)
|
|
401 |
void orb1_set_color(uint8_t col)
|
|
348 | 402 |
{ |
349 |
int red, green, blue;
|
|
350 |
|
|
351 |
red = ((col & 0xE0) >> 5) * 36; |
|
352 |
green = ((col & 0x1C) >> 2) * 36; |
|
353 |
blue = (col & 0x03) * 85; |
|
354 |
|
|
355 |
orb1_set(red, green, blue); |
|
403 |
// uint16_t red, green, blue;
|
|
404 |
// |
|
405 |
// red = ((col & 0xE0) >> 5) * 36;
|
|
406 |
// green = ((col & 0x1C) >> 2) * 36;
|
|
407 |
// blue = (col & 0x03) * 85;
|
|
408 |
// |
|
409 |
// orb1_set(red, green, blue);
|
|
356 | 410 |
} |
357 | 411 |
|
358 | 412 |
/** |
... | ... | |
365 | 419 |
* |
366 | 420 |
* @see orb_init |
367 | 421 |
**/ |
368 |
void orb2_set_color(int col)
|
|
422 |
void orb2_set_color(uint8_t col)
|
|
369 | 423 |
{ |
370 |
int red, green, blue;
|
|
371 |
|
|
372 |
red = ((col & 0xE0) >> 5) * 36; |
|
373 |
green = ((col & 0x1C) >> 2) * 36; |
|
374 |
blue = (col & 0x03) * 85; |
|
375 |
|
|
376 |
orb2_set(red, green, blue); |
|
424 |
// uint16_t red, green, blue;
|
|
425 |
// |
|
426 |
// red = ((col & 0xE0) >> 5) * 36;
|
|
427 |
// green = ((col & 0x1C) >> 2) * 36;
|
|
428 |
// blue = (col & 0x03) * 85;
|
|
429 |
// |
|
430 |
// orb2_set(red, green, blue);
|
|
377 | 431 |
} |
378 | 432 |
|
379 | 433 |
//DOES THIS WORK? |
... | ... | |
388 | 442 |
**/ |
389 | 443 |
void orb_disable() |
390 | 444 |
{ |
391 |
TCCR3B &= 0; //Turn off everything |
|
392 |
ORB_PORT |= _BV(ORB1_RED); |
|
393 |
ORB_PORT |= _BV(ORB1_GREEN); |
|
394 |
ORB_PORT |= _BV(ORB1_BLUE); |
|
395 |
ORB_PORT |= _BV(ORB2_RED); |
|
396 |
ORB_PORT |= _BV(ORB2_GREEN); |
|
397 |
ORB_PORT |= _BV(ORB2_BLUE); |
|
445 |
// TCCR3B &= 0; //Turn off everything
|
|
446 |
// ORB_PORT |= _BV(ORB1_RED);
|
|
447 |
// ORB_PORT |= _BV(ORB1_GREEN);
|
|
448 |
// ORB_PORT |= _BV(ORB1_BLUE);
|
|
449 |
// ORB_PORT |= _BV(ORB2_RED);
|
|
450 |
// ORB_PORT |= _BV(ORB2_GREEN);
|
|
451 |
// ORB_PORT |= _BV(ORB2_BLUE);
|
|
398 | 452 |
} |
399 | 453 |
|
400 | 454 |
//DOES THIS WORK? |
... | ... | |
406 | 460 |
**/ |
407 | 461 |
void orb_enable() |
408 | 462 |
{ |
409 |
// TCCR0 |= _BV(COM01) | _BV(COM00) | _BV(WGM00) | _BV(CS01); //Toggle OC Pin on match, FAST PWM Mode, clock/8 |
|
410 |
TCCR3B =_BV(CS31); |
|
463 |
//// TCCR0 |= _BV(COM01) | _BV(COM00) | _BV(WGM00) | _BV(CS01); //Toggle OC Pin on match, FAST PWM Mode, clock/8
|
|
464 |
// TCCR3B =_BV(CS31);
|
|
411 | 465 |
} |
412 | 466 |
|
413 | 467 |
/** @} **/ //end group |
Also available in: Unified diff