ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
Loading...
Searching...
No Matches
bluetooth.h
Go to the documentation of this file.
1
7#pragma once
8
9#include "mbed.h"
10
26{
27protected:
28
29 const static int buffer_size = 20;
30
31 RawSerial bt_serial;
33 bool send_once;
34 volatile int rx_index;
35 volatile bool data_complete;
38
39 /* This function used to initialise the Bluetooth object */
40 void init(void);
41
42
43public:
44
52 Bluetooth(PinName TX_pin, PinName RX_pin, int baud_rate);
53
58 bool data_recieved_complete(void);
59
70 void data_recieved_ISR(void);
71
79 void reset_rx_buffer(void);
80
86 void send_buffer(char* char_arr);
87
88
94 void send_fstring(const char* format, ...);
95
100 bool is_ready(void);
101
106 bool is_continous(void);
107
112 bool is_send_once(void);
113
119 char* get_rx_buffer(void);
120
121
127 void set_send_once(bool status);
128
134 void set_continous(bool status);
135};
136
137
138
139 // // Possible bluetooth command types
140 // typedef enum
141 // {
142 // execute = 'E', // E
143 // get, // G
144 // set, // S
145 // continous, // C
146 // // invalid,
147 // } BluetoothCommandTypes;
148
149 // typedef enum
150 // {
151 // stop, // S
152 // uturn, // U
153 // encoder_test, // E
154 // motor_pwm_test, // M
155 // straight_test, // C
156 // square_test, // Q
157 // PID_test, // P
158 // toggle_led_test, // L
159 // line_follow, // F
160 // } BluetoothCommandExecTypes;
161
162 // typedef enum
163 // {
164 // pwm_duty, // P
165 // ticks_cumulative, // T
166 // speed, // S
167 // gains_PID, // G
168 // current_usage, // C
169 // runtime, // R
170 // loop_time, // X
171 // loop_count, // Y
172 // } BluetoothCommandDataTypes;
173
174 // typedef enum
175 // {
176 // motor_left, // L // PID, Encoder Ticks, Velocity
177 // motor_right, // R // PID, Encoder Ticks, Velocity
178 // motor_both, // B
179 // sensor, // S
180 // no_obj, // default case
181 // } BluetoothCommandObjects;
182
183 // BluetoothCommandTypes cmd_type;
184 // BluetoothCommandExecTypes exec_type;
185 // BluetoothCommandDataTypes data_type;
186 // BluetoothCommandObjects obj_type;
187
188 // BluetoothCommandDataTypes data_type_sent;
189 // BluetoothCommandObjects obj_type_sent;
190
191 // float data1, data2, data3; // Stores float data from command
BLE HM-10 Interface Class.
Definition bluetooth.h:26
bool continous_update
if this is true, sends data on each loop without bt commands.
Definition bluetooth.h:32
RawSerial bt_serial
creates the RawSerial object to connect with the bluetooth module
Definition bluetooth.h:31
bool data_recieved_complete(void)
Returns true if incoming data is fully recieved.
Definition bluetooth.cpp:35
void set_send_once(bool status)
Set the send once property to the bool value passed.
char * get_rx_buffer(void)
returns the raw data recieved as a character array
Definition bluetooth.cpp:93
static const int buffer_size
Number of bits per packet (20)
Definition bluetooth.h:29
char rx_buffer[buffer_size+1]
buffer to store recieved data
Definition bluetooth.h:37
Bluetooth(PinName TX_pin, PinName RX_pin, int baud_rate)
Construct a new Bluetooth object.
Definition bluetooth.cpp:6
void data_recieved_ISR(void)
ISR that runs for every character recieved.
Definition bluetooth.cpp:18
void send_buffer(char *char_arr)
Sends character array to the bluetooth.
Definition bluetooth.cpp:51
void reset_rx_buffer(void)
Resets the recieved data buffer for new incoming data.
Definition bluetooth.cpp:42
bool send_once
true when get cmd is used
Definition bluetooth.h:33
char tx_buffer[buffer_size+1]
buffer to store transmit data
Definition bluetooth.h:36
volatile int rx_index
keeps track of the next memory location to store the next char recieved
Definition bluetooth.h:34
bool is_send_once(void)
returns true if send once is enabled
void send_fstring(const char *format,...)
Sends formatted string to the bluetooth.
Definition bluetooth.cpp:67
volatile bool data_complete
true if the incoming data if fully recieved
Definition bluetooth.h:35
void set_continous(bool status)
Set the continous property to the bool value passed.
bool is_continous(void)
returns true if continous update is enabled
Definition bluetooth.cpp:87
void init(void)
Definition bluetooth.cpp:9
bool is_ready(void)
returns true if bluetooth module is ready
Definition bluetooth.cpp:80