Stripped-down version of GDP Node Core
Dependencies: EthernetInterface MbedJSONValue SDFileSystem mbed-rtos mbed snail
sensorinterface.h@0:bb17d0395fb8, 2015-05-18 (annotated)
- Committer:
- Trumple
- Date:
- Mon May 18 16:16:15 2015 +0000
- Revision:
- 0:bb17d0395fb8
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Trumple | 0:bb17d0395fb8 | 1 | #ifndef SENSORINTERFACE_H |
Trumple | 0:bb17d0395fb8 | 2 | |
Trumple | 0:bb17d0395fb8 | 3 | #define SENSORINTERFACE_H |
Trumple | 0:bb17d0395fb8 | 4 | |
Trumple | 0:bb17d0395fb8 | 5 | #include "mbed.h" |
Trumple | 0:bb17d0395fb8 | 6 | #include <map> |
Trumple | 0:bb17d0395fb8 | 7 | #include <vector> |
Trumple | 0:bb17d0395fb8 | 8 | |
Trumple | 0:bb17d0395fb8 | 9 | #define I2C_TYPE_HEADER 'T' |
Trumple | 0:bb17d0395fb8 | 10 | #define I2C_REQUEST_HEADER 'R' |
Trumple | 0:bb17d0395fb8 | 11 | #define I2C_DATA_HEADER 'D' |
Trumple | 0:bb17d0395fb8 | 12 | #define I2C_TYPE_PACKET_SIZE 4 |
Trumple | 0:bb17d0395fb8 | 13 | |
Trumple | 0:bb17d0395fb8 | 14 | #define DEBUG |
Trumple | 0:bb17d0395fb8 | 15 | |
Trumple | 0:bb17d0395fb8 | 16 | struct sensor |
Trumple | 0:bb17d0395fb8 | 17 | { |
Trumple | 0:bb17d0395fb8 | 18 | char type; |
Trumple | 0:bb17d0395fb8 | 19 | char packetSize; |
Trumple | 0:bb17d0395fb8 | 20 | char readingSize; |
Trumple | 0:bb17d0395fb8 | 21 | }; |
Trumple | 0:bb17d0395fb8 | 22 | |
Trumple | 0:bb17d0395fb8 | 23 | |
Trumple | 0:bb17d0395fb8 | 24 | struct d_reply |
Trumple | 0:bb17d0395fb8 | 25 | { |
Trumple | 0:bb17d0395fb8 | 26 | char type; |
Trumple | 0:bb17d0395fb8 | 27 | vector<int> readings; |
Trumple | 0:bb17d0395fb8 | 28 | }; |
Trumple | 0:bb17d0395fb8 | 29 | |
Trumple | 0:bb17d0395fb8 | 30 | |
Trumple | 0:bb17d0395fb8 | 31 | class sensorinterface |
Trumple | 0:bb17d0395fb8 | 32 | { |
Trumple | 0:bb17d0395fb8 | 33 | public: |
Trumple | 0:bb17d0395fb8 | 34 | map<char, sensor> sensors; |
Trumple | 0:bb17d0395fb8 | 35 | sensorinterface(); |
Trumple | 0:bb17d0395fb8 | 36 | void requestData(); |
Trumple | 0:bb17d0395fb8 | 37 | bool isDataWaiting(); |
Trumple | 0:bb17d0395fb8 | 38 | d_reply readData(); |
Trumple | 0:bb17d0395fb8 | 39 | private: |
Trumple | 0:bb17d0395fb8 | 40 | map<char, sensor>::iterator currentSensor; |
Trumple | 0:bb17d0395fb8 | 41 | int update(); |
Trumple | 0:bb17d0395fb8 | 42 | void error(int); |
Trumple | 0:bb17d0395fb8 | 43 | sensor& findType(sensor& s, int address); |
Trumple | 0:bb17d0395fb8 | 44 | int sendRequest(char address); |
Trumple | 0:bb17d0395fb8 | 45 | void readySet(); |
Trumple | 0:bb17d0395fb8 | 46 | void readyUnset(); |
Trumple | 0:bb17d0395fb8 | 47 | bool ready; |
Trumple | 0:bb17d0395fb8 | 48 | |
Trumple | 0:bb17d0395fb8 | 49 | I2C i2c; |
Trumple | 0:bb17d0395fb8 | 50 | InterruptIn readyLine; |
Trumple | 0:bb17d0395fb8 | 51 | }; |
Trumple | 0:bb17d0395fb8 | 52 | #endif |