theCore C++ embedded framework

Additional documentation and examples can be found at: More...

Collaboration diagram for HM-10 module driver:

Data Structures

class  ecl::hm10_sync< Uart, Serial >
 HM10 synchronous BT driver. More...
 

Functions

static err ecl::hm10_sync< Uart, Serial >::init ()
 Initializes BT module. More...
 
static err ecl::hm10_sync< Uart, Serial >::set_pin (uint32_t pin)
 Sets pin code for connecting to the bluetooth device. More...
 
static err ecl::hm10_sync< Uart, Serial >::get_pin (uint32_t &pin)
 Gets pin code from the device. More...
 
static err ecl::hm10_sync< Uart, Serial >::set_immediate (bool state=true)
 Sets immediate mode of operation. More...
 
static err ecl::hm10_sync< Uart, Serial >::get_immediate (bool &state)
 Gets immediate mode state. More...
 
static err ecl::hm10_sync< Uart, Serial >::disconnect ()
 Send disconnect command. More...
 
static err ecl::hm10_sync< Uart, Serial >::data_send (const uint8_t *buf, size_t &sz)
 Sends data to the module. More...
 
static err ecl::hm10_sync< Uart, Serial >::data_recv (uint8_t *buf, size_t &sz, std::chrono::milliseconds ms=std::chrono::milliseconds::max())
 Receives data from the module with given timeout. More...
 

Detailed Description

Additional documentation and examples can be found at:

Function Documentation

◆ init()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::init ( )
static

Initializes BT module.

Returns
Status of operation.
Return values
err::invalModule responded with invalid data.
err::timedoutModule did not respond at all.
err::okModule is ready to work.
Here is the call graph for this function:

◆ set_pin()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::set_pin ( uint32_t  pin)
static

Sets pin code for connecting to the bluetooth device.

Sends AT+PASS command.

Parameters
[in]pinPIN to set. Must be in a range of 000000-999999
Returns
Status of operation.
Return values
err::invalModule responded with invalid data.
err::timedoutModule did not respond at all.
err::okNew pin code is set.

◆ get_pin()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::get_pin ( uint32_t &  pin)
static

Gets pin code from the device.

Sends AT+PASS? command.

Warning
In case of error, content of pin argument is undefined.
Parameters
[out]pinPIN set for current device.
Return values
err::invalModule responded with invalid data.
err::timedoutModule did not respond at all.
err::okPin retrieved successfully.
Here is the call graph for this function:

◆ set_immediate()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::set_immediate ( bool  state = true)
static

Sets immediate mode of operation.

Precondition
Module in the master mode.

Sends AT+IMME command. Immediate mode controls how module behaves after power reset. If immediate mode is set, then module will be listening to commands and will not start any connection attempt.. Otherwise, module will operate immediately, (assuming a previous connection has been applied)

Warning
Immediate mode setting is preserved between module power cycles.
Parameters
[in]stateNew state of immediate mode: true - enables immediate mode, false - disables it.
Return values
err::invalModule responded with invalid data.
err::timedoutModule did not respond at all.
err::okImmediate mode state is updated.

◆ get_immediate()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::get_immediate ( bool &  state)
static

Gets immediate mode state.

Precondition
Module in the master mode.

Sends AT+IMME? command.

See also
set_immediate()
Parameters
[out]stateCurrent state of immediate mode: true - immediate mode is enabled. false - immediate mode is disabled.
Return values
err::invalModule responded with invalid data.
err::timedoutModule did not respond at all.
err::okImmediate mode state retrieved succesfully.
Here is the call graph for this function:

◆ disconnect()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::disconnect ( )
static

Send disconnect command.

sends AT command. HM-10 will disconnect from any device.

Return values
err::invalModule responded with invalid data.
err::timedoutModule did not respond at all.
err::okModule has been successfully reset.

◆ data_send()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::data_send ( const uint8_t *  buf,
size_t &  sz 
)
static

Sends data to the module.

Warning
It is possible that no one has connected to the device yet.
Data that is sent to unconnected module will be lost.

Call blocks until all data will be sent.

Parameters
[in]bufBuffer to send.
[in,out]szSize of buffer as input, bytes written as output.
Returns
Status of operation.
Return values
err::okData sent successfully.

◆ data_recv()

template<class Uart , class Serial >
err ecl::hm10_sync< Uart, Serial >::data_recv ( uint8_t *  buf,
size_t &  sz,
std::chrono::milliseconds  ms = std::chrono::milliseconds::max() 
)
static

Receives data from the module with given timeout.

Parameters
[out]bufBuffer to store incoming data.
[in,out]szSize of the buffer as input, bytes effectively written as output.
[in]msOptional. Defines overall time to wait for incoming data. Defaults to infinite time.
Returns
Status of operation.
Return values
err::timedoutBuffer was not filled completely before timeout hit. It is still possible that some data was transferred. Check
Parameters
szto understand how many bytes are there.
Return values
err::okWhole buffer was populated before timeout reached.