aboutsummaryrefslogtreecommitdiffstats
path: root/es51984.h
blob: 9a972a4f476ba6ec5e543b1e6d736c7b6dcca32e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef ES51984_H_
#define ES51984_H_

/* Cyrustek ES 51984 digital multimeter RS232 signal interpreter. */


/** struct es51984 - ES51984 device data structure.
 * This structure is opaque to the API user. */
struct es51984;

/** enum es51984_board_type - The board type the chip is soldered onto.
 */
enum es51984_board_type {
	ES51984_BOARD_UNKNOWN,
	ES51984_BOARD_AMPROBE_35XPA,	/* The Amprobe 35XP-A multimeter */
};

#define ES51984_PACK(value)		((0x30 | (value)) & 0x7F)

/** enum es51984_func - The active device function */
enum es51984_func {
	ES51984_FUNC_VOLTAGE		= ES51984_PACK(0xB), /* Voltage measurement */
	ES51984_FUNC_UA_CURRENT		= ES51984_PACK(0xD), /* Micro-amps current measurement */
	ES51984_FUNC_MA_CURRENT		= ES51984_PACK(0xF), /* Milli-amps current measurement */
	ES51984_FUNC_AUTO_CURRENT	= ES51984_PACK(0x0), /* Auto current measurement */
	ES51984_FUNC_MAN_CURRENT	= ES51984_PACK(0x9), /* Manual current measurement */
	ES51984_FUNC_OHMS		= ES51984_PACK(0x3), /* Resistance measurement */
	ES51984_FUNC_CONT		= ES51984_PACK(0x5), /* Continuity measurement */
	ES51984_FUNC_DIODE		= ES51984_PACK(0x1), /* Diode measurement */
	ES51984_FUNC_FREQUENCY		= ES51984_PACK(0x2), /* Frequency measurement */
	ES51984_FUNC_CAPACITOR		= ES51984_PACK(0x6), /* Capacitor measurement */
	ES51984_FUNC_TEMP		= ES51984_PACK(0x4), /* Temperature measurement */
	ES51984_FUNC_ADP0		= ES51984_PACK(0xE), /* ADP0 */
	ES51984_FUNC_ADP1		= ES51984_PACK(0xC), /* ADP1 */
	ES51984_FUNC_ADP2		= ES51984_PACK(0x8), /* ADP2 */
	ES51984_FUNC_ADP3		= ES51984_PACK(0xA), /* ADP3 */
};

/** struct es51984_sample - Data sample of a measurement.
 *
 * @function: The active device function.
 * @value: The measured value.
 * @dc_mode: Boolean. DC or AC mode.
 * @auto_mode: Boolean. Automatic or manual mode.
 * @overflow: Boolean. Overflow condition present.
 * @degree: Boolean. Degree or Farenheit. Only for FUNC_TEMP.
 * @batt_low: Boolean. Battery low condition.
 * @hold: Boolean. Hold is activated. This does not influence the measurement.
 */
struct es51984_sample {
	enum es51984_func function;
	double value;
	int dc_mode;
	int auto_mode;
	int overflow;
	int degree;
	int batt_low;
	int hold;

	enum es51984_board_type board;
};

/** es51984_get_units - Get units identifier string for the value of a sample.
 * @sample: The sample.
 */
const char * es51984_get_units(const struct es51984_sample *sample);

/** es51984_get_sample - Read a sample.
 *
 * Returns zero on success, or a negative error on failure.
 * If non-blocking and no sample is available, returns -EAGAIN.
 * Returns -EPIPE, if synchronization was lost. es51984_sync() must
 * be called to resolve this error condition.
 *
 * @es: The interface.
 * @sample: Pointer to the sample buffer.
 * @blocking: If true, block until a sample arrives.
 * @debug: If true, enable debug messages.
 */
int es51984_get_sample(struct es51984 *es,
		       struct es51984_sample *sample,
		       int blocking,
		       int debug);

/** es51984_discard - Discard all pending samples
 *
 * This will discard all pending samples from the input buffer.
 * Returns -EPIPE, if the interface is not synchronized.
 *
 * @es: The interface.
 */
int es51984_discard(struct es51984 *es);

/** es51984_sync - Sync to the device.
 *
 * This will discard all pending samples and resynchronize
 * to the datastream. This must be called before requesting a sample.
 *
 * @es: The interface.
 */
int es51984_sync(struct es51984 *es);

/** es51984_init - Initialize the interface.
 * @board: The board the device is soldered onto.
 * @tty: The serial TTY device node.
 */
struct es51984 * es51984_init(enum es51984_board_type board,
			      const char *tty);

/** es51984_exit - Destroy the interface. */
void es51984_exit(struct es51984 *es);


#endif /* ES51984_H_ */
bues.ch cgit interface