SingingCat  0
application
sensor_dev.h
1 #ifndef SENSORDEV_H
2 #define SENSORDEV_H
3 
12 typedef int (*SENSORCALL)(uint8_t sensorindex);
13 typedef int (*SENSORREADCALL)(uint8_t sensorindex, uint8_t *error); //error=0: OK
14 typedef void (*SENSORSTATUS) (uint8_t sensorindex, char *buf, int bufsize, int *status);
15 typedef struct sensordev {
16  uint8_t cfg_flags; /* see SENSOR_CONFIG_FLAG_XXX below */
17  SENSORCALL power_on; /* power up the sensor. return 0 if ok */
18  SENSORCALL power_down; /* power down the sensor. return 0 if ok */
19  SENSORCALL get_reading_size; /* return size in uint8_ts [1..2] of a single measurement */
20  SENSORREADCALL get_reading; /* return a reading (mandatory) - called within an IRQ! (see notes above) */
21  SENSORSTATUS get_status; /* status to buf in human-readable format plus status value specific to this sensor. status==0 defined as OK */
22  const char *const name; /* ow1:ds18b20 etc.. (mandatory, unique)*/
23  const char *const type; /* temperature, current, ... */
24  const char *const unit; /* celsius, ampere, volt... */
25  const char *const unit_prefix; /* deci, milli, micro etc.. */
26  uint8_t sensorindex; /* some sensors might be called several times with different index. This is specific to the sensor */
27  uint8_t pad;
28 } _sensordev;
29 
33 typedef struct sensorruntime {
34  const struct sensordev * sensor; /* pointer to the sensor in question */
35  uint8_t * buf; /* pointer to data buf */
36  uint16_t bufsize; /* size of buf */
37  uint16_t bytesinbuf; /* byte used */
38  uint16_t values; /* counts how many values have been read */
39  uint16_t valuesize; /* size of each value, as determined when runtime was created */
40  int runctr; /* counts how many millis have actually passed between reads */
41  long runsecs; /* secondctr for submission */
42  uint8_t flags; /* current internal flags for this device */
43  union {
44  uint32_t last_value_uint32;
45  uint16_t last_value_uint16;
46  uint8_t last_value_uint8;
47  };
49 
50 
51 #endif
runtime data per sensor (in-ram)
Definition: sensor_dev.h:33