Skip to content

Commit

Permalink
Merge pull request #11 from matthias-bs/feat-param-activescan
Browse files Browse the repository at this point in the history
Added flag activeScan as parameter to begin()
  • Loading branch information
matthias-bs authored Apr 26, 2024
2 parents 9cc4e1a + 1ab4082 commit 92a4423
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
|
ps -p "$$"
arduino-cli lib install [email protected]
arduino-cli lib install [email protected].1
arduino-cli lib install [email protected].2

- name: Install platform
if: ${{ env.run-build == 'true' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
// History:
//
// 20221123 Created
// 20240403 Added reedSwitchState, gpioTrgOutput, controlParameters,
// tempTriggerEvent &humiTriggerEvent
// 20240425 Added device name
//
// To Do:
// -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// https://github.com/matthias-bs/ATC_MiThermometer
// Mijia lywsd03mmc thermometers are first to be loaded with a custom firmware as per:
// https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html
//
// 20240425 Added device name

#include "ATC_MiThermometer.h"

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ATC_MiThermometer
version=0.4.1
version=0.4.2
author=Matthias Prinke <[email protected]>
maintainer=Matthias Prinke <[email protected]>
sentence=Arduino library for BLE ATC_MiThermometer thermometer/hygrometer sensors.
Expand Down
11 changes: 7 additions & 4 deletions src/ATC_MiThermometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
//
// 20221123 Created
// 20221223 Added support for ATC1441 format
// 20240403 Added reedSwitchState, gpioTrgOutput, controlParameters,
// tempTriggerEvent &humiTriggerEvent
// 20240425 Added device name
//
// ToDo:
// -
Expand Down Expand Up @@ -73,12 +76,12 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {


// Set up BLE scanning
void ATC_MiThermometer::begin(void)
void ATC_MiThermometer::begin(bool activeScan)
{
NimBLEDevice::init("");
_pBLEScan = BLEDevice::getScan(); //create new scan
_pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
_pBLEScan->setActiveScan(false); //active scan uses more power, but get results faster
_pBLEScan->setActiveScan(activeScan); //active scan uses more power, but get results faster
_pBLEScan->setInterval(100);
_pBLEScan->setFilterPolicy(BLE_HCI_SCAN_FILT_NO_WL);
_pBLEScan->setWindow(99); // less or equal setInterval value
Expand Down Expand Up @@ -133,7 +136,7 @@ unsigned ATC_MiThermometer::getData(uint32_t duration) {
data[n].batt_level = foundDevices.getDevice(i).getServiceData().c_str()[12];

// Count
data[n].count = foundDevices.getDevice(i).getServiceData().c_str()[13];
data[n].count = foundDevices.getDevice(i).getServiceData().c_str()[13];

//Flags
uint8_t flagsByte = foundDevices.getDevice(i).getServiceData().c_str()[14];
Expand Down Expand Up @@ -178,7 +181,7 @@ unsigned ATC_MiThermometer::getData(uint32_t duration) {
return foundDevices.getCount();
}


// Set all array members invalid
void ATC_MiThermometer::resetData(void)
{
Expand Down
14 changes: 11 additions & 3 deletions src/ATC_MiThermometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
// History:
//
// 20221123 Created
// 20240403 Added reedSwitchState, gpioTrgOutput, controlParameters,
// tempTriggerEvent &humiTriggerEvent
// 20240425 Added device name
// 20240426 Added parameter activeScan to begin()
//
// ToDo:
// -
Expand Down Expand Up @@ -92,9 +96,13 @@ class ATC_MiThermometer {
};

/*!
\brief Initialization.
*/
void begin(void);
* \brief Initialization.
*
* \param activeScan Set to true for achtive scan, which uses more power,
* but get results faster. As a side effect, the device name
* is received (most of the times).
*/
void begin(bool activeScan = true);

/*!
\brief Delete results from BLEScan buffer to release memory.
Expand Down

0 comments on commit 92a4423

Please sign in to comment.