-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflowmaster.h
158 lines (127 loc) · 4.31 KB
/
flowmaster.h
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef FM_SERIAL_H
#define FM_SERIAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "flowmaster_internal.h"
struct flowmaster_s;
#ifndef __cplusplus
/*
* The intention here is to make the 'flowmaster' typedef available
* for use in C code, but not mess up the namespace for the C++ code
*
* If we are using C++ code, then don't expose this so we can declare
* the flowmaster class.
* */
typedef struct flowmaster_s flowmaster;
#endif
/*
FM_B19200 - 19200 bps
FM_B38400 - 38400 bps
FM_B57600 - 57600 bps
FM_B115200 - 115200 bps
Valid baud rate values.
Defined in platform include file
*/
typedef enum fm_baud_rate_e fm_baud_rate;
/*
* Flowmaster return codes
*
* Generally, zero on success. otherwise check RC.
*
* */
enum fm_rc_e
{
FM_OK = 0,
FM_WRITE_ERROR,
FM_READ_TIMEOUT,
FM_READ_ERROR,
FM_PORT_ERROR,
FM_CHECKSUM_ERROR,
FM_FILE_ERROR,
FM_BAD_HEXFILE,
FM_BAD_BUFFER_LENGTH
};
typedef enum fm_rc_e fm_rc;
enum flash_state_e
{
FLASH_OPEN_FILE_OK, /* null, file was opened ok */
FLASH_OPEN_FILE_ERROR, /* null, file was not opened */
FLASH_BLOCK_COUNT, /* int, the number of blocks that will be written */
FLASH_WRITE_BLOCK_OK, /* int, the block that was written */
FLASH_WRITE_BLOCK_ERROR,/* int, the block that failed validation or writing */
FLASH_VALIDATE_OK, /* null, hex file was validated ok */
FLASH_VALIDATE_ERROR, /* null, validation error */
FLASH_ERASE_CHIP_BEGIN, /* null, begin chip erase */
FLASH_ERASE_CHIP_OK, /* null, done chip erase */
FLASH_UPDATE_BEGIN, /* null, starting the programming run */
FLASH_UPDATE_OK, /* null, flash operation suceeded */
FLASH_UPDATE_ERROR /* null, flash operation failed */
};
typedef enum flash_state_e flash_state;
/* Create a flowmaster handle */
DLLEXPORT struct flowmaster_s* fm_create();
/* clean up the flowmaster handle */
DLLEXPORT void fm_destroy(struct flowmaster_s *fm);
/*
* Open the serial port
* port - the serial port to open. EG "COM1" "/dev/ttyUSB0" etc
* */
DLLEXPORT fm_rc fm_connect(struct flowmaster_s *fm, const char *port);
/* Close the serial port */
DLLEXPORT fm_rc fm_disconnect(struct flowmaster_s *fm);
/* True if connected*/
DLLEXPORT int fm_isconnected(struct flowmaster_s *fm);
/* returns 0 if alive, -1 if error*/
DLLEXPORT fm_rc fm_ping(struct flowmaster_s *fm);
/* Set the cursor XY position */
DLLEXPORT int fm_set_cursor(struct flowmaster_s *fm, int row, int col);
/* Print a message to the flowmaster display. max 20 chars. */
DLLEXPORT int fm_print_message(struct flowmaster_s *fm, const char *message, int message_len);
/* Enable or disable automatic regulation of fan speed. true: auto, false manual */
DLLEXPORT int fm_autoregulate(struct flowmaster_s *fm, int regulate);
/*
* Set the speed of the fans or pump.
* duty_cycle is a float between 0.0 and 1.0
*
* duty cycles > 1.0 will be set to 1.0
* duty cycles < 0.3 will be set to 0.3
*
* A pump may never be switched off.
* */
DLLEXPORT int fm_set_fan_speed(flowmaster *fm, float duty_cycle);
DLLEXPORT int fm_set_pump_speed(flowmaster *fm, float duty_cycle);
/* Stop rotating the displays */
DLLEXPORT int fm_halt_update_display(struct flowmaster_s *fm);
/* Change to a given display */
DLLEXPORT int fm_set_display(struct flowmaster_s *fm, int display);
/* filename is a path to an intel HEX file that you want to upload to the microcontroller */
typedef void (*fm_flash_callback)(enum flash_state_e, void *userdata, void *data);
DLLEXPORT int flash_validate_and_program(
struct flowmaster_s *fm,
const char *filename,
fm_flash_callback cb,
void *userdata
);
/*
* Query the microcontroller for it's latest status info.
* Don't call this more than once per 500ms
*
* */
DLLEXPORT fm_rc fm_update_status(struct flowmaster_s *fm);
DLLEXPORT fm_rc fm_set_fan_profile(struct flowmaster_s *fm, float *data, int length);
DLLEXPORT fm_rc fm_get_fan_profile(struct flowmaster_s *fm, float *data, int length);
/*
* Getter functions for fetching the status of the pump controller.
* Refreshed by calling fm_update_status();
* */
DLLEXPORT float fm_fan_duty_cycle(flowmaster *fm);
DLLEXPORT float fm_pump_duty_cycle(flowmaster *fm);
DLLEXPORT float fm_ambient_temp(flowmaster *fm);
DLLEXPORT float fm_coolant_temp(flowmaster *fm);
DLLEXPORT int fm_fan_rpm(flowmaster *fm);
DLLEXPORT int fm_pump_rpm(flowmaster *fm);
#ifdef __cplusplus
}
#endif
#endif