The firmware of the Grove Node
Dependencies: BLE_API color_pixels mbed-src-nrf51822 nRF51822
Fork of BLE_LoopbackUART by
udriver/analog_sensor.cpp@11:c0885b74a63a, 2015-06-04 (annotated)
- Committer:
- yihui
- Date:
- Thu Jun 04 12:39:32 2015 +0000
- Revision:
- 11:c0885b74a63a
- Parent:
- 10:f34ff4e47741
fixed direct control bug
Who changed what in which revision?
User | Revision | Line number | New 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 | int analog_sensor_init(void *obj, void *params) |
yihui | 10:f34ff4e47741 | 6 | { |
yihui | 10:f34ff4e47741 | 7 | int pin = *(int *)params; |
yihui | 10:f34ff4e47741 | 8 | AnalogIn *probe = new AnalogIn((PinName)pin); |
yihui | 10:f34ff4e47741 | 9 | *((AnalogIn **)obj) = probe; |
yihui | 10:f34ff4e47741 | 10 | |
yihui | 10:f34ff4e47741 | 11 | return 0; |
yihui | 10:f34ff4e47741 | 12 | } |
yihui | 10:f34ff4e47741 | 13 | |
yihui | 10:f34ff4e47741 | 14 | |
yihui | 10:f34ff4e47741 | 15 | int analog_sensor_read(void *obj, void *data) |
yihui | 10:f34ff4e47741 | 16 | { |
yihui | 10:f34ff4e47741 | 17 | AnalogIn *probe = *(AnalogIn **)obj; |
yihui | 10:f34ff4e47741 | 18 | |
yihui | 10:f34ff4e47741 | 19 | *(float *)data = probe->read() * 100; |
yihui | 10:f34ff4e47741 | 20 | |
yihui | 10:f34ff4e47741 | 21 | return 0; |
yihui | 10:f34ff4e47741 | 22 | } |
yihui | 10:f34ff4e47741 | 23 | |
yihui | 10:f34ff4e47741 | 24 | int analog_sensor_write(void *obj, void *data) |
yihui | 10:f34ff4e47741 | 25 | { |
yihui | 10:f34ff4e47741 | 26 | return 0; |
yihui | 10:f34ff4e47741 | 27 | } |
yihui | 10:f34ff4e47741 | 28 | |
yihui | 10:f34ff4e47741 | 29 | int analog_sensor_fini(void *obj) |
yihui | 10:f34ff4e47741 | 30 | { |
yihui | 10:f34ff4e47741 | 31 | AnalogIn *ptr = *(AnalogIn **)obj; |
yihui | 10:f34ff4e47741 | 32 | delete ptr; |
yihui | 10:f34ff4e47741 | 33 | |
yihui | 10:f34ff4e47741 | 34 | return 0; |
yihui | 10:f34ff4e47741 | 35 | } |
yihui | 10:f34ff4e47741 | 36 | |
yihui | 10:f34ff4e47741 | 37 | driver_t analog_sensor_driver = |
yihui | 10:f34ff4e47741 | 38 | { |
yihui | 10:f34ff4e47741 | 39 | .init = analog_sensor_init, |
yihui | 10:f34ff4e47741 | 40 | .read = analog_sensor_read, |
yihui | 10:f34ff4e47741 | 41 | .write = analog_sensor_write, |
yihui | 10:f34ff4e47741 | 42 | .fini = analog_sensor_fini, |
yihui | 10:f34ff4e47741 | 43 | |
yihui | 10:f34ff4e47741 | 44 | .d = 1, |
yihui | 10:f34ff4e47741 | 45 | }; |