AirDemo1

Dependencies:   BLE_API mbed nRF51822

Committer:
AndreaP
Date:
Thu May 19 11:37:37 2016 +0000
Revision:
0:2b43978ace0e
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndreaP 0:2b43978ace0e 1 #include "mbed.h"
AndreaP 0:2b43978ace0e 2 #include "nRF5xGap.h"
AndreaP 0:2b43978ace0e 3
AndreaP 0:2b43978ace0e 4 #define DEMOBOARD 1
AndreaP 0:2b43978ace0e 5 #if DEMOBOARD
AndreaP 0:2b43978ace0e 6 InterruptIn powerButtonOn(P0_17);
AndreaP 0:2b43978ace0e 7 InterruptIn powerButtonOff(P0_18);
AndreaP 0:2b43978ace0e 8 DigitalOut greenLed(P0_21);
AndreaP 0:2b43978ace0e 9 DigitalOut blueLed(P0_22);
AndreaP 0:2b43978ace0e 10 DigitalOut redLed(P0_23);
AndreaP 0:2b43978ace0e 11 #else
AndreaP 0:2b43978ace0e 12 InterruptIn powerButton(P0_18);
AndreaP 0:2b43978ace0e 13 DigitalOut greenLed(P0_12);
AndreaP 0:2b43978ace0e 14 DigitalOut blueLed(P0_15);
AndreaP 0:2b43978ace0e 15 DigitalOut redLed(P0_16);
AndreaP 0:2b43978ace0e 16 #endif
AndreaP 0:2b43978ace0e 17
AndreaP 0:2b43978ace0e 18 #if DEMOBOARD
AndreaP 0:2b43978ace0e 19 #define LED_ON 0
AndreaP 0:2b43978ace0e 20 #define LED_OFF 1
AndreaP 0:2b43978ace0e 21 #else
AndreaP 0:2b43978ace0e 22 #define LED_ON 1
AndreaP 0:2b43978ace0e 23 #define LED_OFF 0
AndreaP 0:2b43978ace0e 24 #endif
AndreaP 0:2b43978ace0e 25
AndreaP 0:2b43978ace0e 26 volatile uint8_t state = 255;
AndreaP 0:2b43978ace0e 27 Ticker timer;
AndreaP 0:2b43978ace0e 28 volatile uint8_t lastState = 0;
AndreaP 0:2b43978ace0e 29
AndreaP 0:2b43978ace0e 30 void powerButtonOnPressedCallback(void)
AndreaP 0:2b43978ace0e 31 {
AndreaP 0:2b43978ace0e 32 //NRF_POWER->SYSTEMOFF=0;
AndreaP 0:2b43978ace0e 33 state= 1;
AndreaP 0:2b43978ace0e 34 }
AndreaP 0:2b43978ace0e 35
AndreaP 0:2b43978ace0e 36 void powerButtonOffPressedCallback(void)
AndreaP 0:2b43978ace0e 37 {
AndreaP 0:2b43978ace0e 38 //NRF_POWER->SYSTEMOFF=1;
AndreaP 0:2b43978ace0e 39 state= 11;
AndreaP 0:2b43978ace0e 40 }
AndreaP 0:2b43978ace0e 41 void cbToON()
AndreaP 0:2b43978ace0e 42 {
AndreaP 0:2b43978ace0e 43 timer.detach();
AndreaP 0:2b43978ace0e 44 state = 2;
AndreaP 0:2b43978ace0e 45 }
AndreaP 0:2b43978ace0e 46
AndreaP 0:2b43978ace0e 47 void cbToOFF()
AndreaP 0:2b43978ace0e 48 {
AndreaP 0:2b43978ace0e 49 timer.detach();
AndreaP 0:2b43978ace0e 50 state = 12;
AndreaP 0:2b43978ace0e 51 }
AndreaP 0:2b43978ace0e 52
AndreaP 0:2b43978ace0e 53 int main() {
AndreaP 0:2b43978ace0e 54 //set event button
AndreaP 0:2b43978ace0e 55 powerButtonOn.fall(powerButtonOnPressedCallback);
AndreaP 0:2b43978ace0e 56 powerButtonOff.fall(powerButtonOffPressedCallback);
AndreaP 0:2b43978ace0e 57
AndreaP 0:2b43978ace0e 58 blueLed = LED_OFF;
AndreaP 0:2b43978ace0e 59 greenLed = LED_OFF;
AndreaP 0:2b43978ace0e 60 redLed = LED_OFF;
AndreaP 0:2b43978ace0e 61
AndreaP 0:2b43978ace0e 62 printf("\r\nInit\r\n");
AndreaP 0:2b43978ace0e 63
AndreaP 0:2b43978ace0e 64 //NRF_POWER->SYSTEMOFF=0; //power ON
AndreaP 0:2b43978ace0e 65 //sd_power_system_off();
AndreaP 0:2b43978ace0e 66
AndreaP 0:2b43978ace0e 67 while(1) {
AndreaP 0:2b43978ace0e 68 if(lastState != state) {
AndreaP 0:2b43978ace0e 69 lastState = state;
AndreaP 0:2b43978ace0e 70 printf("STATO %d\r\n", state);
AndreaP 0:2b43978ace0e 71 }
AndreaP 0:2b43978ace0e 72 switch(state) {
AndreaP 0:2b43978ace0e 73 case 1:
AndreaP 0:2b43978ace0e 74 printf("Stato 1\r\n");
AndreaP 0:2b43978ace0e 75 blueLed = LED_ON;
AndreaP 0:2b43978ace0e 76 timer.attach(cbToON, 1.0);
AndreaP 0:2b43978ace0e 77 state = 255;
AndreaP 0:2b43978ace0e 78 break;
AndreaP 0:2b43978ace0e 79 case 2:
AndreaP 0:2b43978ace0e 80 printf("Stato 2\r\n");
AndreaP 0:2b43978ace0e 81 NRF_POWER->SYSTEMOFF=0; //power ON
AndreaP 0:2b43978ace0e 82 state = 255;
AndreaP 0:2b43978ace0e 83 break;
AndreaP 0:2b43978ace0e 84 case 11:
AndreaP 0:2b43978ace0e 85 printf("Stato 11\r\n");
AndreaP 0:2b43978ace0e 86 blueLed = LED_OFF;
AndreaP 0:2b43978ace0e 87 timer.attach(cbToOFF, 1.0);
AndreaP 0:2b43978ace0e 88 state = 255;
AndreaP 0:2b43978ace0e 89 break;
AndreaP 0:2b43978ace0e 90 case 12:
AndreaP 0:2b43978ace0e 91 printf("Stato 12\r\n");
AndreaP 0:2b43978ace0e 92 NRF_POWER->SYSTEMOFF=1; //power OFF
AndreaP 0:2b43978ace0e 93 break;
AndreaP 0:2b43978ace0e 94 case 255:
AndreaP 0:2b43978ace0e 95 break;
AndreaP 0:2b43978ace0e 96 default:
AndreaP 0:2b43978ace0e 97 break;
AndreaP 0:2b43978ace0e 98 }
AndreaP 0:2b43978ace0e 99 }
AndreaP 0:2b43978ace0e 100 }