-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCControl.h
140 lines (120 loc) · 4.05 KB
/
CControl.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
/**
* @file CControl.h
*
* @brief Header file for the CControl class, providing control functionalities.
*
* This file contains the declaration of the CControl class, which encapsulates
* communication and control functionalities for digital/analog inputs, outputs,
* buttons, servos, and microcontroller auto-detection.
*
* @author Faniel Yemane
*/
#pragma once
#include "Serial.h"
#define RGBLED_RED_PIN 39
#define RGBLED_GRN_PIN 38
#define RGBLED_BLU_PIN 37
#define BUTTON1 33
#define BUTTON2 32
#define JOYSTICK_X 2
#define JOYSTICK_Y 26
#define JOYSTICK_SEL 5
#define ACC_X 23
#define ACC_Y 24
#define ACC_Z 25
#define SERVO_PORT0 0
#define SERVO_PORT1 1
#define SERVO_PORT2 2
#define SERVO_PORT3 3
enum CommandType { DIGITAL = 0, ANALOG, SERVO };
/**
* @class CControl
* @brief Provides control functionalities for interacting with a microcontroller.
*/
class CControl {
private:
Serial _com; ///< Serial communication object.
public:
/**
* @brief Constructor for CControl class.
*/
CControl();
/**
* @brief Destructor for CControl class.
*/
~CControl();
/**
* @brief Initializes the communication with the microcontroller.
* @param comport The COM port number for communication.
*/
void init_com(int comport);
/**
* @brief Reads data from the microcontroller.
* @param type Type of data (DIGITAL, ANALOG, SERVO).
* @param channel Channel number for the data.
* @param result Reference to store the result.
* @return True if successful, false otherwise.
*/
bool get_data(int type, int channel, int& result);
/**
* @brief Writes data to the microcontroller.
* @param type Type of data (DIGITAL, ANALOG, SERVO).
* @param channel Channel number for the data.
* @param val Value to be written.
* @return True if successful, false otherwise.
*/
bool set_data(int type, int channel, int val);
/**
* @brief Reads analog data from the microcontroller.
* @param channel Channel number for the analog input.
* @param result Reference to store the result.
* @return True if successful, false otherwise.
*/
bool get_analog(int channel, int& result);
/**
* @brief Reads digital data from the microcontroller.
* @param channel Channel number for the digital input.
* @param result Reference to store the result.
* @return True if successful, false otherwise.
*/
bool get_digital(int channel, int& result);
/**
* @brief Writes digital data to the microcontroller.
* @param channel Channel number for the digital output.
* @param val Value to be written (0 or 1).
* @return True if successful, false otherwise.
*/
bool set_digital(int channel, int val);
/**
* @brief Get button state with debounce.
* @param channel The channel number.
* @param val Reference to store the debounced button state.
* @return True if the operation is successful, false otherwise.
*/
bool get_button(int channel, int& val);
/**
* @brief Reads the position of a servo motor from the microcontroller.
* @param channel Channel number for the servo motor.
* @param result Reference to store the servo position.
* @return True if successful, false otherwise.
*/
bool get_servo(int channel, int& result);
/**
* @brief Sets the position of a servo motor on the microcontroller.
* @param channel Channel number for the servo motor.
* @param position Position to be set for the servo motor.
* @return True if successful, false otherwise.
*/
bool set_servo(int channel, int position);
/**
* @brief Automatically detects the correct serial port for the microcontroller.
* @return True if successful, false otherwise.
*/
bool auto_detect_microcontroller();
private:
/**
* @brief Reads response from the microcontroller.
* @return Response string from the microcontroller.
*/
std::string read_response();
};