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

Dependencies:   UniGraphic mbed vt100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers edge_sensor.h Source File

edge_sensor.h

00001 #ifndef _EDGE_SENSOR_H_
00002 #define _EDGE_SENSOR_H_
00003 /**
00004  * edge_sensor super class of each sensor manager class
00005  */
00006 #include "edge_time.h"
00007 #include "afLib.h"
00008 #include "af_mgr.h"
00009 #include <ILI9341.h>
00010 #include "edge_chart.h"
00011 
00012 class edge_sensor {
00013 public:
00014 /**
00015  * constructor 
00016  */
00017     edge_sensor() ;
00018 
00019 /**
00020  * destructor
00021  */
00022     ~edge_sensor() ;
00023 
00024 /**
00025  * reset reset property valuse of edge_sensor
00026  */
00027     virtual void    reset(void) ;
00028 
00029 /**
00030  * assign _id manually
00031  */
00032     virtual void    setId(uint16_t id) { _id = id ; }
00033     
00034     virtual uint16_t getId(void) { return _id ; } 
00035     
00036 /**
00037  * enable the edge_sensor 
00038  */
00039     virtual void    enable(void) ;
00040     
00041 /**
00042  * disable the edge_sensor
00043  */
00044     virtual void    disable(void) ;
00045     
00046 /**
00047  * test if the edge_sensor is enabled (or not)
00048  * @returns true: the sensor is enabled false: the sensor is disabled
00049  */
00050     virtual bool    isEnabled(void) ;
00051 
00052 /**
00053  * prepare the sensor for sampling
00054  */
00055     virtual void    prepare(void) ;
00056     
00057 /**
00058  * sample trigger sampling action of the sensor and acquire the data
00059  * @returns 0:success non-0:failure
00060  */
00061     virtual int    sample(void) ;
00062 
00063     
00064 /**
00065  * deliver the sampled data to the afero cloud via setAttributes
00066  */
00067     virtual int     deliver(void) ;
00068     
00069 /**
00070  * show the value(s) to the display (TFT)
00071  */
00072     virtual void    show(void) ;
00073     
00074 /**
00075  * toJson convert sampled data to json format
00076  * @param buf char* string buf to store the json string
00077  */
00078     virtual void    toJson(char *buf) ;
00079     
00080 /**
00081  * display timestamp in human readable format
00082  * @parm ts int32_t timestamp value to display
00083  */
00084     virtual void    displayTime(int32_t ts) ;
00085 
00086 /**
00087  * setInterval assign sampling interval time (in sec)
00088  * @param interval uint16_t the value to assign
00089  */
00090     void            setInterval(uint16_t interval) ;
00091     
00092 /**
00093  * getInterval get sampling interval time (in sec)
00094  * @returns the interval time in uint16_t
00095  */
00096     uint16_t        getInterval(void) ;
00097     
00098 /**
00099  * getStatus get current status of the state machine
00100  * @returns current status as int
00101  */
00102     int             getStatus(void) ;
00103     
00104 /**
00105  * advanceStatus proceed status into the next state
00106  * @returns advanced status
00107  */
00108     int             advanceStatus(void) ;
00109 
00110 /**
00111  * runStateMachine run the statemachine for single cycle
00112  * @returns the result status
00113  */
00114     virtual int     runStateMachine(void) ;
00115 protected:
00116     uint16_t        _id ;
00117     bool            _enable ;
00118     uint32_t        _interval ;
00119     int             _status ;
00120     int             _error_count ;
00121     int             _sample_error ;
00122     int             _prev_status ;
00123     uint32_t        _end_interval ;
00124     uint32_t        _sampled_time ;
00125     char            _str_buf[256] ;
00126 } ;
00127 
00128 /* may be, we had better use enum here */
00129 #define EDGE_SENSOR_INACTIVE    0
00130 #define EDGE_SENSOR_WAIT        1
00131 #define EDGE_SENSOR_READY       2
00132 #define EDGE_SENSOR_PREPARED    3
00133 #define EDGE_SENSOR_SAMPLED     4
00134 #define EDGE_SENSOR_DELIVERED   5
00135 #define EDGE_SENSOR_DISPLAYED   6
00136 
00137 /* _id numbers for sensors */
00138 #define SENSOR_ID_ACCEL          0
00139 #define SENSOR_ID_COLOR1         1
00140 #define SENSOR_ID_COLOR2         2
00141 #define SENSOR_ID_TEMP           3
00142 #define SENSOR_ID_PRESS          4
00143 
00144 /* Y position of SUMMARY MODE */
00145 #define EDGE_SUMMARY_X          10
00146 #define EDGE_SUMMARY_TIME_Y     10
00147 #define EDGE_SUMMARY_ACCEL_Y    45
00148 #define EDGE_SUMMARY_PRESS_Y    80
00149 #define EDGE_SUMMARY_COLOR1_Y   115
00150 #define EDGE_SUMMARY_COLOR2_Y   150
00151 #define EDGE_SUMMARY_TEMP_Y     185
00152 
00153 #define EDGE_SAMPLE_SUCCESS     0
00154 #define SAMPLE_ERROR_TOLERANCE  3
00155 
00156 extern ILI9341             *display     ;
00157 extern int                 display_mode ;
00158 extern const unsigned char Arial12x12[] ;
00159 extern const unsigned char Arial24x23[] ;
00160 extern const unsigned char Arial28x28[] ;
00161 
00162 #endif /* _EDGE_SENSOR_H_ */