-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kueche.cpp
73 lines (59 loc) · 1.8 KB
/
Kueche.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <array>
#include <memory>
#include <type_traits>
#include <vector>
#include "IoT/Debounce.hpp"
#include "IoT/Device.hpp"
#include "IoT/IoT.hpp"
#include "IoT/Pcf8574.hpp"
#include "IoT/PushButton.hpp"
#include "IoT/SceneManager.hpp"
#include "IoT/WireConfig.hpp"
#include "IoT/String.hpp"
using namespace std;
template< typename T, size_t N >
class StaticVector
{
public:
template< typename ...Args >
T& emplace( Args&&... args )
{
auto& data = data_[size_++];
new(&data) T( std::forward< Args >( args )... );
return *reinterpret_cast< T* >( &data );
}
private:
typename std::aligned_storage< sizeof( T ), alignof( T ) >::type data_[N];
size_t size_ {};
};
static constexpr char const* deviceNames[] = {
"Vitrinen",
"Tuer",
"Haengeschraenke",
"Anrichte",
"Deckenlampe",
"Fensterbank",
"Theke"
};
static constexpr size_t deviceCount = sizeof( deviceNames ) / sizeof( deviceNames[0] );
IoTClass IoT( "akvsoft", "sacomoco02047781", "192.168.178.28", 1883 );
WireConfig wireConfig( 2, 0 );
Pcf8574 pcf8574Output( wireConfig, 56, 0xff );
Pcf8574 pcf8574Input( wireConfig, 57, 0x00 );
StaticVector< PushButton, deviceCount > buttons;
StaticVector< Device, deviceCount > outputs;
SceneManager sceneManager( "Kueche" );
void setup()
{
for ( uint8_t i = 0; i < 7; ++i ) {
auto& button = buttons.emplace( debounce( [i] { return pcf8574Input.read( i ); } ));
auto& output = outputs.emplace( str( "Kueche/", deviceNames[i] ), [i]( bool value ) { pcf8574Output.set( i, value ); } );
sceneManager.addLocalDevice( output );
button.clickedEvent += [&output]( unsigned clicked ) { sceneManager.deviceButtonClicked( output, clicked ); };
}
IoT.begin();
}
void loop()
{
IoT.loop();
}