Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Behaviour.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Dec 6, 2019
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
10#include <time/cs_DayOfWeek.h>
11#include <time/cs_Time.h>
12#include <time/cs_TimeOfDay.h>
13
14#include <vector>
15
20class Behaviour {
21public:
22 enum class Type : uint8_t { Switch = 0, Twilight = 1, Extended = 2, Undefined = 0xff };
23 typedef std::array<uint8_t, 1 + 13> SerializedDataType;
24
25protected:
27 uint8_t activeIntensity = 0;
28 uint8_t profileId = 0;
32
33public:
34 virtual ~Behaviour() = default; // (to prevent object slicing from leaking memory.)
35
37 Type typ,
38 uint8_t intensity,
39 uint8_t profileid,
40 DayOfWeekBitMask activedaysofweek,
43
46
47 // return value: pointer to next empty val in outbuff.
48 virtual uint8_t* serialize(uint8_t* outbuff, size_t max_size);
49
50 virtual size_t serializedSize() const;
51 std::vector<uint8_t> serialized(); // calls the above virtual functions.
52
53 virtual void print();
54
55 // implementations of behaviours have a class specific identifier
56 // which is defined by overriding this method.
57 virtual Type getType() const { return Type::Undefined; }
58
65 bool isValid(Time currenttime);
66
67 virtual bool requiresPresence() { return false; }
68 virtual bool requiresAbsence() { return false; }
69
70 // =========== Getters ===========
71
75 uint8_t value() const;
76
80 TimeOfDay from() const;
81
86};
Class to derrive behaviours from, centralizing common variables such as from and until times.
Definition: cs_Behaviour.h:20
Behaviour(Type typ, uint8_t intensity, uint8_t profileid, DayOfWeekBitMask activedaysofweek, TimeOfDay from, TimeOfDay until)
uint8_t activeIntensity
Definition: cs_Behaviour.h:27
Type
Definition: cs_Behaviour.h:22
virtual bool requiresPresence()
Definition: cs_Behaviour.h:67
TimeOfDay behaviourAppliesFrom
Definition: cs_Behaviour.h:30
TimeOfDay behaviourAppliesUntil
Definition: cs_Behaviour.h:31
virtual Type getType() const
Definition: cs_Behaviour.h:57
Type typ
Definition: cs_Behaviour.h:26
std::vector< uint8_t > serialized()
SerializedDataType serialize()
virtual ~Behaviour()=default
virtual uint8_t * serialize(uint8_t *outbuff, size_t max_size)
DayOfWeekBitMask activeDays
Definition: cs_Behaviour.h:29
uint8_t profileId
Definition: cs_Behaviour.h:28
bool isValid(Time currenttime)
Does the behaviour apply to the current situation? If from() == until() the behaviour isValid all day...
TimeOfDay until() const
Returns until (excl.) which time on this behaviour applies.
virtual size_t serializedSize() const
uint8_t value() const
Returns the intended state when this behaviour is valid.
virtual void print()
Behaviour(SerializedDataType arr)
std::array< uint8_t, 1+13 > SerializedDataType
Definition: cs_Behaviour.h:23
virtual bool requiresAbsence()
Definition: cs_Behaviour.h:68
TimeOfDay from() const
Returns from (incl.) which time on this behaviour applies.
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24,...
Definition: cs_TimeOfDay.h:19
static TimeOfDay Midnight()
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Sep 24,...
Definition: cs_Time.h:14
uint8_t DayOfWeekBitMask
Definition: cs_DayOfWeek.h:23