example firmware for nRF51-Dongle to use with Opentrigger
Dependencies: BLE_API mbed nRF51822
Fork of BLE_Button by
Diff: main.cpp
- Revision:
- 19:3807de5c6a58
- Parent:
- 18:2b328834f64f
- Child:
- 20:7d2043754467
diff -r 2b328834f64f -r 3807de5c6a58 main.cpp --- a/main.cpp Tue Jun 14 18:14:30 2016 +0000 +++ b/main.cpp Tue Jun 21 19:22:32 2016 +0000 @@ -34,6 +34,7 @@ const uint16_t MIN_ADVERT_INTERVAL = 50; /* msec */ static uint8_t gpio_states[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; /* initial state is up */ +static uint8_t event_id = 0; enum { RELEASED = 0, @@ -52,6 +53,7 @@ * BLE device API from the main thread. */ buttonState = PRESSED; gpio_states[0]=0x00; + event_id++; } void button0ReleasedCallback(void) @@ -60,20 +62,21 @@ * BLE device API from the main thread. */ buttonState = RELEASED; gpio_states[0]=0x01; + event_id++; } // Callbacks for the other 5 Buttons -void button1PressedCallback(void) { buttonState = PRESSED; gpio_states[1]=0x00; } -void button1ReleasedCallback(void){ buttonState = RELEASED; gpio_states[1]=0x01; } -void button2PressedCallback(void) { buttonState = PRESSED; gpio_states[2]=0x00; } -void button2ReleasedCallback(void){ buttonState = RELEASED; gpio_states[2]=0x01; } -void button3PressedCallback(void) { buttonState = PRESSED; gpio_states[3]=0x00; } -void button3ReleasedCallback(void){ buttonState = RELEASED; gpio_states[3]=0x01; } -void button4PressedCallback(void) { buttonState = PRESSED; gpio_states[4]=0x00; } -void button4ReleasedCallback(void){ buttonState = RELEASED; gpio_states[4]=0x01; } -void button5PressedCallback(void) { buttonState = PRESSED; gpio_states[5]=0x00; } -void button5ReleasedCallback(void){ buttonState = RELEASED; gpio_states[5]=0x01; } +void button1PressedCallback(void) { buttonState = PRESSED; gpio_states[1]=0x00; event_id++; } +void button1ReleasedCallback(void){ buttonState = RELEASED; gpio_states[1]=0x01; event_id++; } +void button2PressedCallback(void) { buttonState = PRESSED; gpio_states[2]=0x00; event_id++; } +void button2ReleasedCallback(void){ buttonState = RELEASED; gpio_states[2]=0x01; event_id++; } +void button3PressedCallback(void) { buttonState = PRESSED; gpio_states[3]=0x00; event_id++; } +void button3ReleasedCallback(void){ buttonState = RELEASED; gpio_states[3]=0x01; event_id++; } +void button4PressedCallback(void) { buttonState = PRESSED; gpio_states[4]=0x00; event_id++; } +void button4ReleasedCallback(void){ buttonState = RELEASED; gpio_states[4]=0x01; event_id++; } +void button5PressedCallback(void) { buttonState = PRESSED; gpio_states[5]=0x00; event_id++; } +void button5ReleasedCallback(void){ buttonState = RELEASED; gpio_states[5]=0x01; event_id++; } // Just in case void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) @@ -115,14 +118,15 @@ // http://tokencube.com/bluetooth-sensor.html uint8_t data[] = { - 0xee, 0xff, // Tokencube Manufacturer ID - 0x04, // Token Module Version - 0x01, // Firmware Version - 0x11, // Page 1 of 1 - 0x07, gpioSet() ? 0x01 : 0x00, // pir value (0x00 = off, 0x01 = on) - // custom data - state of all 6 gpio's - // 0x00 = down, 0x01 = up - 0x0F, gpio_states[0], gpio_states[1], gpio_states[2], gpio_states[3], gpio_states[4], gpio_states[5] + 0xee, 0xff, // Tokencube Manufacturer ID + 0x04, // Token Module Version + 0x01, // Firmware Version + 0x11, // Page 1 of 1 + 0x07, gpioSet() ? 0x01 : 0x00, // PIR value (0x00 = off, 0x01 = on) + 0x0F, event_id, // EventId (0x00 - 0xFF, every time a button gets pressed, the EventId changes) + gpio_states[0], gpio_states[1], // 6 GPIO Values (0x00 = down, 0x01 = up) + gpio_states[2], gpio_states[3], + gpio_states[4], gpio_states[5], }; __enable_irq();