This repository has been archived by the owner on Apr 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOXOcard.cpp
664 lines (594 loc) · 22.4 KB
/
OXOcard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
/*******************************************************************************
* \file OXOcard.cpp
********************************************************************************
* \author Jascha Haldemann jh@oxon.ch
* \author Thomas Garaio tg@oxon.ch
* \date 01.02.2017
* \version 1.0
*
* \license LGPL-V2.1
* Copyright (c) 2017 OXON AG. All rights reserved.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see 'http://www.gnu.org/licenses/'
*******************************************************************************/
/* ================================= Imports ================================ */
#include "OXOcard.h"
/* ======================= Module constant declaration ====================== */
/* ======================== Module macro declaration ======================== */
#ifdef DEBUG_OXOCARD
#define DebugOXOcard_begin(...) Serial.begin(__VA_ARGS__)
#define DebugOXOcard_print(...) Serial.print(__VA_ARGS__)
#define DebugOXOcard_println(...) Serial.println(__VA_ARGS__)
#else
#define DebugOXOcard_begin(...)
#define DebugOXOcard_print(...)
#define DebugOXOcard_println(...)
#endif
/* ====================== Module class instantiations ======================= */
/* ======================== Public member Functions ========================= */
/* Global variables ========================================================= */
unsigned int autoTurnOffAfter = -1;
volatile unsigned int autoTurnOffCnt = 0;
volatile bool goingToTurnOff = false;
/* System functions */
/** -------------------------------------------------------------------------
* \fn begin
* \brief inits teh OXOcard
--------------------------------------------------------------------------- */
void OXOcard::begin()
{
DebugOXOcard_begin(DEBUG_BAUDRATE_OXOCARD);
DebugOXOcard_println();
initPins();
disableUnusedCpuFunctions();
initTimerIRQ(1, 1024, 7812); // interrupt every 1 Second
/* init LED matrix (~30ms) */
DebugOXOcard_println(F("init LED matrix"));
matrix = new IS31FL3731(Wire, &P_EN_LED_DRIVER, EN_LED_DRIVER, 8, 8);
matrix->begin(400000L);
matrix->clear();
/* init accelerometer (~2ms) */
DebugOXOcard_println(F("init accelerometer"));
accel = new MMA7660FC(Wire);
accel->begin(400000L);
/* init BLE (~1500ms) */
DebugOXOcard_println(F("init BLE"));
bleSerial = new SoftwareSerial0(PIN_NR_SW_RXD, PIN_NR_SW_TXD);
ble = new HM11_SoftwareSerial0(*bleSerial, &P_SW_RXD, SW_RXD, &P_SW_TXD, SW_TXD, &P_EN_BLE, EN_BLE, &P_RST_BLE, RST_BLE);
//ble->forceRenew();
ble->begin(BAUDRATE_BLE);
}
/** -------------------------------------------------------------------------
* \fn turnOff
* \brief turns off the device by putting it in a power down sleep-mode
*
* \requ <avr/sleep.h>
*
* \param leftButton enable wake-up by the left button
* \param middleButton enable wake-up by the middle button
* \param rightButton enable wake-up by the right button
* \return None
--------------------------------------------------------------------------- */
void OXOcard::turnOff(bool leftButton, bool middleButton, bool rightButton)
{
DebugOXOcard_println(F("turnOff"));
/* check periphery state */
bool isBlueLEDEnabled = getLEDBlue();
/* disable periphery */
matrix->end();
accel->end();
ble->disable();
clearBit(P_PIEZO, PIEZO);
setLEDBlue(LOW);
setLEDRed(LOW);
/* disable HW-Serial */
Serial.flush();
uint8_t ucsrb = UCSR0B;
UCSR0B = 0;
clearBit(P_RXD, RXD); // necessary!
delay(1);
/* all interrupts have to be disabled during turn off configurations */
cli();
if (leftButton) // PCINT2
{
/* mask the correct pin */
setBit(PCMSK2, PCINT20); // BUTTON1 = PCINT20
/* clear the interrupt flags */
setBit(PCIFR, PCIF2);
/* enable external interrupt PCINTn (to wake up later) */
setBit(PCICR, PCIE2);
}
if (middleButton) // INT1
{
/* define that a low-level of INTn generates an interrupt request */
clearBit(EICRA, ISC11);
clearBit(EICRA, ISC10);
/* clear the interrupt flags */
setBit(EIFR, INTF1);
/* enable external interrupt INTn (to wake up later) */
setBit(EIMSK, INT1);
}
if (rightButton) // INT0
{
/* define that a low-level of INTn generates an interrupt request */
clearBit(EICRA, ISC01);
clearBit(EICRA, ISC00);
/* clear the interrupt flags */
setBit(EIFR, INTF0);
/* enable external interrupt INTn (to wake up later) */
setBit(EIMSK, INT0);
}
/* disable other interrupts */
clearBit(TIMSK1, OCIE1A); // autoTurnOff
//clearBit(TIMSK2, OCIE2A);
/* choose "Power-down" sleep mode */
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
/* enable sleep-mode */
sleep_enable();
/* reenable interrupts */
sei();
/* system actually sleeps here */
sleep_cpu();
/* zzzZZZzzzZZZ... */
/* INTn occured (button click) -> wakes up! system continues here... */
/* reenable other interrupts */
setBit(TIMSK1, OCIE1A);
//setBit(TIMSK2, OCIE2A);
/* reenable HW-Serial */
UCSR0B = ucsrb;
setBit(P_RXD, RXD);
/* reenable periphery */
setLEDRed(HIGH);
matrix->begin();
accel->begin();
ble->enable();
if (isBlueLEDEnabled) setLEDBlue(HIGH);
}
/** -------------------------------------------------------------------------
* \fn handleAutoTurnOff
* \brief handles the functinality to turnOff after a defined time in s
*
* \requ turnOff()
*
* \param seconds time in s
* \param leftButton enable wake-up by the left button
* \param middleButton enable wake-up by the middle button
* \param rightButton enable wake-up by the right button
* \return None
--------------------------------------------------------------------------- */
void OXOcard::handleAutoTurnOff(uint16_t seconds, bool leftButton, bool middleButton, bool rightButton)
{
if (seconds < autoTurnOffAfter)
{
/* counter has been changed -> reset the interrupt counter */
resetAutoTurnOffCounter();
}
autoTurnOffAfter = seconds;
if (goingToTurnOff)
{
goingToTurnOff = false;
turnOff(leftButton, middleButton, rightButton);
}
}
/** -------------------------------------------------------------------------
* \fn resetAutoTurnOffCounter
* \brief resets the auto turn off counter
--------------------------------------------------------------------------- */
void OXOcard::resetAutoTurnOffCounter()
{
autoTurnOffCnt = 0;
}
/** -------------------------------------------------------------------------
* \fn isLeftButtonPressed
* \brief checks if the left button is pressed
*
* \return true if button is pressed
--------------------------------------------------------------------------- */
bool OXOcard::isLeftButtonPressed()
{
bool pressed = false;
if (button1Pressed)
{
resetAutoTurnOffCounter(); // prevent autoturnoff after an action
pressed = true;
}
return pressed;
}
/** -------------------------------------------------------------------------
* \fn isMiddleButtonPressed
* \brief checks if the middle button is pressed
*
* \return true if button is pressed
--------------------------------------------------------------------------- */
bool OXOcard::isMiddleButtonPressed()
{
bool pressed = false;
if (button2Pressed)
{
resetAutoTurnOffCounter(); // prevent autoturnoff after an action
pressed = true;
}
return pressed;
}
/** -------------------------------------------------------------------------
* \fn isRightButtonPressed
* \brief checks if the right button is pressed
*
* \return true if button is pressed
--------------------------------------------------------------------------- */
bool OXOcard::isRightButtonPressed()
{
bool pressed = false;
if (button3Pressed)
{
resetAutoTurnOffCounter(); // prevent autoturnoff after an action
pressed = true;
}
return pressed;
}
/* BLE functions */
/** -------------------------------------------------------------------------
* \fn setupAsIBeacon
* \brief setups the BLE module of the OXOcard as iBeacon
*
* \param beaconName iBeacon name (max. 20 characters)
* \param interv advert. interval (see enumerator in the HM11.h file)
* \return None
--------------------------------------------------------------------------- */
void OXOcard::setupAsIBeacon(String beaconName, HM11::advertInterval_t interv)
{
if (beaconName.length() > 20)
{
DebugOXOcard_println(F("iBeacon name is too long! (max. 20 characters)"));
beaconName = beaconName.substring(0, 20);
}
/* convert to hex char array */
HM11::iBeaconData_t iBeacon;
iBeacon.name = BLE_NAME;
iBeaconNameToIBeaconUUID(beaconName, &iBeacon);
iBeacon.interv = interv;
ble->setupAsIBeacon(&iBeacon);
setLEDBlue(HIGH);
}
/** -------------------------------------------------------------------------
* \fn setupAsIBeacon
* \brief setups the BLE module of the OXOcard as iBeacon
*
* \param beaconNr iBeacon number (1... 65534)
* \param interv advert. interval (see enumerator in the HM11.h file)
* \return None
--------------------------------------------------------------------------- */
void OXOcard::setupAsIBeacon(uint16_t beaconNr, HM11::advertInterval_t interv)
{
HM11::iBeaconData_t iBeacon;
iBeacon.name = BLE_NAME;
iBeacon.uuid = BLE_DEFAULT_UUID;
iBeacon.marjor = BLE_DEFAULT_MARJOR;
iBeacon.minor = beaconNr;
iBeacon.interv = interv;
ble->setupAsIBeacon(&iBeacon);
setLEDBlue(HIGH);
}
/** -------------------------------------------------------------------------
* \fn findIBeacon
* \brief searches for near iBeacon with given iBeacon name
*
* \param beaconName iBeacon number (1... 65534)
* \return 0 or tx power in dBm if an iBeacon was found
--------------------------------------------------------------------------- */
int16_t OXOcard::findIBeacon(String beaconName)
{
static bool firstTime = true;
int16_t txPower = 0;
if (firstTime)
{
ble->setupAsIBeaconDetector();
firstTime = false;
}
static HM11::iBeaconData_t iBeacon;
iBeaconNameToIBeaconUUID(beaconName, &iBeacon);
DebugOXOcard_println(F("detectIBeacon..."));
if (ble->detectIBeacon(&iBeacon))
{
setLEDBlue(HIGH);
DebugOXOcard_print(F("iBeacon.accessAddress = ")); DebugOXOcard_println(iBeacon.accessAddress);
DebugOXOcard_print(F("iBeacon.uuid = ")); DebugOXOcard_println(iBeacon.uuid);
DebugOXOcard_print(F("iBeacon.deviceAddress = ")); DebugOXOcard_println(iBeacon.deviceAddress);
DebugOXOcard_print(F("iBeacon.marjor = ")); DebugOXOcard_println(iBeacon.marjor);
DebugOXOcard_print(F("iBeacon.minor = ")); DebugOXOcard_println(iBeacon.minor);
DebugOXOcard_print(F("iBeacon.txPower = ")); DebugOXOcard_println(iBeacon.txPower);
txPower = iBeacon.txPower;
}
else
{
DebugOXOcard_println(F("no iBeacon found"));
setLEDBlue(LOW);
}
DebugOXOcard_println();
return txPower;
}
/** -------------------------------------------------------------------------
* \fn findIBeacon
* \brief searches for near iBeacon with given iBeacon number
*
* \param beaconNr iBeacon number (1... 65534)
* \return 0 or tx power in dBm if an iBeacon was found
--------------------------------------------------------------------------- */
int16_t OXOcard::findIBeacon(uint16_t beaconNr)
{
static bool firstTime = true;
int16_t txPower = 0;
static HM11::iBeaconData_t iBeacon;
iBeacon.minor = beaconNr; // minor you wish to search for
if (firstTime)
{
iBeacon.uuid = BLE_DEFAULT_UUID; // UUID you wish to search for
iBeacon.marjor = BLE_DEFAULT_MARJOR; // marjor you wish to search for
ble->setupAsIBeaconDetector();
firstTime = false;
}
DebugOXOcard_println(F("detectIBeacon..."));
if (ble->detectIBeacon(&iBeacon))
{
setLEDBlue(HIGH);
DebugOXOcard_print(F("iBeacon.accessAddress = ")); DebugOXOcard_println(iBeacon.accessAddress);
DebugOXOcard_print(F("iBeacon.uuid = ")); DebugOXOcard_println(iBeacon.uuid);
DebugOXOcard_print(F("iBeacon.deviceAddress = ")); DebugOXOcard_println(iBeacon.deviceAddress);
DebugOXOcard_print(F("iBeacon.marjor = ")); DebugOXOcard_println(iBeacon.marjor);
DebugOXOcard_print(F("iBeacon.minor = ")); DebugOXOcard_println(iBeacon.minor);
DebugOXOcard_print(F("iBeacon.txPower = ")); DebugOXOcard_println(iBeacon.txPower);
txPower = iBeacon.txPower;
}
else
{
DebugOXOcard_println(F("no iBeacon found"));
setLEDBlue(LOW);
}
DebugOXOcard_println();
return txPower;
}
/* ======================= Private member Functions ========================= */
/** -------------------------------------------------------------------------
* \fn initPins
* \brief inits used I/Os of the uC
--------------------------------------------------------------------------- */
void OXOcard::initPins()
{
DebugOXOcard_println(F("initPins"));
/* Port B */
DDRB = 0b00000010; // SW-TXD (must be defined as output!)
PORTB = 0b00111000; // L
/* Port C */
DDRC = 0b00000111; // EN_LED_DRIVER, !BLUE, !RED
PORTC = 0b00000010; // L , H , L
/* Port D */
setBit(P_EN_BLE, EN_BLE);
DDRD = 0b11100000; // PIEZO, !RST_BLE, !EN_BLE
PORTD = 0b00111101; // L , L , H
}
/** -------------------------------------------------------------------------
* \fn disableUnusedCpuFunctions
* \brief disables unused cpu-functions to reduce power consumption
*
* \note uC: ATmega328P
--------------------------------------------------------------------------- */
void OXOcard::disableUnusedCpuFunctions()
{
DebugOXOcard_println(F("disableUnusedCpuFunctions"));
setBit(ACSR, ACD); // disable ACD
clearBit(ADCSRA, ADEN); // disable ADC
/* set Power Reduction Register */
setBit(PRR, PRADC); // disable ADC
//setBit(PRR, PRUSART0); // disable USART0 -> used to debug
setBit(PRR, PRSPI); // disable SPI
//setBit(PRR, PRTIM0); // disable TIM0 -> used by the Arduino delay()-functions
//setBit(PRR, PRTIM1); // disable TIM1 -> used for automatic turnOff
//setBit(PRR, PRTIM2); // disable TIM2 -> used by the tone()-functions
//setBit(PRR, PRTWI); // disable TWI -> used to control accelerometer and the LED matrix
}
/** -------------------------------------------------------------------------
* \fn initTimerIRQ
* \brief initialize a timer in the Clear Timer on Compare
* Match (CTC) mode and enables its interrupt OCIEnA
*
* \note uC: ATtiny85, ATmega328P or ATmeag32U4
* implement: ISR (TIMERn_COMPA_vect)
* f_isr = ((fckl / prescaler) / (divisor + 1))
*
* \param timerNr timer number (0, 1, 2, 3)
* \param prescaler prescaler value (1, 8, 64, 256, 1024)
* \param divisor divisor value (0... 255 or 65535)
* \return None
--------------------------------------------------------------------------- */
void OXOcard::initTimerIRQ(uint8_t timerNr, uint16_t prescaler, uint16_t divisor)
{
DebugOXOcard_println(F("initTimerIRQ"));
cli();
switch (prescaler)
{
case 1: prescaler = uint8_t(0x01); break;
case 8: prescaler = uint8_t(0x02); break;
case 64: prescaler = uint8_t(0x03); break;
case 256: prescaler = uint8_t(0x04); break;
case 1024: prescaler = uint8_t(0x05); break;
default:
DebugOXOcard_println(F("invalid TIM prescaler!"));
for(;;);
}
switch (timerNr)
{
case 0: // 8bit Timer/Counter
TCCR0A = 0x02; // enable CTC (Clear Timer on Compare match) mode
TCCR0B = prescaler; // select prescaler mode
clearBit(TCCR0B, WGM02); // enable CTC (Clear Timer on Compare match) mode
#ifdef TIMSK0
setBit(TIMSK0, OCIE0A); // enable interrupt (register A)
#else
setBit(TIMSK, OCIE0A); // enable interrupt (register A)
#endif
OCR0A = uint8_t(divisor); // set output compare register A
TCNT0 = 0; // reset counter register
break;
case 1: // 16bit Timer/Counter
#ifdef TCCR1B
TCCR1A = 0x00;
TCCR1B = (TCCR1B & ~0x07) | prescaler;
setBit(TCCR1B, WGM12);
#else
TCCR1 = (TCCR1 & ~0x0F) | prescaler;
#endif
#ifdef TIMSK1
setBit(TIMSK1, OCIE1A); // enable interrupt (register A)
#else
setBit(TIMSK, OCIE1A); // enable interrupt (register A)
#endif
#ifdef OCR1AH
OCR1AH = (divisor & 0xFF00) >> 8;
OCR1AL = divisor & 0xFF;
#else
OCR1A = uint8_t(divisor);
#endif
TCNT1 = 0;
break;
#ifdef TCCR2A
case 2: // 8bit Timer/Counter
TCCR2A = 0x02;
TCCR2B = prescaler;
clearBit(TCCR2B, WGM22);
setBit(TIMSK2, OCIE2A);
OCR2A = uint8_t(divisor);
TCNT2 = 0;
break;
#endif
#ifdef TCCR3A
case 3: // 16bit Timer/Counter
TCCR3A = 0x00;
TCCR3B = prescaler;
setBit(TCCR3B, WGM32);
setBit(TIMSK3, OCIE3A);
OCR3AH = (divisor & 0xFF00) >> 8;
OCR3AL = divisor & 0xFF;
TCNT3 = 0;
break;
#endif
default:
DebugOXOcard_println(F("invalid timerNr!"));
for(;;);
}
sei();
}
/* ======================= Private class Functions ========================== */
/** -------------------------------------------------------------------------
* \fn iBeaconNameToIBeaconUUID
* \brief converts given iBeacon name string (max. 20 characters)
* into hex values for uuid, marjor and minor
*
* \param beaconName iBeacon name (max. 20 characters)
* \param iBeacon iBeacon structure pointer (see struct in HM11.h file)
* \return None
--------------------------------------------------------------------------- */
void OXOcard::iBeaconNameToIBeaconUUID(String beaconName, HM11::iBeaconData_t *iBeacon)
{
char hexCharArray[20*2];
for (uint8_t i = 0; i < 20*2; i++) hexCharArray[i] = '1'; // init with '1' since the HM-11 doesn't allow '0'
//DebugOXOcard_print("String(hexCharArray) = "); DebugOXOcard_println(String(hexCharArray));
for (uint8_t i = 0; i < beaconName.length(); i++)
{
String tempStr = HM11::byteToHexString(uint8_t(beaconName[i]));
hexCharArray[i*2] = tempStr[0];
hexCharArray[i*2+1] = tempStr[1];
}
//DebugOXOcard_print("String(hexCharArray) = "); DebugOXOcard_println(String(hexCharArray));
iBeacon->uuid = "";
for (uint8_t i = 0; i < 16*2; i++) iBeacon->uuid.concat(hexCharArray[i]);
//DebugOXOcard_print("iBeacon->uuid = "); DebugOXOcard_println(iBeacon->uuid);
iBeacon->marjor = 0;
for (uint8_t i = 16*2; i < 18*2; i++) iBeacon->marjor += uint8_t(hexCharArray[i] - '0');
//DebugOXOcard_print("iBeacon->marjor = "); DebugOXOcard_println(iBeacon->marjor);
iBeacon->minor = 0;
for (uint8_t i = 18*2; i < 20*2; i++) iBeacon->minor += uint8_t(hexCharArray[i] - '0');
//DebugOXOcard_print("iBeacon->minor = "); DebugOXOcard_println(iBeacon->minor);
}
/* Interrupts =============================================================== */
/** -------------------------------------------------------------------------
* \fn ISR (timer1 OCIE1A interrupt TIMER1_COMPA)
* \brief timer interrupt service routine (handler)
* (f_isr = fcpu / (prescaler * frequency_divisor))
*
* \param 'TIMER1_COMPA vector'
* \return None
--------------------------------------------------------------------------- */
ISR (TIMER1_COMPA_vect)
{
autoTurnOffCnt++;
if (autoTurnOffCnt >= autoTurnOffAfter)
{
autoTurnOffCnt = 0;
goingToTurnOff = true;
}
}
/** -------------------------------------------------------------------------
* \fn ISR (external interrupt PCINT2)
* \brief interrupt service routine (handler) for the wake-up-interrupt
* (PCINT2)
*
* \requ <avr/sleep.h>
*
* \param 'PCINT0 vector'
* \return None
--------------------------------------------------------------------------- */
ISR(PCINT2_vect)
{
/* disable wake up interrupt INTn */
clearBit(PCICR, PCIE2); // BUTTON 1
clearBit(EIMSK, INT1); // BUTTON 2
clearBit(EIMSK, INT0); // BUTTON 3
sleep_disable();
DebugOXOcard_println(F("wkUpInt1 occured, waking up..."));
}
/** -------------------------------------------------------------------------
* \fn ISR (external interrupt INT1)
* \brief interrupt service routine (handler) for the wake-up-interrupt
* (INT1)
*
* \requ <avr/sleep.h>
*
* \param 'INT1 vector'
* \return None
--------------------------------------------------------------------------- */
ISR(INT1_vect)
{
/* disable wake up interrupt INTn */
clearBit(PCICR, PCIE2); // BUTTON 1
clearBit(EIMSK, INT1); // BUTTON 2
clearBit(EIMSK, INT0); // BUTTON 3
sleep_disable();
DebugOXOcard_println(F("wkUpInt2 occured, waking up..."));
}
/** -------------------------------------------------------------------------
* \fn ISR (external interrupt INT0)
* \brief interrupt service routine (handler) for the wake-up-interrupt
* (INT0)
*
* \requ <avr/sleep.h>
*
* \param 'INT0 vector'
* \return None
--------------------------------------------------------------------------- */
ISR(INT0_vect)
{
/* disable wake up interrupt INTn */
clearBit(PCICR, PCIE2); // BUTTON 1
clearBit(EIMSK, INT1); // BUTTON 2
clearBit(EIMSK, INT0); // BUTTON 3
sleep_disable();
DebugOXOcard_println(F("wkUpInt3 occured, waking up..."));
}