1 /* $Id: main.c,v 1.8 2010/07/25 20:40:44 simimeie Exp $
2 * Main file for the HaWo moodlight.
3 * This is the main file that glues it all together. It also contains all
4 * functionality that is too small to require an extra file.
5 * (C) Michael "Fox" Meier 2010
9 #include <avr/interrupt.h>
11 #include <avr/eeprom.h>
12 #include <avr/power.h>
13 #include <avr/sleep.h>
16 #include <util/delay.h>
20 #include "ircontrol.h"
22 #include "ledframing.h"
24 #include "eepromdata.h"
27 #define IRSTATE_GREEN 2
28 #define IRSTATE_BLUE 3
29 #define IRSTATE_WHITE 4
35 /* Load settings from EEPROM */
36 ledpwm_bri = eeprom_read_byte(&ee_defledbrightness);
38 /* Initialize stuff */
48 /* Prepare sleep mode */
49 //set_sleep_mode(SLEEP_MODE_IDLE);
52 /* All set up, enable interrupts and go. */
55 while (1) { /* We should never exit */
57 uint8_t k = ircontrol_getlastcommand();
61 if (irstate == IRSTATE_RED) {
62 if (ledpwm_re < 0xff) { ledpwm_re++; }
63 } else if (irstate == IRSTATE_GREEN) {
64 if (ledpwm_gr < 0xff) { ledpwm_gr++; }
65 } else if (irstate == IRSTATE_BLUE) {
66 if (ledpwm_bl < 0xff) { ledpwm_bl++; }
68 if (ledpwm_bri < 0xff) { ledpwm_bri++; }
71 case 0x01: /* "Down" */
72 if (irstate == IRSTATE_RED) {
73 if (ledpwm_re > 0) { ledpwm_re--; }
74 } else if (irstate == IRSTATE_GREEN) {
75 if (ledpwm_gr > 0) { ledpwm_gr--; }
76 } else if (irstate == IRSTATE_BLUE) {
77 if (ledpwm_bl > 0) { ledpwm_bl--; }
79 if (ledpwm_bri > 0) { ledpwm_bri--; }
82 case 0x02: /* "Off" */
89 if (irstate == IRSTATE_RED) {
90 ledpwm_re = 0xff; ledpwm_gr = 0; ledpwm_bl = 0;
93 irstate = IRSTATE_RED;
96 case 0x05: /* Green */
97 if (irstate == IRSTATE_GREEN) {
98 ledpwm_re = 0; ledpwm_gr = 0xff; ledpwm_bl = 0;
101 irstate = IRSTATE_GREEN;
104 case 0x06: /* Blue */
105 if (irstate == IRSTATE_BLUE) {
106 ledpwm_re = 0; ledpwm_gr = 0; ledpwm_bl = 0xff;
109 irstate = IRSTATE_BLUE;
112 case 0x07: /* White */
113 if (irstate == IRSTATE_WHITE) {
114 ledpwm_re = 0xff; ledpwm_gr = 0xff; ledpwm_bl = 0xff;
117 irstate = IRSTATE_WHITE;
120 case 0x08: /* Dark orange */
121 ledpwm_re = 0xff; ledpwm_gr = 0x40; ledpwm_bl = 0x00;
124 case 0x09: /* greenish cyan */
125 ledpwm_re = 0x00; ledpwm_gr = 0xff; ledpwm_bl = 0x80;
128 case 0x0a: /* dark blue */
129 ledpwm_re = 0x20; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
132 case 0x0c: /* orange */
133 ledpwm_re = 0xff; ledpwm_gr = 0x80; ledpwm_bl = 0x00;
136 case 0x0d: /* cyan */
137 ledpwm_re = 0x00; ledpwm_gr = 0xff; ledpwm_bl = 0xff;
140 case 0x0e: /* dark orchid 2 */
141 ledpwm_re = 0x50; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
144 case 0x10: /* bright orange */
145 ledpwm_re = 0xff; ledpwm_gr = 0xc0; ledpwm_bl = 0x00;
148 case 0x11: /* blueish cyan */
149 ledpwm_re = 0x00; ledpwm_gr = 0xa0; ledpwm_bl = 0xff;
152 case 0x12: /* dark orchid */
153 ledpwm_re = 0xc0; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
156 case 0x14: /* yellow */
157 ledpwm_re = 0xff; ledpwm_gr = 0xff; ledpwm_bl = 0x00;
160 case 0x15: /* blueerish cyan */
161 ledpwm_re = 0x00; ledpwm_gr = 0x60; ledpwm_bl = 0xff;
164 case 0x16: /* violet */
165 ledpwm_re = 0xff; ledpwm_gr = 0x00; ledpwm_bl = 0xff;
169 ledpwm_set(ledpwm_re, ledpwm_gr, ledpwm_bl, ledpwm_bri);
172 console_printhex8(i);
173 ledpwm_setled(LEDPWM_REDLED, i);
174 ledpwm_setled(LEDPWM_GREENLED, i+128);
175 ledpwm_setled(LEDPWM_BLUELED, 255-i);