-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuart_com.h
100 lines (96 loc) · 2.94 KB
/
uart_com.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
/*******************************************************************************
* Copyright (c) 2020, 2023 Carnegie Mellon University, IBM Corporation, and others
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*******************************************************************************/
#include "SensorReader.h"
#ifndef UART_COM_H_
#define UART_COM_H_
#define CMD_BUF_MAX (128)
#define MAX_LEN 64
class uart_com : SensorReader
{
private:
// for parsing
char CmdBuf[CMD_BUF_MAX]; // command buffer
int CmdBuf_wp = 0; // Number of stored in command buffer
char * words[MAX_LEN];
int words_len = 0;
const char delim[2] = ",";
bool CMD_PARSE_FLAG = false;
bool StartFlg = false;
uint32_t _last_update_millis = 0;
bool _started = false;
bool parse_mot();
bool parse_mot_r();
bool parse_mot_c();
bool parse_mot_l();
bool parse_thresh();
bool parse_sensi();
bool parse_dat();
bool parse_dat_short();
bool parse_dat_shortest();
bool parse_error();
bool parse_CAP12xx_logging();
void StringCmdParse(char c);
public:
bool touch;
int capacitance;
int cap_thresh;
int sensi = 2;
int motor_r;
int motor_c;
int motor_l;
int expected_motor_r;
int expected_motor_c;
int expected_motor_l;
int resync_r;
int resync_c;
int resync_l;
int switch_up;
int switch_down;
int switch_left;
int switch_right;
int switch_center;
int general;
int noise;
int cal_act;
int i2c_err;
int uart_err;
bool should_log;
int error_count;
explicit uart_com(cabot::Handle & ch);
void init();
void update();
void begin(int baud_rate = 38400);
void start();
void stop();
bool is_started();
bool is_alive();
bool set_mot(int right, int center, int left);
bool set_mot_r(int val);
bool set_mot_c(int val);
bool set_mot_l(int val);
bool set_thresh(int thresh);
bool set_sensi(int sensi);
void publish();
void check_feedback();
void check_CAP12xx_logging();
};
#endif // UART_COM_H_