Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
TapToToggle Class Reference

Class that toggles the switch when a device, like a phone, is held close to the Crownstone. More...

#include <cs_TapToToggle.h>

Inheritance diagram for TapToToggle:
Collaboration diagram for TapToToggle:

Public Member Functions

void init (int8_t rssiThreshold)
 
void handleEvent (event_t &event)
 Handle events. More...
 
- Public Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 

Static Public Member Functions

static TapToTogglegetInstance ()
 

Private Member Functions

 TYPIFY (CONFIG_TAP_TO_TOGGLE_ENABLED) enabled
 Whether tap to toggle is enabled on this crownstone. More...
 
 TapToToggle ()
 
void handleBackgroundAdvertisement (adv_background_parsed_t *adv)
 Handle background advertisement. More...
 
void tick ()
 Decrease score of each MAC address. More...
 

Private Attributes

t2t_entry_t list [T2T_LIST_COUNT]
 
uint16_t timeoutCounter = 0
 Used to count down the timeout. More...
 
int8_t rssiThreshold = 0
 RSSI threshold, above which score will be added. More...
 
int8_t defaultRssiThreshold = 0
 Default RSSI threshold for this board. More...
 
uint8_t scoreIncrement = T2T_SCORE_INC
 Score is increased with this value when rssi is above rssi threshold. More...
 
uint8_t scoreThreshold = T2T_SCORE_THRESHOLD
 Threshold above which the toggle is triggered. More...
 
uint8_t scoreMax = T2T_SCORE_MAX
 Score can't be higher than this value. More...
 
uint8_t timeoutTicks = (T2T_TIMEOUT_MS / TICK_INTERVAL_MS)
 Minimal time in ticks between 2 tap to toggle events. More...
 

Detailed Description

Class that toggles the switch when a device, like a phone, is held close to the Crownstone.

Receives data from event EVT_ADV_BACKGROUND_PARSED. Checks if tap to toggle is enabled in that data. Determines whether a device is considered to be close. Implemented as a leaking bucket:

  • A score per MAC address is kept up.
  • Each received background advertisement with an RSSI above threshold, adds to the score.
  • Each tick the score is decreased.
  • When going from below score threshold to above, a toggle is sent. Makes sure there is some time between two toggles.
  • Each time a toggle is sent, score additions will be blocked for a certain time. Sends out CMD_SWITCH_TOGGLE to toggle switch.

Constructor & Destructor Documentation

◆ TapToToggle()

Member Function Documentation

◆ getInstance()

static TapToToggle & TapToToggle::getInstance ( )
inlinestatic

◆ handleBackgroundAdvertisement()

void TapToToggle::handleBackgroundAdvertisement ( adv_background_parsed_t adv)
private

Handle background advertisement.

Checks if RSSI is above threshold. Checks if tap to toggle is enabled in the background advertisement. Checks if timeout is active. Adds to score. Triggers toggle.

◆ handleEvent()

void TapToToggle::handleEvent ( event_t event)
virtual

Handle events.

This method is overloaded by all classes that derive from EventListener. They can receive an event_t struct and act upon it. These events are dispatched by the EventDispatcher.

Implements EventListener.

◆ init()

void TapToToggle::init ( int8_t  rssiThreshold)

◆ tick()

void TapToToggle::tick ( )
private

Decrease score of each MAC address.

◆ TYPIFY()

TapToToggle::TYPIFY ( CONFIG_TAP_TO_TOGGLE_ENABLED  )
private

Whether tap to toggle is enabled on this crownstone.

Member Data Documentation

◆ defaultRssiThreshold

int8_t TapToToggle::defaultRssiThreshold = 0
private

Default RSSI threshold for this board.

◆ list

t2t_entry_t TapToToggle::list[T2T_LIST_COUNT]
private

◆ rssiThreshold

int8_t TapToToggle::rssiThreshold = 0
private

RSSI threshold, above which score will be added.

◆ scoreIncrement

uint8_t TapToToggle::scoreIncrement = T2T_SCORE_INC
private

Score is increased with this value when rssi is above rssi threshold.

◆ scoreMax

uint8_t TapToToggle::scoreMax = T2T_SCORE_MAX
private

Score can't be higher than this value.

◆ scoreThreshold

uint8_t TapToToggle::scoreThreshold = T2T_SCORE_THRESHOLD
private

Threshold above which the toggle is triggered.

◆ timeoutCounter

uint16_t TapToToggle::timeoutCounter = 0
private

Used to count down the timeout.

◆ timeoutTicks

uint8_t TapToToggle::timeoutTicks = (T2T_TIMEOUT_MS / TICK_INTERVAL_MS)
private

Minimal time in ticks between 2 tap to toggle events.


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