ESP Line Following Buggy
2nd Year Embedded System Project (Group 48 - 2023/24)
Loading...
Searching...
No Matches
Bluetooth Class Reference

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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Bluetooth()

Bluetooth::Bluetooth ( PinName TX_pin,
PinName RX_pin,
int baud_rate )

Construct a new Bluetooth object.

Parameters
TX_pinTX pin on the MCU, but RX pin on the BT Module
RX_pinRX pin on the MCU, but TX pin on the BT Module
baud_rateThe bluetooth module baudrate

Definition at line 6 of file bluetooth.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ data_recieved_complete()

bool Bluetooth::data_recieved_complete ( void )

Returns true if incoming data is fully recieved.

Definition at line 35 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ data_recieved_ISR()

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.

Here is the caller graph for this function:

◆ get_rx_buffer()

char * Bluetooth::get_rx_buffer ( void )

returns the raw data recieved as a character array

Returns
pointer to the rx buffer (character array)

Definition at line 93 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ init()

void Bluetooth::init ( void )
protected

Definition at line 9 of file bluetooth.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_continous()

bool Bluetooth::is_continous ( void )

returns true if continous update is enabled

Definition at line 87 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ is_ready()

bool Bluetooth::is_ready ( void )

returns true if bluetooth module is ready

Definition at line 80 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ is_send_once()

bool Bluetooth::is_send_once ( void )

returns true if send once is enabled

Definition at line 100 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ reset_rx_buffer()

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.

Here is the caller graph for this function:

◆ send_buffer()

void Bluetooth::send_buffer ( char * char_arr)

Sends character array to the bluetooth.

Parameters
char_arrpointer to the character array

Definition at line 51 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ send_fstring()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_continous()

void Bluetooth::set_continous ( bool status)

Set the continous property to the bool value passed.

Parameters
statusbool value to be applied

Definition at line 112 of file bluetooth.cpp.

Here is the caller graph for this function:

◆ set_send_once()

void Bluetooth::set_send_once ( bool status)

Set the send once property to the bool value passed.

Parameters
statusbool value to be applied

Definition at line 106 of file bluetooth.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ bt_serial

RawSerial Bluetooth::bt_serial
protected

creates the RawSerial object to connect with the bluetooth module

Definition at line 31 of file bluetooth.h.

◆ buffer_size

const int Bluetooth::buffer_size = 20
staticprotected

Number of bits per packet (20)

Definition at line 29 of file bluetooth.h.

◆ continous_update

bool Bluetooth::continous_update
protected

if this is true, sends data on each loop without bt commands.

Definition at line 32 of file bluetooth.h.

◆ data_complete

volatile bool Bluetooth::data_complete
protected

true if the incoming data if fully recieved

Definition at line 35 of file bluetooth.h.

◆ rx_buffer

char Bluetooth::rx_buffer[buffer_size+1]
protected

buffer to store recieved data

Definition at line 37 of file bluetooth.h.

◆ rx_index

volatile int Bluetooth::rx_index
protected

keeps track of the next memory location to store the next char recieved

Definition at line 34 of file bluetooth.h.

◆ send_once

bool Bluetooth::send_once
protected

true when get cmd is used

Definition at line 33 of file bluetooth.h.

◆ tx_buffer

char Bluetooth::tx_buffer[buffer_size+1]
protected

buffer to store transmit data

Definition at line 36 of file bluetooth.h.


The documentation for this class was generated from the following files: