phyphox BLE
Plot your Arduino's data in the phyphox app and control the board from the phone
Loading...
Searching...
No Matches
ExperimentStore.h
Go to the documentation of this file.
1// The copy of the experiment that outlives the sketch's builder objects.
2//
3// PhyphoxBLE::addExperiment(exp) walks the builder's lists (views → elements → subgraphs,
4// export sets → entries, sensors) twice: once to measure, then — after ONE malloc of exactly
5// that size — to copy every plain-data struct into the block. From then on the builder objects
6// may die; the serializer and the channel store read only this copy. The block is never freed
7// (a second addExperiment() frees and reallocates it, which is the one case where the heap is
8// touched twice). No capacity limits: RAM is what the experiment needs.
9#ifndef PHYPHOX_BLE_CORE_EXPERIMENTSTORE_H
10#define PHYPHOX_BLE_CORE_EXPERIMENTSTORE_H
11
12#include "ElementData.h"
13
15
16namespace phyphox {
17
21 bool used = false;
22 bool isButton = false;
23 bool fromSensor = false;
24 uint8_t sensorIndex = 0;
25 uint8_t componentIndex = 0;
26 float defaultValue = 0;
27 bool hasDefault = false;
28 uint8_t submitWithChannel = 0;
29};
30
32public:
38 static size_t bytesNeeded(const PhyphoxBleExperiment& exp);
42 void clear();
43
44 const ExperimentData& data() const { return data_; }
45 ExperimentData& data() { return data_; }
46 const InputChannelInfo& input(uint8_t channel) const;
47 bool hasErrors() const;
49 uint8_t inputChannelsUsed() const { return inputChannelsUsed_; }
50 size_t blockSize() const { return blockSize_; }
52 void* channelStorage() const { return channelStorage_; }
54 uint16_t* partTable() const { return partTable_; }
56
57private:
58 ExperimentData data_;
59 uint8_t* block_ = nullptr;
60 size_t blockSize_ = 0;
61 InputChannelInfo* inputs_ = nullptr;
62 void* channelStorage_ = nullptr;
63 uint16_t* partTable_ = nullptr;
64 uint8_t inputChannelsUsed_ = 0;
65};
66
67} // namespace phyphox
68
69#endif
Definition phyphoxBleExperiment.h:34
Definition ExperimentStore.h:31
uint8_t inputChannelsUsed() const
Highest input channel in use (so the serializer emits only what exists).
Definition ExperimentStore.h:49
void buildDefault()
The experiment served when a sketch calls start() without addExperiment(): one view with a graph of c...
~ExperimentStore()
Definition ExperimentStore.h:55
size_t blockSize() const
bytes allocated
Definition ExperimentStore.h:50
bool copyFrom(const PhyphoxBleExperiment &exp)
Measures, allocates and deep-copies the builder into the block; assigns characteristics; validates ch...
void * channelStorage() const
Storage inside the block for the ChannelStore (ChannelStore::bytesNeeded(inputChannelsUsed())).
Definition ExperimentStore.h:52
const ExperimentData & data() const
Definition ExperimentStore.h:44
static size_t bytesNeeded(const PhyphoxBleExperiment &exp)
Bytes the copy of exp needs (what copyFrom() would allocate) — for the size report.
uint16_t * partTable() const
Storage inside the block for the serializer's part table (viewCount + 3 entries).
Definition ExperimentStore.h:54
ExperimentData & data()
Definition ExperimentStore.h:45
const InputChannelInfo & input(uint8_t channel) const
1 … inputChannelsUsed()
Definition ChannelStore.h:11
The whole experiment.
Definition ElementData.h:211
What the store knows about one input channel after the copy: which characteristic carries it,...
Definition ExperimentStore.h:20
bool used
Definition ExperimentStore.h:21
bool fromSensor
fed by a phone sensor component (periodic by nature)
Definition ExperimentStore.h:23
uint8_t submitWithChannel
Definition ExperimentStore.h:28
uint8_t sensorIndex
if fromSensor: which sensor, and
Definition ExperimentStore.h:24
bool hasDefault
Definition ExperimentStore.h:27
uint8_t componentIndex
which component (offset = componentIndex * 4)
Definition ExperimentStore.h:25
bool isButton
a button owns this channel (no change detector, no default)
Definition ExperimentStore.h:22
float defaultValue
Definition ExperimentStore.h:26