Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)

Dependencies:   UniGraphic mbed vt100

18-Jun-2018 外部センサの電源オン・オフ機能は下位互換の為に無効になっていました。 この版で再度有効にしました。

Committer:
Rhyme
Date:
Fri Apr 13 04:19:23 2018 +0000
Revision:
0:846e2321c637
power to color sensor on/off test OK. Currently the function is disabled.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:846e2321c637 1 #ifndef _EDGE_SENSOR_H_
Rhyme 0:846e2321c637 2 #define _EDGE_SENSOR_H_
Rhyme 0:846e2321c637 3 /**
Rhyme 0:846e2321c637 4 * edge_sensor super class of each sensor manager class
Rhyme 0:846e2321c637 5 */
Rhyme 0:846e2321c637 6 #include "edge_time.h"
Rhyme 0:846e2321c637 7 #include "afLib.h"
Rhyme 0:846e2321c637 8 #include "af_mgr.h"
Rhyme 0:846e2321c637 9 #include <ILI9341.h>
Rhyme 0:846e2321c637 10 #include "edge_chart.h"
Rhyme 0:846e2321c637 11
Rhyme 0:846e2321c637 12 class edge_sensor {
Rhyme 0:846e2321c637 13 public:
Rhyme 0:846e2321c637 14 /**
Rhyme 0:846e2321c637 15 * constructor
Rhyme 0:846e2321c637 16 */
Rhyme 0:846e2321c637 17 edge_sensor() ;
Rhyme 0:846e2321c637 18
Rhyme 0:846e2321c637 19 /**
Rhyme 0:846e2321c637 20 * destructor
Rhyme 0:846e2321c637 21 */
Rhyme 0:846e2321c637 22 ~edge_sensor() ;
Rhyme 0:846e2321c637 23
Rhyme 0:846e2321c637 24 /**
Rhyme 0:846e2321c637 25 * reset reset property valuse of edge_sensor
Rhyme 0:846e2321c637 26 */
Rhyme 0:846e2321c637 27 virtual void reset(void) ;
Rhyme 0:846e2321c637 28
Rhyme 0:846e2321c637 29 /**
Rhyme 0:846e2321c637 30 * assign _id manually
Rhyme 0:846e2321c637 31 */
Rhyme 0:846e2321c637 32 virtual void setId(uint16_t id) { _id = id ; }
Rhyme 0:846e2321c637 33
Rhyme 0:846e2321c637 34 virtual uint16_t getId(void) { return _id ; }
Rhyme 0:846e2321c637 35
Rhyme 0:846e2321c637 36 /**
Rhyme 0:846e2321c637 37 * enable the edge_sensor
Rhyme 0:846e2321c637 38 */
Rhyme 0:846e2321c637 39 virtual void enable(void) ;
Rhyme 0:846e2321c637 40
Rhyme 0:846e2321c637 41 /**
Rhyme 0:846e2321c637 42 * disable the edge_sensor
Rhyme 0:846e2321c637 43 */
Rhyme 0:846e2321c637 44 virtual void disable(void) ;
Rhyme 0:846e2321c637 45
Rhyme 0:846e2321c637 46 /**
Rhyme 0:846e2321c637 47 * test if the edge_sensor is enabled (or not)
Rhyme 0:846e2321c637 48 * @returns true: the sensor is enabled false: the sensor is disabled
Rhyme 0:846e2321c637 49 */
Rhyme 0:846e2321c637 50 virtual bool isEnabled(void) ;
Rhyme 0:846e2321c637 51
Rhyme 0:846e2321c637 52 /**
Rhyme 0:846e2321c637 53 * prepare the sensor for sampling
Rhyme 0:846e2321c637 54 */
Rhyme 0:846e2321c637 55 virtual void prepare(void) ;
Rhyme 0:846e2321c637 56
Rhyme 0:846e2321c637 57 /**
Rhyme 0:846e2321c637 58 * sample trigger sampling action of the sensor and acquire the data
Rhyme 0:846e2321c637 59 * @returns 0:success non-0:failure
Rhyme 0:846e2321c637 60 */
Rhyme 0:846e2321c637 61 virtual int sample(void) ;
Rhyme 0:846e2321c637 62
Rhyme 0:846e2321c637 63
Rhyme 0:846e2321c637 64 /**
Rhyme 0:846e2321c637 65 * deliver the sampled data to the afero cloud via setAttributes
Rhyme 0:846e2321c637 66 */
Rhyme 0:846e2321c637 67 virtual int deliver(void) ;
Rhyme 0:846e2321c637 68
Rhyme 0:846e2321c637 69 /**
Rhyme 0:846e2321c637 70 * show the value(s) to the display (TFT)
Rhyme 0:846e2321c637 71 */
Rhyme 0:846e2321c637 72 virtual void show(void) ;
Rhyme 0:846e2321c637 73
Rhyme 0:846e2321c637 74 /**
Rhyme 0:846e2321c637 75 * toJson convert sampled data to json format
Rhyme 0:846e2321c637 76 * @param buf char* string buf to store the json string
Rhyme 0:846e2321c637 77 */
Rhyme 0:846e2321c637 78 virtual void toJson(char *buf) ;
Rhyme 0:846e2321c637 79
Rhyme 0:846e2321c637 80 /**
Rhyme 0:846e2321c637 81 * display timestamp in human readable format
Rhyme 0:846e2321c637 82 * @parm ts int32_t timestamp value to display
Rhyme 0:846e2321c637 83 */
Rhyme 0:846e2321c637 84 virtual void displayTime(int32_t ts) ;
Rhyme 0:846e2321c637 85
Rhyme 0:846e2321c637 86 /**
Rhyme 0:846e2321c637 87 * setInterval assign sampling interval time (in sec)
Rhyme 0:846e2321c637 88 * @param interval uint16_t the value to assign
Rhyme 0:846e2321c637 89 */
Rhyme 0:846e2321c637 90 void setInterval(uint16_t interval) ;
Rhyme 0:846e2321c637 91
Rhyme 0:846e2321c637 92 /**
Rhyme 0:846e2321c637 93 * getInterval get sampling interval time (in sec)
Rhyme 0:846e2321c637 94 * @returns the interval time in uint16_t
Rhyme 0:846e2321c637 95 */
Rhyme 0:846e2321c637 96 uint16_t getInterval(void) ;
Rhyme 0:846e2321c637 97
Rhyme 0:846e2321c637 98 /**
Rhyme 0:846e2321c637 99 * getStatus get current status of the state machine
Rhyme 0:846e2321c637 100 * @returns current status as int
Rhyme 0:846e2321c637 101 */
Rhyme 0:846e2321c637 102 int getStatus(void) ;
Rhyme 0:846e2321c637 103
Rhyme 0:846e2321c637 104 /**
Rhyme 0:846e2321c637 105 * advanceStatus proceed status into the next state
Rhyme 0:846e2321c637 106 * @returns advanced status
Rhyme 0:846e2321c637 107 */
Rhyme 0:846e2321c637 108 int advanceStatus(void) ;
Rhyme 0:846e2321c637 109
Rhyme 0:846e2321c637 110 /**
Rhyme 0:846e2321c637 111 * runStateMachine run the statemachine for single cycle
Rhyme 0:846e2321c637 112 * @returns the result status
Rhyme 0:846e2321c637 113 */
Rhyme 0:846e2321c637 114 virtual int runStateMachine(void) ;
Rhyme 0:846e2321c637 115 protected:
Rhyme 0:846e2321c637 116 uint16_t _id ;
Rhyme 0:846e2321c637 117 bool _enable ;
Rhyme 0:846e2321c637 118 uint32_t _interval ;
Rhyme 0:846e2321c637 119 int _status ;
Rhyme 0:846e2321c637 120 int _error_count ;
Rhyme 0:846e2321c637 121 int _sample_error ;
Rhyme 0:846e2321c637 122 int _prev_status ;
Rhyme 0:846e2321c637 123 uint32_t _end_interval ;
Rhyme 0:846e2321c637 124 uint32_t _sampled_time ;
Rhyme 0:846e2321c637 125 char _str_buf[256] ;
Rhyme 0:846e2321c637 126 } ;
Rhyme 0:846e2321c637 127
Rhyme 0:846e2321c637 128 /* may be, we had better use enum here */
Rhyme 0:846e2321c637 129 #define EDGE_SENSOR_INACTIVE 0
Rhyme 0:846e2321c637 130 #define EDGE_SENSOR_WAIT 1
Rhyme 0:846e2321c637 131 #define EDGE_SENSOR_READY 2
Rhyme 0:846e2321c637 132 #define EDGE_SENSOR_PREPARED 3
Rhyme 0:846e2321c637 133 #define EDGE_SENSOR_SAMPLED 4
Rhyme 0:846e2321c637 134 #define EDGE_SENSOR_DELIVERED 5
Rhyme 0:846e2321c637 135 #define EDGE_SENSOR_DISPLAYED 6
Rhyme 0:846e2321c637 136
Rhyme 0:846e2321c637 137 /* _id numbers for sensors */
Rhyme 0:846e2321c637 138 #define SENSOR_ID_ACCEL 0
Rhyme 0:846e2321c637 139 #define SENSOR_ID_COLOR1 1
Rhyme 0:846e2321c637 140 #define SENSOR_ID_COLOR2 2
Rhyme 0:846e2321c637 141 #define SENSOR_ID_TEMP 3
Rhyme 0:846e2321c637 142 #define SENSOR_ID_PRESS 4
Rhyme 0:846e2321c637 143
Rhyme 0:846e2321c637 144 /* Y position of SUMMARY MODE */
Rhyme 0:846e2321c637 145 #define EDGE_SUMMARY_X 10
Rhyme 0:846e2321c637 146 #define EDGE_SUMMARY_TIME_Y 10
Rhyme 0:846e2321c637 147 #define EDGE_SUMMARY_ACCEL_Y 45
Rhyme 0:846e2321c637 148 #define EDGE_SUMMARY_PRESS_Y 80
Rhyme 0:846e2321c637 149 #define EDGE_SUMMARY_COLOR1_Y 115
Rhyme 0:846e2321c637 150 #define EDGE_SUMMARY_COLOR2_Y 150
Rhyme 0:846e2321c637 151 #define EDGE_SUMMARY_TEMP_Y 185
Rhyme 0:846e2321c637 152
Rhyme 0:846e2321c637 153 #define EDGE_SAMPLE_SUCCESS 0
Rhyme 0:846e2321c637 154 #define SAMPLE_ERROR_TOLERANCE 3
Rhyme 0:846e2321c637 155
Rhyme 0:846e2321c637 156 extern ILI9341 *display ;
Rhyme 0:846e2321c637 157 extern int display_mode ;
Rhyme 0:846e2321c637 158 extern const unsigned char Arial12x12[] ;
Rhyme 0:846e2321c637 159 extern const unsigned char Arial24x23[] ;
Rhyme 0:846e2321c637 160 extern const unsigned char Arial28x28[] ;
Rhyme 0:846e2321c637 161
Rhyme 0:846e2321c637 162 #endif /* _EDGE_SENSOR_H_ */