ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
|
BLE HM-10 Interface Class. More...
#include <bluetooth.h>
Public Member Functions | |
Bluetooth (PinName TX_pin, PinName RX_pin, int baud_rate) | |
Construct a new Bluetooth object. | |
bool | data_recieved_complete (void) |
Returns true if incoming data is fully recieved. | |
void | data_recieved_ISR (void) |
ISR that runs for every character recieved. | |
void | reset_rx_buffer (void) |
Resets the recieved data buffer for new incoming data. | |
void | send_buffer (char *char_arr) |
Sends character array to the bluetooth. | |
void | send_fstring (const char *format,...) |
Sends formatted string to the bluetooth. | |
bool | is_ready (void) |
returns true if bluetooth module is ready | |
bool | is_continous (void) |
returns true if continous update is enabled | |
bool | is_send_once (void) |
returns true if send once is enabled | |
char * | get_rx_buffer (void) |
returns the raw data recieved as a character array | |
void | set_send_once (bool status) |
Set the send once property to the bool value passed. | |
void | set_continous (bool status) |
Set the continous property to the bool value passed. | |
Protected Member Functions | |
void | init (void) |
Protected Attributes | |
RawSerial | bt_serial |
creates the RawSerial object to connect with the bluetooth module | |
bool | continous_update |
if this is true, sends data on each loop without bt commands. | |
bool | send_once |
true when get cmd is used | |
volatile int | rx_index |
keeps track of the next memory location to store the next char recieved | |
volatile bool | data_complete |
true if the incoming data if fully recieved | |
char | tx_buffer [buffer_size+1] |
buffer to store transmit data | |
char | rx_buffer [buffer_size+1] |
buffer to store recieved data | |
Static Protected Attributes | |
static const int | buffer_size = 20 |
Number of bits per packet (20) | |
BLE HM-10 Interface Class.
Library to interface with the HM-10 Bluetooth Low Energy Module
BLE has a standard of 20 bytes maximum per packet so it cant be used like a normal UART serial and theres problems with buffering
So this class Utilises RawSerial to get and send individual characters
Has functions that sends and recieves individual characters in a loop (keep in mind 20 bytes limit)
"Continous update" and "send once" property are stored in the class but handled externally
Definition at line 25 of file bluetooth.h.
Bluetooth::Bluetooth | ( | PinName | TX_pin, |
PinName | RX_pin, | ||
int | baud_rate ) |
Construct a new Bluetooth object.
TX_pin | TX pin on the MCU, but RX pin on the BT Module |
RX_pin | RX pin on the MCU, but TX pin on the BT Module |
baud_rate | The bluetooth module baudrate |
Definition at line 6 of file bluetooth.cpp.
bool Bluetooth::data_recieved_complete | ( | void | ) |
Returns true if incoming data is fully recieved.
Definition at line 35 of file bluetooth.cpp.
void Bluetooth::data_recieved_ISR | ( | void | ) |
ISR that runs for every character recieved.
This ISR will run for every character recieved by the bluetooth module.
Each time this ISR is ran one character is stored into rx_buffer.
rx_index stores the location of next memory location to store the next character
Definition at line 18 of file bluetooth.cpp.
char * Bluetooth::get_rx_buffer | ( | void | ) |
returns the raw data recieved as a character array
Definition at line 93 of file bluetooth.cpp.
|
protected |
Definition at line 9 of file bluetooth.cpp.
bool Bluetooth::is_continous | ( | void | ) |
returns true if continous update is enabled
Definition at line 87 of file bluetooth.cpp.
bool Bluetooth::is_ready | ( | void | ) |
returns true if bluetooth module is ready
Definition at line 80 of file bluetooth.cpp.
bool Bluetooth::is_send_once | ( | void | ) |
returns true if send once is enabled
Definition at line 100 of file bluetooth.cpp.
void Bluetooth::reset_rx_buffer | ( | void | ) |
Resets the recieved data buffer for new incoming data.
Ideally used after processing recieved data.
Note: newly recieved data will be lost if rx_buffer was not reset
Definition at line 42 of file bluetooth.cpp.
void Bluetooth::send_buffer | ( | char * | char_arr | ) |
Sends character array to the bluetooth.
char_arr | pointer to the character array |
Definition at line 51 of file bluetooth.cpp.
void Bluetooth::send_fstring | ( | const char * | format, |
... ) |
Sends formatted string to the bluetooth.
Used the same way as printf()
Definition at line 67 of file bluetooth.cpp.
void Bluetooth::set_continous | ( | bool | status | ) |
Set the continous property to the bool value passed.
status | bool value to be applied |
Definition at line 112 of file bluetooth.cpp.
void Bluetooth::set_send_once | ( | bool | status | ) |
Set the send once property to the bool value passed.
status | bool value to be applied |
Definition at line 106 of file bluetooth.cpp.
|
protected |
creates the RawSerial object to connect with the bluetooth module
Definition at line 31 of file bluetooth.h.
|
staticprotected |
Number of bits per packet (20)
Definition at line 29 of file bluetooth.h.
|
protected |
if this is true, sends data on each loop without bt commands.
Definition at line 32 of file bluetooth.h.
|
protected |
true if the incoming data if fully recieved
Definition at line 35 of file bluetooth.h.
|
protected |
buffer to store recieved data
Definition at line 37 of file bluetooth.h.
|
protected |
keeps track of the next memory location to store the next char recieved
Definition at line 34 of file bluetooth.h.
|
protected |
true when get cmd is used
Definition at line 33 of file bluetooth.h.
|
protected |
buffer to store transmit data
Definition at line 36 of file bluetooth.h.