#ifndef _DEVICE_H_ #define _DEVICE_H_ #define MAX_DEVICES 3 #define SAMPLE_ARRAY_SZ 1000 #include "utility.h" #include "params.h" typedef enum device_state_t { /** The counter has not yet been created or has been destroyed */ device_idle = 0, /** The counter has not yet been started or has been stopped */ device_stopped, /** The counter is counting */ device_running, /** the counter has been paused */ device_paused } DEVICE_STATE; typedef struct device_t { char name[64]; DEVICE_STATE state; /** time of this read */ struct timeval current_time; /** time of last read */ struct timeval previous_time; /** time of next sample closure */ struct timeval sample_timer; /** time of next report generation */ struct timeval report_timer; /** number of polls */ int poll_counter; /** output value */ unsigned int out_value; /** physical device value */ unsigned int value; /** tentative new value */ unsigned int new_value; /** debounce counter */ int new_count; /** Control parameters */ PARAMETERS params; struct device_private_t* private_data; } DEVICE, *pDEVICE; void make_report(DEVICE* device); void device_sample(DEVICE* device); void device_send(DEVICE* device, int n); void device_read(DEVICE* device, int n); void device_write(DEVICE* device, int n, const char *tp); void device_print(DEVICE* device, FILE* fd); void device_report(DEVICE* device); int device_init(DEVICE** cpp, char* name); int device_start(DEVICE* device); int device_stop(DEVICE* device); int device_pause(DEVICE* device); int device_resume(DEVICE* device); int device_command(void* device, const char* cmd); int device_poll(DEVICE* device); void device_term(DEVICE* device); bool device_fatal(int error); void device_errmsg(char* buff, int len); double device_time_to_next_sample(DEVICE* device); double device_time_to_next_report(DEVICE* device); #endif