9e9f365e
henyxia
Added HVC interface
|
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
|
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <strings.h>
#include <inttypes.h>
#include "ui.h"
#include "hvc.h"
#include "printx.h"
#include "serial.h"
#define DEVICE1 "/dev/ttyACM1"
#define SPEED B19200
#define HVC_POLLING_TIME 500000
#define WAIT_BEFORE_RETRY 5000
#define GET_DEVICE_MODEL 'A'
#define DEVICE_MODEL_HVC 'C'
#define GET_TEMP 'H'
// Globals
int hvc_fd = -1;
bool hvcStop = false;
bool sPump = false;
bool sHeat = false;
struct termios hvcSaveterm;
bool initHVC()
{
unsigned char data;
printx(DEBUG, HVC, "Connecting to interface 1\n");
if(init_serial(DEVICE1, SPEED, &hvc_fd, &hvcSaveterm))
{
printx(DEBUG, HVC, "Connected to an interface\n");
sendData(&hvc_fd, GET_DEVICE_MODEL);
printx(DEBUG, HVC, "Sended identification request %02x\n", GET_DEVICE_MODEL);
data = getData(&hvc_fd);
if(data == DEVICE_MODEL_HVC)
printx(INFO, HVC, "HVC Arduino connected\n");
else
printx(DEBUG, HVC, "HVC Arduino not found, response was %02x\n", data);
}
else
{
printx(WARNING, HVC, "Unable to connect to such interface\n");
return false;
}
return true;
}
void* processHVC(void* we)
{
uint8_t data;
while(!hvcStop)
{
printx(DEBUG, HVC, "Querying data\n");
sendData(&hvc_fd, GET_TEMP);
data = getData(&hvc_fd);
setTemp(data);
usleep(HVC_POLLING_TIME);
}
return NULL;
}
|