conrad rsl366t funksteckdosen
[svn42.git] / rf433ctl / rf433ctl.pde
1 #include <avr/io.h>
2 #include <avr/interrupt.h>
3 #include <inttypes.h>
4 #include <OneWire.h>
5 #include <DallasTemperature.h>
6 #include <IRremote.h>
7
8 //********************************************************************//
9
10 #define RF_DATA_OUT_PIN 13
11 #define IR_MOVEMENT_PIN 9
12 #define IR_MOVEMENT_PIN2 12
13 #define ONE_WIRE_PIN 8
14 #define PANIC_BUTTON_PIN 7
15 #define PANICLED_PWM_PIN 6
16 #define BLUELED_PWM_PIN 11
17 #define PHOTO_ANALOGPIN 0
18 //movement is reported if during IR_SAMPLE_DURATION at least IR_TRESHOLD ir signals are detectd
19 #define IR_SAMPLE_DURATION 8000
20 #define IR_TRESHOLD 7500
21 //duration PanicButton needs to be pressed before status change occurs (i.e. for two PanicButton Reports, the buttons needs to be pressed 1000 cycles, releases 1000 cycles and again pressed 1000 cycles)
22 #define PB_TRESHOLD 1000
23 #define PHOTO_SAMPLE_INTERVAL 4000
24 #define IRREMOTE_SEND_PIN 3   //hardcoded in library
25 //WARNING IRremote Lib uses TCCR2
26
27 OneWire  onewire(ONE_WIRE_PIN);
28 DallasTemperature dallas_sensors(&onewire);
29 DeviceAddress onShieldTemp = { 0x10, 0xE7, 0x77, 0xD3, 0x01, 0x08, 0x00, 0x3F };
30 IRsend irsend; 
31 #define TEMPC_OFFSET_ARDUINO_GENEREATED_HEAT 
32
33 //********************************************************************//
34 // IR Codes, 32 bit, NEC
35 const int YAMAHA_CODE_BITS = 32;
36 const unsigned long int YAMAHA_CODE_BASE = 0x0000000005EA10000;
37
38 const char YAMAHA_POWER_TOGGLE =0xF8; //Power On/Off
39 const char YAMAHA_POWER_OFF =0x78; //Power Off !!!
40 const char YAMAHA_SLEEP =0xEA; //Toggle Sleep 120/90/60/30min or Off
41
42 const char YAMAHA_CD =0xA8; //Input CD
43 const char YAMAHA_TUNER =0x68; //Input Tuner
44 const char YAMAHA_TAPE =0x18; //Input Toggle Tape/CD
45 const char YAMAHA_DVD_SPDIF =0xE8; //Input Toggle DVD Auto / DVD Analog
46 const char YAMAHA_SAT_SPDIFF =0x2A; //Input Toggle Sat-DTV Auto / Sat-DTV Analog
47 const char YAMAHA_AUX =0xAA;  //Input AUX (mode)
48 const char YAMAHA_VCR =0xF0; //Input VCR
49 const char YAMAHA_EXT51DEC =0xE1; //Input Ext. Decoder On/Off
50
51 const char YAMAHA_TUNER_PLUS =0x08; //Tuner Next Station 1-7  (of A1 - E7)
52 const char YAMAHA_TUNER_MINUS =0x88; //Tuner Prev Station 1-7  (of A1 - E7)
53 const char YAMAHA_TUNER_ABCDE =0x48; //Tuner Next Station Row A-E (of A1 - E7)
54
55 const char YAMAHA_MUTE =0x38;
56 const char YAMAHA_VOLUME_UP =0x58;
57 const char YAMAHA_VOLUME_DOWN =0xD8;
58
59 //const char YAMAHA_FRONT_LEVEL_P =0x01;  //no function
60 //const char YAMAHA_FRONT_LEVEL_M =0x81; //no function
61 //const char YAMAHA_CENTRE_LEVEL_P =0x41;  //no function
62 //const char YAMAHA_CENTRE_LEVEL_M =0xC1; //no function
63 //const char YAMAHA_REAR_LEVEL_P =0x7A; //no function
64 //const char YAMAHA_REAR_LEVEL_M =0xFA; //no function
65 const char YAMAHA_PLUS =0x4A;  //unteres Steuerkreuz: Taste Rechts (Plus)
66 const char YAMAHA_MINUS =0xCA; //unteres Steuerkreuz: Taste Links (Minus)
67 const char YAMAHA_MENU =0x39; // Menu: Settings
68 const char YAMAHA_TEST =0xA1; // Test Sounds
69 const char YAMAHA_TIME_LEVEL =0x19; //Settings for Delay, Subwfs, Right Surround, Left Surround, Center
70 const char YAMAHA_TIME_LEVEL2 =0x61; //(also) Settings for Delay, Subwfs, Right Surround, Left Surround, Center
71 const char YAMAHA_TIME_LEVEL3 =0x99; //(also) Settings for Delay, Subwfs, Right Surround, Left Surround, Center
72
73 const char YAMAHA_EFFECT_TOGGLE =0x6A; //Effect Toggle On/Off
74 const char YAMAHA_PRG_DOWN =0x9A; //Effect/DSP Programm Toggle in down direction
75 const char YAMAHA_PRG_UP =0x1A; //Effect/DSP Programm Toggle in up direction
76 const char YAMAHA_EFFECT1 =0x31; //Effect TV Sports
77 const char YAMAHA_EFFECT2 =0x71; //Effect Rock Concert
78 const char YAMAHA_EFFECT3 =0xB1;  //Effect Disco
79 const char YAMAHA_EFFECT4 =0xD1;  //Mono Movie
80 const char YAMAHA_EFFECT5 =0x91; //Effect Toggle 70mm Sci-Fi / 70mm Spectacle
81 const char YAMAHA_EFFECT6 =0x51; //Effect Toggle 70mm General / 70mm Adventure
82 const char YAMAHA_P5 =0xFB; //P5 PRT (1 Main Bypass)? (1587674115)
83
84 //********************************************************************//
85
86 typedef struct {
87   byte offset;
88   byte state;
89 } rf_bit_t;
90
91 // offset is number of alphas (0.08ms)
92
93 const rf_bit_t zero_bit[] = { {  4, 1 },
94                               { 16, 0 },
95                               { 20, 1 },
96                               { 32, 0 },
97                               {  0, 0 } };
98
99 const rf_bit_t one_bit[] = { { 12, 1 },
100                              { 16, 0 },
101                              { 28, 1 },
102                              { 32, 0 },
103                              {  0, 0 } };
104
105 const rf_bit_t float_bit[] = { {  4, 1 },
106                                { 16, 0 },
107                                { 28, 1 },
108                                { 32, 0 },
109                                {  0, 0 } };
110
111 const rf_bit_t sync_bit[] = { {   4, 1 },
112                               { 128, 0 },
113                               {   0, 0 } };
114
115 //WORKS @ alpha=0.0775ms
116 //const rf_bit_t pwm_0_bit[] = {  {7, 1}, {24, 0}, {  0, 0 } };     // 1.86ms gesamt: { 0.46ms HIGH , 1.4ms LOW }
117 //const rf_bit_t pwm_1_bit[] = {  {18, 1}, {24, 0}, {  0, 0 } };    // 1.86ms gesamt: { 1.4ms HIGH , 0.46ms LOW }
118 //const rf_bit_t pwm_pause_bit[] = {  {168, 0}, {  0, 0 } };        // 13ms pause 
119
120 //WORKS @ alpha=0.08ms
121 const rf_bit_t pwm_0_bit[] = {  {6, 1}, {23, 0}, {  0, 0 } };   // 1.86ms gesamt: { 0.46ms HIGH , 1.4ms LOW }
122 const rf_bit_t pwm_1_bit[] = {  {18, 1}, {23, 0}, {  0, 0 } };  // 1.86ms gesamt: { 1.4ms HIGH , 0.46ms LOW }
123 const rf_bit_t pwm_pause_bit[] = {  {162, 0}, {  0, 0 } };      // 13ms pause 
124
125 typedef enum { ZERO = 0, ONE , FLOAT , SYNC , PWM0, PWM1, PWM_PAUSE, WORD_END } adbit_t;
126 typedef byte ad_bit_t;
127 #define MAX_WORD_LEN 27
128 typedef ad_bit_t word_t[MAX_WORD_LEN];
129
130 const rf_bit_t* bit_defs[] = { zero_bit, one_bit, float_bit, sync_bit, pwm_0_bit, pwm_1_bit, pwm_pause_bit };
131
132 byte alpha_cnt = 0;
133 byte bit_cnt = 0;
134 byte chunk_cnt = 0;
135 byte word_cnt = 0;
136 const ad_bit_t* current_word;
137 byte volatile frame_finished = 1;
138
139 #define FRAME_LEN 10
140
141 #define A1_ON  0
142 #define A1_OFF 1
143 #define A2_ON  2
144 #define A2_OFF 3
145
146 #define B1_ON  4
147 #define B1_OFF 5
148 #define B2_ON  6
149 #define B2_OFF 7
150
151 #define C1_ON  8
152 #define C1_OFF 9
153 #define C2_ON  10
154 #define C2_OFF 11
155
156 #define D1_ON  12
157 #define D1_OFF 13
158 #define D2_ON  14
159 #define D2_OFF 15
160
161 #define BLACK_A1_ON 16
162 #define BLACK_A1_OFF 17
163 #define BLACK_A2_ON 18
164 #define BLACK_A2_OFF 19
165 #define BLACK_A3_ON 20
166 #define BLACK_A3_OFF 21
167
168 #define BLACK_B1_ON 22
169 #define BLACK_B1_OFF 23
170 #define BLACK_B2_ON 24
171 #define BLACK_B2_OFF 25
172 #define BLACK_B3_ON 26
173 #define BLACK_B3_OFF 27
174
175 #define BLACK_C1_ON 28
176 #define BLACK_C1_OFF 29
177 #define BLACK_C2_ON 30
178 #define BLACK_C2_OFF 31
179 #define BLACK_C3_ON 32
180 #define BLACK_C3_OFF 33
181
182 #define BLACK_D1_ON 34
183 #define BLACK_D1_OFF 35
184 #define BLACK_D2_ON 36
185 #define BLACK_D2_OFF 37
186 #define BLACK_D3_ON 38
187 #define BLACK_D3_OFF 39
188
189 #define RSL336T_INDEX(SW,BT,OFF)   40+(2*4*SW)+(2*BT)+OFF
190
191
192 #define PWM_01 PWM0,PWM1
193 #define PWM_00 PWM0,PWM0
194 #define RSL336T_SWBT_1  PWM_00,PWM_01,PWM_01,PWM_01
195 #define RSL336T_SWBT_2  PWM_01,PWM_00,PWM_01,PWM_01
196 #define RSL336T_SWBT_3  PWM_01,PWM_01,PWM_00,PWM_01
197 #define RSL336T_SWBT_4  PWM_01,PWM_01,PWM_01,PWM_00
198
199 const word_t words[]  = {
200 { ZERO,  ZERO,  FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END}, // A1_ON
201 { ZERO,  ZERO,  FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END}, // A1_OFF
202 { ZERO,  ZERO,  FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // A2_ON
203 { ZERO,  ZERO,  FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // A2_OFF
204
205 { FLOAT, ZERO,  FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // B1_ON
206 { FLOAT, ZERO,  FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // B1_OFF
207 { FLOAT, ZERO,  FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // B2_ON
208 { FLOAT, ZERO,  FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // B2_OFF
209
210 { ZERO,  FLOAT, FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // C1_ON
211 { ZERO,  FLOAT, FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // C1_OFF
212 { ZERO,  FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // C2_ON
213 { ZERO,  FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // C2_OFF
214
215 { FLOAT, FLOAT, FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // D1_ON
216 { FLOAT, FLOAT, FLOAT, FLOAT, ZERO,  ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // D1_OFF
217 { FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, FLOAT, SYNC, WORD_END, WORD_END,WORD_END }, // D2_ON
218 { FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO, FLOAT, FLOAT, ZERO,  SYNC, WORD_END, WORD_END,WORD_END }, // D2_OFF
219
220 {PWM1,PWM1,P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0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM1,PWM1,PWM0, PWM_PAUSE, WORD_END}, // BLACK_D1_OFF  
243 {PWM0,PWM1,PWM0,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM1,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM1,PWM1,PWM0,PWM0,PWM0, PWM_PAUSE, WORD_END}, // BLACK_D2_ON  
244 {PWM0,PWM1,PWM0,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM1,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM1,PWM1,PWM0, PWM_PAUSE, WORD_END}, // BLACK_D2_OFF  
245 {PWM0,PWM1,PWM0,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM1,PWM1,PWM0,PWM0,PWM0, PWM_PAUSE, WORD_END}, // BLACK_D3_ON
246 {PWM0,PWM1,PWM0,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM1,PWM0,PWM1,PWM1,PWM1,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM0,PWM1,PWM1,PWM0, PWM_PAUSE, WORD_END},  // BLACK_D3_OFF
247
248 {RSL336T_SWBT_1,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_1_ON
249 {RSL336T_SWBT_1,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_1_OFF
250 {RSL336T_SWBT_1,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_2_ON
251 {RSL336T_SWBT_1,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_2_OFF
252 {RSL336T_SWBT_1,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_3_ON
253 {RSL336T_SWBT_1,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_3_OFF
254 {RSL336T_SWBT_1,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_4_ON
255 {RSL336T_SWBT_1,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_I_4_OFF
256
257 {RSL336T_SWBT_2,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_1_ON
258 {RSL336T_SWBT_2,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_1_OFF
259 {RSL336T_SWBT_2,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_2_ON
260 {RSL336T_SWBT_2,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_2_OFF
261 {RSL336T_SWBT_2,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_3_ON
262 {RSL336T_SWBT_2,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_3_OFF
263 {RSL336T_SWBT_2,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_4_ON
264 {RSL336T_SWBT_2,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_II_4_OFF
265
266 {RSL336T_SWBT_3,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_1_ON
267 {RSL336T_SWBT_3,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_1_OFF
268 {RSL336T_SWBT_3,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_2_ON
269 {RSL336T_SWBT_3,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_2_OFF
270 {RSL336T_SWBT_3,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_3_ON
271 {RSL336T_SWBT_3,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_3_OFF
272 {RSL336T_SWBT_3,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_4_ON
273 {RSL336T_SWBT_3,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_III_4_OFF
274
275 {RSL336T_SWBT_4,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_1_ON
276 {RSL336T_SWBT_4,RSL336T_SWBT_1,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_1_OFF
277 {RSL336T_SWBT_4,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_2_ON
278 {RSL336T_SWBT_4,RSL336T_SWBT_2,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_2_OFF
279 {RSL336T_SWBT_4,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_3_ON
280 {RSL336T_SWBT_4,RSL336T_SWBT_3,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_3_OFF
281 {RSL336T_SWBT_4,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_01,PWM0, PWM_PAUSE, WORD_END}, // RSL366T_IV_4_ON
282 {RSL336T_SWBT_4,RSL336T_SWBT_4,PWM_01,PWM_01,PWM_01,PWM_00,PWM0, PWM_PAUSE, WORD_END}  // RSL366T_IV_4_OFF
283 };
284
285
286 //********************************************************************//
287
288 void start_timer()
289 {
290   // timer 1: 2 ms
291   TCCR1A = 0;                    // prescaler 1:8, WGM = 4 (CTC)
292   TCCR1B = 1<<WGM12 | 1<<CS11;   // 
293 //  OCR1A = 39;        // (1+39)*8 = 320 -> 0.02ms @ 16 MHz -> 1*alpha
294 //default: alpha=0.08  
295   OCR1A = 159;        // (1+159)*8 = 1280 -> 0.08ms @ 16 MHz -> 1*alpha
296 //  OCR1A = 154;        // (1+154)*8 = 1240 -> 0.0775ms @ 16 MHz -> 1*alpha
297 //  OCR1A = 207;        // (1+207)*8 = 1664 -> 0.104ms @ 16 MHz -> 1*alpha
298   TCNT1 = 0;          // reseting timer
299   TIMSK1 = 1<<OCIE1A; // enable Interrupt
300 }
301
302 void stop_timer() // stop the timer
303 {
304   // timer1
305   TCCR1B = 0; // no clock source
306   TIMSK1 = 0; // disable timer interrupt
307 }
308
309 void init_word(const word_t w)
310 {
311   current_word = w;
312   alpha_cnt = 0;
313   chunk_cnt = 0;
314   bit_cnt = 0;
315
316   if(bit_defs[current_word[bit_cnt]][chunk_cnt].state)
317     digitalWrite(RF_DATA_OUT_PIN, LOW); //neue 12V MosFET Verstärkung invertiert Logik !
318   else
319     digitalWrite(RF_DATA_OUT_PIN, HIGH);
320
321   start_timer();
322 }
323
324 ISR(TIMER1_COMPA_vect)
325 {
326   alpha_cnt++;
327   if(alpha_cnt < bit_defs[current_word[bit_cnt]][chunk_cnt].offset)
328     return;
329
330   chunk_cnt++;
331   if(bit_defs[current_word[bit_cnt]][chunk_cnt].offset != 0) {
332     if(bit_defs[current_word[bit_cnt]][chunk_cnt].state)
333       digitalWrite(RF_DATA_OUT_PIN, LOW); //neue 12V MosFET Verstärkung invertiert Logik !
334     else
335       digitalWrite(RF_DATA_OUT_PIN, HIGH);
336     return;
337   }
338   
339   bit_cnt++;
340   if(current_word[bit_cnt] != WORD_END && bit_cnt < MAX_WORD_LEN) {
341     alpha_cnt = 0;
342     chunk_cnt = 0;
343     if(bit_defs[current_word[bit_cnt]][chunk_cnt].state)
344       digitalWrite(RF_DATA_OUT_PIN, LOW); //neue 12V MosFET Verstärkung invertiert Logik !
345     else
346       digitalWrite(RF_DATA_OUT_PIN, HIGH);
347     return;
348   }
349   stop_timer();
350   digitalWrite(RF_DATA_OUT_PIN, HIGH);
351
352   word_cnt++;
353   if(word_cnt < FRAME_LEN)
354     init_word(current_word);
355   else
356     frame_finished = 2;
357 }
358
359 //***********//
360
361
362 void send_frame(const word_t w)
363 {
364   if (frame_finished != 1)
365     for(;;) //wait until sending of previous frame finishes
366       if (frame_finished)
367       {
368         delay(150);
369         break;
370       }
371   word_cnt = 0;
372   frame_finished = 0;
373   init_word(w);
374 }
375
376 void check_frame_done()
377 {
378   if (frame_finished==2)
379   {
380     Serial.println("Ok");
381     frame_finished=1;
382     delay(120);
383   }
384 }
385
386 //********************************************************************//
387
388 void printTemperature(DeviceAddress deviceAddress)
389 {
390   dallas_sensors.requestTemperatures();
391   float tempC = dallas_sensors.getTempC(deviceAddress);
392   //Serial.print("Temp C: ");
393   Serial.println(tempC TEMPC_OFFSET_ARDUINO_GENEREATED_HEAT);
394   //Serial.print(" Temp F: ");
395   //Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
396 }
397
398 //********************************************************************//
399
400 unsigned int light_level_mean_ = 0;
401 unsigned int light_sample_time_ = 0;
402
403 void updateLightLevel(unsigned int pin)
404 {
405   light_sample_time_++;
406   if (light_sample_time_ < PHOTO_SAMPLE_INTERVAL)
407     return;
408   light_sample_time_ = 0;
409   
410   unsigned int value = analogRead(pin);
411   if (value == light_level_mean_)
412     return;
413   
414   unsigned int diff = abs(value - light_level_mean_);
415   if (diff > 100)
416     light_level_mean_ = value;
417   else
418       light_level_mean_=(unsigned int) ( ((float) light_level_mean_) * 0.90 + ((float)value)*0.10 );
419 }
420
421 void printLightLevel()
422 {
423   //Serial.print("Photo: ");
424   Serial.println(light_level_mean_);
425 }
426
427 //********************************************************************//
428
429 unsigned long wm_start_[3]={0,0,0};
430 bool wait_millis(unsigned long *start_time, unsigned long ms)
431 {
432   if (ms == 0)
433     return false;
434   else if (*start_time > 0)
435   {
436     if (millis() < *start_time || millis() > (*start_time) + ms)
437     {
438       *start_time = 0;
439       return false;
440     }
441     else
442       return true;
443   }
444   else
445   {
446     *start_time=millis();
447     return true;
448   }
449 }
450 #define NUM_LEDS 2
451 char flash_led_pins_[NUM_LEDS]={BLUELED_PWM_PIN,PANICLED_PWM_PIN};
452 unsigned int flash_led_time_[3]={0,0,0};
453 unsigned int flash_led_brightness_[3]={255,255,255};
454 unsigned int flash_led_delay_[3]={8,8,8};
455 unsigned int flash_led_initial_delay_[3]={0,0,0};
456 void calculate_led_level()
457 {
458   for (int ledid = 0; ledid < NUM_LEDS; ledid++)
459   {
460     if (flash_led_time_[ledid] == 0)
461       continue;
462     if (wait_millis(wm_start_ + ledid, flash_led_initial_delay_[ledid]))
463       continue;
464     flash_led_initial_delay_[ledid]=0;
465     if (wait_millis(wm_start_ + ledid, flash_led_delay_[ledid]))
466       continue;
467     flash_led_time_[ledid]--;
468     int c = abs(sin(float(flash_led_time_[ledid]) / 100.0)) * flash_led_brightness_[ledid];
469     //int d = abs(sin(float(flash_led_time_) / 100.0)) * flash_led_brightness_;
470     analogWrite(flash_led_pins_[ledid], 255-c);
471   }
472 }
473
474 // id: id of LED to flash (0,1)
475 // times: # of times the LED should flash
476 // brightness_divisor: 1: full brightness, 2: half brightness, ...
477 // delay_divisor: 1: slow... 8: fastest
478 // phase_divisor: 0.. same phase; 2.. pi/2 phase, 4.. pi phase, 6.. 3pi/2 phase
479 void flash_led(unsigned int id, unsigned int times, unsigned int brightness_divisor, unsigned int delay_divisor, unsigned int phase_divisor)
480 {
481   if (id >= NUM_LEDS)
482     return;
483   unsigned int new_flash_led_brightness = 255;
484   unsigned int new_flash_led_delay = 8;
485   if (times == 0)
486   {
487     analogWrite(flash_led_pins_[id],255); //off
488     return;
489   }
490   if (brightness_divisor > 1) //guard against div by zero
491     new_flash_led_brightness /= brightness_divisor;
492   if (delay_divisor > 1)  //guard against div by zero
493     new_flash_led_delay /= delay_divisor;
494   if (flash_led_time_[id] == 0 || new_flash_led_brightness > flash_led_brightness_[id])
495     flash_led_brightness_[id]=new_flash_led_brightness;
496   if (flash_led_time_[id] == 0 || new_flash_led_delay < flash_led_delay_[id])
497     flash_led_delay_[id]=new_flash_led_delay;
498   flash_led_time_[id] += 314*times;
499   flash_led_initial_delay_[id] = flash_led_delay_[id]*314*phase_divisor/8;
500 }
501
502 //********************************************************************//
503
504 int save_tcnt2=0;
505 int save_tccr2a=0;
506 int save_tccr2b=0;
507 void reset_timer2()
508 {
509   TCNT2 = save_tcnt2;
510   TCCR2A = save_tccr2a;  // normal mode
511   TCCR2B = save_tccr2b;
512   //TCNT2 = 256 - (50*(16000000/8/1000000)) + 5;
513   //TCCR2A = 0;  // normal mode
514   //TCCR2B = 0;
515 }
516
517 void send_yamaha_ir_signal(char codebyte)
518 {
519   unsigned long int code = codebyte & 0xFF;
520   code <<= 8;
521   code |= (0xff ^ codebyte) & 0xFF;
522   code |= YAMAHA_CODE_BASE;
523   
524   //irsend changes PWM Timer Frequency among other things
525   //.. doesn't go well with PWM output using the same timer
526   //.. thus we just set output to 255 so whatever frequency is used, led is off for the duration
527   //analogWrite(BLUELED_PWM_PIN,255); // switch led off
528
529   irsend.sendNEC(code,YAMAHA_CODE_BITS);
530
531   reset_timer2();
532   analogWrite(BLUELED_PWM_PIN,255); // switch off led again to be sure
533                                       //is actually not necessary, since we are not multitasking/using interrupts, but just to be sure in case this might change
534
535   Serial.println("Ok");
536 }
537
538 //********************************************************************//
539
540 void setup()
541 {
542   pinMode(RF_DATA_OUT_PIN, OUTPUT);
543   digitalWrite(RF_DATA_OUT_PIN, HIGH);
544   pinMode(IR_MOVEMENT_PIN, INPUT);      // set pin to input
545   digitalWrite(IR_MOVEMENT_PIN, LOW);  // turn off pullup resistors  
546   digitalWrite(IR_MOVEMENT_PIN2, LOW);  // turn off pullup resistors  
547   pinMode(PANIC_BUTTON_PIN, INPUT);      // set pin to input
548   digitalWrite(PANIC_BUTTON_PIN, LOW);  // turn of pullup resistors 
549   analogWrite(PANICLED_PWM_PIN,255);
550   analogWrite(BLUELED_PWM_PIN,255); //pwm sink(-) instead of pwm + (better for mosfets)
551   pinMode(IRREMOTE_SEND_PIN, OUTPUT);
552   digitalWrite(IRREMOTE_SEND_PIN, HIGH);
553   
554   Serial.begin(9600);
555   
556   onewire.reset();
557   onewire.reset_search();
558   dallas_sensors.begin();
559   //in case we change temp sensor:
560   if (!dallas_sensors.getAddress(onShieldTemp, 0)) 
561     Serial.println("Error: Unable to find address for Device 0"); 
562   dallas_sensors.setResolution(onShieldTemp, 9);  
563
564   //save prev timer states:
565   save_tcnt2 = TCNT2;
566   save_tccr2a = TCCR2A;  // normal mode
567   save_tccr2b = TCCR2B;
568 }
569
570 unsigned int ir_time=IR_SAMPLE_DURATION;
571 unsigned int ir_count=0;
572 unsigned int ir_count2=0;
573 boolean pb_last_state=0;
574 boolean pb_state=0;
575 boolean pb_postth_state=0;
576 unsigned int pb_time=0;
577
578 void sensorEchoCommand(char command)
579 {
580   Serial.print("Sensor ");
581   Serial.print(command);
582   Serial.print(": ");
583 }
584
585 void loop()
586 {
587   ir_time--;
588   ir_count += (digitalRead(IR_MOVEMENT_PIN) == HIGH);
589   ir_count2 += (digitalRead(IR_MOVEMENT_PIN2) == HIGH);
590
591   if (pb_time < PB_TRESHOLD)
592     pb_time++;
593   pb_state=(digitalRead(PANIC_BUTTON_PIN) == HIGH);
594   
595   if (ir_time == 0)
596   {
597     if (ir_count >= IR_TRESHOLD || ir_count2 >= IR_TRESHOLD)
598     {
599       flash_led(0, 1, 8, 1, 0 );
600       Serial.println("movement");
601     }
602     ir_time=IR_SAMPLE_DURATION;
603     ir_count=0;
604     ir_count2=0;
605   }
606   
607   if (pb_state == pb_last_state && pb_time >= PB_TRESHOLD)
608   {
609     if (pb_state && ! pb_postth_state)
610     {   
611       pb_postth_state=1;
612       Serial.println("PanicButton");
613       flash_led(0, 28, 1, 4, 0 );
614       flash_led(1, 28, 1, 4, 4 );
615     }
616     else if (!pb_state)
617       pb_postth_state=0;
618   }
619   else if (pb_state != pb_last_state)
620   {
621     pb_time=0;
622     pb_last_state=pb_state;
623   }
624   
625   updateLightLevel(PHOTO_ANALOGPIN);
626   calculate_led_level();
627   check_frame_done();
628   
629   if(Serial.available()) {
630     char command = Serial.read();
631     
632     if(command == 'A')
633       send_frame(words[A1_ON]);
634     else if(command == 'a')
635       send_frame(words[A1_OFF]);
636     else if(command == 'B')
637       send_frame(words[A2_ON]);
638     else if(command == 'b')
639       send_frame(words[A2_OFF]);
640
641     else if(command == 'C')
642       send_frame(words[B1_ON]);
643     else if(command == 'c')
644       send_frame(words[B1_OFF]);
645     else if(command == 'D')
646       send_frame(words[B2_ON]);
647     else if(command == 'd')
648       send_frame(words[B2_OFF]);
649
650     else if(command == 'E')
651       send_frame(words[C1_ON]);
652     else if(command == 'e')
653       send_frame(words[C1_OFF]);
654     else if(command == 'F')
655       send_frame(words[C2_ON]);
656     else if(command == 'f')
657       send_frame(words[C2_OFF]);
658
659     else if(command == 'G')
660       send_frame(words[D1_ON]);
661     else if(command == 'g')
662       send_frame(words[D1_OFF]);
663     else if(command == 'H')
664       send_frame(words[D2_ON]);
665     else if(command == 'h')
666       send_frame(words[D2_OFF]);
667       
668     else if(command == 'I')
669       send_frame(words[BLACK_A1_ON]);
670     else if(command == 'i')
671       send_frame(words[BLACK_A1_OFF]);
672     else if(command == 'J')
673       send_frame(words[BLACK_A2_ON]);
674     else if(command == 'j')
675       send_frame(words[BLACK_A2_OFF]);
676     else if(command == 'K')
677       send_frame(words[BLACK_A3_ON]);
678     else if(command == 'k')
679       send_frame(words[BLACK_A3_OFF]);
680       
681     else if(command == 'L')
682       send_frame(words[BLACK_B1_ON]);
683     else if(command == 'l')
684       send_frame(words[BLACK_B1_OFF]);
685     else if(command == 'M')
686       send_frame(words[BLACK_B2_ON]);
687     else if(command == 'm')
688       send_frame(words[BLACK_B2_OFF]);
689     else if(command == 'N')
690       send_frame(words[BLACK_B3_ON]);
691     else if(command == 'n')
692       send_frame(words[BLACK_B3_OFF]);
693       
694     else if(command == 'O')
695       send_frame(words[BLACK_C1_ON]);
696     else if(command == 'o')
697       send_frame(words[BLACK_C1_OFF]);
698     else if(command == 'P')
699       send_frame(words[BLACK_C2_ON]);
700     else if(command == 'p')
701       send_frame(words[BLACK_C2_OFF]);
702     else if(command == 'Q')
703       send_frame(words[BLACK_C3_ON]);
704     else if(command == 'q')
705       send_frame(words[BLACK_C3_OFF]);
706             
707     else if(command == 'R')
708       send_frame(words[BLACK_D1_ON]);
709     else if(command == 'r')
710       send_frame(words[BLACK_D1_OFF]);
711     else if(command == 'S')
712       send_frame(words[BLACK_D2_ON]);
713     else if(command == 's')
714       send_frame(words[BLACK_D2_OFF]);
715     else if(command == 'T')
716       send_frame(words[BLACK_D3_ON]);
717     else if(command == 't')
718       send_frame(words[BLACK_D3_OFF]);
719
720     else if (command == 'U')
721       send_frame(words[RSL336T_INDEX(0,0,0)]);
722     else if (command == 'u')
723       send_frame(words[RSL336T_INDEX(0,0,1)]);
724     else if (command == 'V')
725       send_frame(words[RSL336T_INDEX(0,1,0)]);
726     else if (command == 'v')
727       send_frame(words[RSL336T_INDEX(0,1,1)]);
728     else if (command == 'W')
729       send_frame(words[RSL336T_INDEX(0,2,0)]);
730     else if (command == 'w')
731       send_frame(words[RSL336T_INDEX(0,2,1)]);
732     else if (command == 'X')
733       send_frame(words[RSL336T_INDEX(0,3,0)]);
734     else if (command == 'x')
735       send_frame(words[RSL336T_INDEX(0,3,1)]);
736     else if (command == 'Y')
737       send_frame(words[RSL336T_INDEX(1,0,0)]);
738     else if (command == 'y')
739       send_frame(words[RSL336T_INDEX(1,0,1)]);
740     else if (command == 'Z')
741       send_frame(words[RSL336T_INDEX(1,1,0)]);
742     else if (command == 'z')
743       send_frame(words[RSL336T_INDEX(1,1,1)]);
744     
745     else if(command == '*')
746     {
747       sensorEchoCommand(command);
748       printTemperature(onShieldTemp);
749     }
750     else if(command == '?')
751     {
752       sensorEchoCommand(command);
753       printLightLevel();
754     }
755     else if (command == '^')
756     {
757       //flash_led(1, 1, 2, 1, 0);
758       flash_led(1, 1, 1, 1, 0);
759       Serial.println("Ok");
760     }
761     else if (command == '&')
762     {
763       flash_led(0, 1, 2, 1, 0);
764       Serial.println("Ok");
765     }
766     else if (command == '1')
767       send_yamaha_ir_signal(YAMAHA_CD);
768     else if (command == '2')
769       send_yamaha_ir_signal(YAMAHA_TUNER);
770     else if (command == '3')
771       send_yamaha_ir_signal(YAMAHA_TAPE);
772     else if (command == '4')
773       send_yamaha_ir_signal(YAMAHA_DVD_SPDIF);
774     else if (command == '5')
775       send_yamaha_ir_signal(YAMAHA_SAT_SPDIFF);
776     else if (command == '6')
777       send_yamaha_ir_signal(YAMAHA_VCR);
778 //    else if (command == '7')
779 //      send_yamaha_ir_signal();
780     else if (command == '8')
781       send_yamaha_ir_signal(YAMAHA_AUX);
782     else if (command == '9')
783       send_yamaha_ir_signal(YAMAHA_EXT51DEC);
784     else if (command == '0')
785       send_yamaha_ir_signal(YAMAHA_TEST);
786     else if (command == '/')
787       send_yamaha_ir_signal(YAMAHA_TUNER_ABCDE);
788     else if (command == '\\')
789       send_yamaha_ir_signal(YAMAHA_EFFECT_TOGGLE);
790     else if (command == '-')
791       send_yamaha_ir_signal(YAMAHA_TUNER_MINUS);
792     else if (command == '+')
793       send_yamaha_ir_signal(YAMAHA_TUNER_PLUS);
794     else if (command == ':')
795       send_yamaha_ir_signal(YAMAHA_POWER_OFF);
796     else if (command == '.')
797       send_yamaha_ir_signal(YAMAHA_POWER_TOGGLE);
798     else if (command == ';')
799       send_yamaha_ir_signal(YAMAHA_VOLUME_UP);
800     else if (command == ',')
801       send_yamaha_ir_signal(YAMAHA_VOLUME_DOWN);
802     else if (command == '_')
803       send_yamaha_ir_signal(YAMAHA_MUTE);
804     else if (command == '#')
805       send_yamaha_ir_signal(YAMAHA_MENU);
806     else if (command == '"')
807       send_yamaha_ir_signal(YAMAHA_PLUS);
808     else if (command == '!')
809       send_yamaha_ir_signal(YAMAHA_MINUS);
810     else if (command == '=')
811       send_yamaha_ir_signal(YAMAHA_TIME_LEVEL);
812     else if (command == '$')
813       send_yamaha_ir_signal(YAMAHA_PRG_DOWN);
814     else if (command == '%')
815       send_yamaha_ir_signal(YAMAHA_PRG_UP);
816     else if (command == '(')
817       send_yamaha_ir_signal(YAMAHA_SLEEP);
818     else if (command == ')')
819       send_yamaha_ir_signal(YAMAHA_P5);
820     else
821       Serial.println("Error: unknown command");
822   }
823 }