Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_TapToToggle.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Jan 2, 2019
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
9#include <ble/cs_Nordic.h>
10#include <cfg/cs_AutoConfig.h>
12
13struct __attribute__((__packed__)) t2t_entry_t {
14 uint8_t address[BLE_GAP_ADDR_LEN];
15 uint16_t score; // Score that decreases every tick, and increases when rssi is above threshold.
16};
17
18#define T2T_LIST_COUNT 3
19#define T2T_SCORE_INC (2000 / TICK_INTERVAL_MS)
20#define T2T_SCORE_THRESHOLD (3000 / TICK_INTERVAL_MS)
21#define T2T_SCORE_MAX (5000 / TICK_INTERVAL_MS)
22#define T2T_TIMEOUT_MS 1500
23
38class TapToToggle : public EventListener {
39public:
41 static TapToToggle instance;
42 return instance;
43 }
44 void init(int8_t rssiThreshold);
45 void handleEvent(event_t& event);
46
47private:
52
57 uint16_t timeoutCounter = 0;
58
62 int8_t rssiThreshold = 0;
63
68
73
78
83
88
90
101
105 void tick();
106};
Event listener.
Definition: cs_EventListener.h:17
Class that toggles the switch when a device, like a phone, is held close to the Crownstone.
Definition: cs_TapToToggle.h:38
void tick()
Decrease score of each MAC address.
uint8_t scoreThreshold
Threshold above which the toggle is triggered.
Definition: cs_TapToToggle.h:77
void init(int8_t rssiThreshold)
int8_t defaultRssiThreshold
Default RSSI threshold for this board.
Definition: cs_TapToToggle.h:67
uint16_t timeoutCounter
Used to count down the timeout.
Definition: cs_TapToToggle.h:57
int8_t rssiThreshold
RSSI threshold, above which score will be added.
Definition: cs_TapToToggle.h:62
uint8_t scoreMax
Score can't be higher than this value.
Definition: cs_TapToToggle.h:82
void handleBackgroundAdvertisement(adv_background_parsed_t *adv)
Handle background advertisement.
void handleEvent(event_t &event)
Handle events.
uint8_t scoreIncrement
Score is increased with this value when rssi is above rssi threshold.
Definition: cs_TapToToggle.h:72
TYPIFY(CONFIG_TAP_TO_TOGGLE_ENABLED) enabled
Whether tap to toggle is enabled on this crownstone.
static TapToToggle & getInstance()
Definition: cs_TapToToggle.h:40
uint8_t timeoutTicks
Minimal time in ticks between 2 tap to toggle events.
Definition: cs_TapToToggle.h:87
t2t_entry_t list[T2T_LIST_COUNT]
Definition: cs_TapToToggle.h:53
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
const bool g_CONFIG_TAP_TO_TOGGLE_ENABLED_DEFAULT
#define TICK_INTERVAL_MS
Interval in milliseconds at which tick events are dispatched.
Definition: cs_Config.h:277
#define T2T_LIST_COUNT
Definition: cs_TapToToggle.h:18
#define T2T_SCORE_MAX
Definition: cs_TapToToggle.h:21
#define T2T_TIMEOUT_MS
Definition: cs_TapToToggle.h:22
#define T2T_SCORE_INC
Definition: cs_TapToToggle.h:19
#define T2T_SCORE_THRESHOLD
Definition: cs_TapToToggle.h:20
@ CONFIG_TAP_TO_TOGGLE_ENABLED
Parsed background advertisement.
Definition: cs_PacketsInternal.h:241
Definition: cs_TapToToggle.h:13
uint16_t score
Definition: cs_TapToToggle.h:15