phyphox BLE
Plot your Arduino's data in the phyphox app and control the board from the phone
Loading...
Searching...
No Matches
ChannelStore.h
Go to the documentation of this file.
1// The board-side view of everything the phone can send: one slot per input channel with the
2// last value received, plus the callbacks to fire. Written by the Server when a characteristic
3// is written, read by PhyphoxBLE::read() and by the sketch's callbacks.
4#ifndef PHYPHOX_BLE_CORE_CHANNELSTORE_H
5#define PHYPHOX_BLE_CORE_CHANNELSTORE_H
6
7#include <stdint.h>
8#include "Config.h"
9#include "ElementData.h"
10
11namespace phyphox {
12
14public:
16 void attach(uint8_t channels, void* storage);
17 static size_t bytesNeeded(uint8_t channels);
18 void clear();
20 void setDefault(uint8_t channel, float value);
21 void setCallbacks(uint8_t channel, ChangeCallback onChange, PressCallback onPress);
23 void deliver(uint8_t channel, float value);
24 float value(uint8_t channel) const;
26 uint32_t updates(uint8_t channel) const;
28 bool changed(uint8_t channel);
29
30private:
31 struct Slot {
32 float value = 0;
33 uint32_t updates = 0;
34 uint32_t seen = 0;
35 ChangeCallback onChange = nullptr;
36 PressCallback onPress = nullptr;
37 };
38 Slot* slots_ = nullptr;
39 uint8_t channels_ = 0;
40};
41
44enum EventType : uint8_t { EVENT_PAUSE = 0x00, EVENT_START = 0x01, EVENT_CLEAR = 0x02, EVENT_SYNC = 0xff };
47 int64_t experimentTimeMs = 0;
48 int64_t systemTimeMs = 0;
50 bool decode(const uint8_t* bytes, uint16_t len);
51};
52
53} // namespace phyphox
54
55#endif
Definition ChannelStore.h:13
uint32_t updates(uint8_t channel) const
How many deliveries the channel has seen since start (lets a sketch poll for changes).
void attach(uint8_t channels, void *storage)
Size for channels 1 … channels (storage comes from the experiment block).
void deliver(uint8_t channel, float value)
A value arrived from the phone. Stores it, bumps the counter, fires the callbacks.
bool changed(uint8_t channel)
True once per delivery: returns whether a value arrived since the last call.
void setDefault(uint8_t channel, float value)
Pre-fill a channel with the element's default so read() returns it before any change.
float value(uint8_t channel) const
void setCallbacks(uint8_t channel, ChangeCallback onChange, PressCallback onPress)
static size_t bytesNeeded(uint8_t channels)
Definition ChannelStore.h:11
EventType
The 17-byte block phyphox writes to the event characteristic (bluetooth-low-energy....
Definition ChannelStore.h:44
@ EVENT_CLEAR
Definition ChannelStore.h:44
@ EVENT_SYNC
Definition ChannelStore.h:44
@ EVENT_PAUSE
Definition ChannelStore.h:44
@ EVENT_START
Definition ChannelStore.h:44
void(* ChangeCallback)(float value)
Callback types. Plain function pointers (captureless lambdas convert), never std::function.
Definition ElementData.h:19
void(* PressCallback)()
Definition ElementData.h:20
Definition ChannelStore.h:45
bool decode(const uint8_t *bytes, uint16_t len)
Decode 17 big-endian bytes; returns false if len < 17.
int64_t experimentTimeMs
−1 for SYNC
Definition ChannelStore.h:47
int64_t systemTimeMs
Unix time in ms.
Definition ChannelStore.h:48
EventType type
Definition ChannelStore.h:46