The firmware of the Grove Node

Dependencies:   BLE_API color_pixels mbed-src-nrf51822 nRF51822

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Committer:
yihui
Date:
Thu Jun 04 09:34:13 2015 +0000
Revision:
10:f34ff4e47741
0.01 - sync input & output with android app

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 10:f34ff4e47741 1
yihui 10:f34ff4e47741 2 #include "udriver.h"
yihui 10:f34ff4e47741 3 #include "mbed.h"
yihui 10:f34ff4e47741 4
yihui 10:f34ff4e47741 5 uint8_t time_sensor_second = 0;
yihui 10:f34ff4e47741 6
yihui 10:f34ff4e47741 7
yihui 10:f34ff4e47741 8 void time_sensor_tick(void)
yihui 10:f34ff4e47741 9 {
yihui 10:f34ff4e47741 10 time_sensor_second++;
yihui 10:f34ff4e47741 11 if (time_sensor_second >= 60) {
yihui 10:f34ff4e47741 12 time_sensor_second = 0;
yihui 10:f34ff4e47741 13 }
yihui 10:f34ff4e47741 14 }
yihui 10:f34ff4e47741 15
yihui 10:f34ff4e47741 16 int time_sensor_init(void *obj, void *params)
yihui 10:f34ff4e47741 17 {
yihui 10:f34ff4e47741 18 Ticker *ticker = new Ticker();
yihui 10:f34ff4e47741 19 *((Ticker **)obj) = ticker;
yihui 10:f34ff4e47741 20
yihui 10:f34ff4e47741 21 ticker->attach(time_sensor_tick, 1);
yihui 10:f34ff4e47741 22
yihui 10:f34ff4e47741 23 return 0;
yihui 10:f34ff4e47741 24 }
yihui 10:f34ff4e47741 25
yihui 10:f34ff4e47741 26
yihui 10:f34ff4e47741 27 int time_sensor_read(void *obj, void *data)
yihui 10:f34ff4e47741 28 {
yihui 10:f34ff4e47741 29 *(float *)data = time_sensor_second;
yihui 10:f34ff4e47741 30
yihui 10:f34ff4e47741 31 return 0;
yihui 10:f34ff4e47741 32 }
yihui 10:f34ff4e47741 33
yihui 10:f34ff4e47741 34 int time_sensor_write(void *obj, void *data)
yihui 10:f34ff4e47741 35 {
yihui 10:f34ff4e47741 36 return 0;
yihui 10:f34ff4e47741 37 }
yihui 10:f34ff4e47741 38
yihui 10:f34ff4e47741 39 int time_sensor_fini(void *obj)
yihui 10:f34ff4e47741 40 {
yihui 10:f34ff4e47741 41 Ticker *ptr = *(Ticker **)obj;
yihui 10:f34ff4e47741 42 ptr->detach();
yihui 10:f34ff4e47741 43 delete ptr;
yihui 10:f34ff4e47741 44
yihui 10:f34ff4e47741 45 return 0;
yihui 10:f34ff4e47741 46 }
yihui 10:f34ff4e47741 47
yihui 10:f34ff4e47741 48 driver_t time_sensor_driver =
yihui 10:f34ff4e47741 49 {
yihui 10:f34ff4e47741 50 .init = time_sensor_init,
yihui 10:f34ff4e47741 51 .read = time_sensor_read,
yihui 10:f34ff4e47741 52 .write = time_sensor_write,
yihui 10:f34ff4e47741 53 .fini = time_sensor_fini,
yihui 10:f34ff4e47741 54
yihui 10:f34ff4e47741 55 .d = 1,
yihui 10:f34ff4e47741 56 };