Files
sics/site_ansto/hardsup/Digital/device.h
Douglas Clowes 9ca1b3199a Debounce digital inputs
r1387 | dcl | 2007-01-09 11:15:02 +1100 (Tue, 09 Jan 2007) | 2 lines
2012-11-15 12:56:09 +11:00

71 lines
1.9 KiB
C

#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