src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
12 / 12
100.0%
Branches:
6 / 6
100.0%
Functions:
2 / 2
100.0%

ShadeSettings.h
Line Branch Exec Source
1 #ifndef SHADE_SETTINGS_H
2 #define SHADE_SETTINGS_H
3 #include <Arduino.h>
4 #include "ShadeTypes.h"
5
6 // The settings a shade's behaviour reads and never changes. The user sets
7 // them through JSON, the config file and ModelEditor. Kept free of the shade
8 // model so they can be used in the unit tests on the PC (pio test -e native).
9
10 // What shades and groups share: how their frames go on air.
11 struct RemoteSettings {
12 bool flipCommands = false;
13 uint8_t bitLength = 0;
14 uint8_t repeats = 1;
15 };
16 // What only a shade has.
17 struct ShadeSettings {
18 shade_types shadeType = shade_types::roller;
19 tilt_types tiltType = tilt_types::none;
20 uint32_t upTime = 10000;
21 uint32_t downTime = 10000;
22 uint32_t tiltTime = 7000;
23 uint16_t stepSize = 100;
24 bool flipPosition = false;
25 // Reaches the favorite by moving to it rather than sending My.
26 bool simMy = false;
27 bool sunSensor = false;
28 };
29
30 // The bits of a shade's flags byte that are settings. The rest are state the
31 // shade changes (sun flag, sunny, windy, demo mode) or unused (lighted).
32 static const uint8_t SHADE_SETTING_FLAGS = static_cast<uint8_t>(somfy_flags_t::SunSensor) |
33 static_cast<uint8_t>(somfy_flags_t::Light) | static_cast<uint8_t>(somfy_flags_t::SimMy);
34
35 // The flags byte as it is saved and sent, put together from where its bits live.
36 259 inline uint8_t joinShadeFlags(const ShadeSettings &settings, bool light, uint8_t stateFlags) {
37 259 uint8_t flags = stateFlags & ~SHADE_SETTING_FLAGS;
38
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 131 times.
259 if(settings.sunSensor) flags |= static_cast<uint8_t>(somfy_flags_t::SunSensor);
39
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 131 times.
259 if(light) flags |= static_cast<uint8_t>(somfy_flags_t::Light);
40
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 130 times.
259 if(settings.simMy) flags |= static_cast<uint8_t>(somfy_flags_t::SimMy);
41 259 return flags;
42 }
43 // Splits a saved or sent flags byte back to where its bits live.
44 258 inline void splitShadeFlags(uint8_t flags, ShadeSettings &settings, bool &light, uint8_t &stateFlags) {
45 258 settings.sunSensor = flags & static_cast<uint8_t>(somfy_flags_t::SunSensor);
46 258 light = flags & static_cast<uint8_t>(somfy_flags_t::Light);
47 258 settings.simMy = flags & static_cast<uint8_t>(somfy_flags_t::SimMy);
48 258 stateFlags = flags & ~SHADE_SETTING_FLAGS;
49 258 }
50 #endif
51