-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmbientPixel.h
122 lines (109 loc) · 2.37 KB
/
AmbientPixel.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#pragma once
#include <StandardCplusplus.h>
#include <system_configuration.h>
#include <unwind-cxx.h>
#include <utility.h>
#include <vector>
#include <skInfraredCOM.h>
#include <Adafruit_NeoPixel.h>
#define DEBUG 1
#ifdef DEBUG
#define AP_DEBUG_LOG(x) Serial.print(x)
#define AP_DEBUG_LOG_LN(x) Serial.println(x)
#define AP_DEBUG_LOG_FMT(x, y) Serial.println(x, y)
#else
#define AP_DEBUG_LOG(x)
#define AP_DEBUG_LOG_LN(x)
#define AP_DEBUG_LOG_FMT(x, y)
#endif
namespace AmbientPixel
{
class ColorAttr
{
public:
uint8_t red;
uint8_t green;
uint8_t blue;
ColorAttr();
ColorAttr(uint8_t red, uint8_t green, uint8_t blue);
};
class Port
{
public:
skInfraredCOM *com;
uint8_t adjacent_device_id;
Port(skInfraredCOM *com, uint8_t adjacent_device_id);
};
class Packet
{
public:
// 1byteのパケットデータを生成する
static uint8_t packet_data(uint8_t device_id, uint8_t flag, uint8_t color);
};
class Pixel
{
private:
// フルカラーLED制御用変数
Adafruit_NeoPixel led;
// 送信・受信ポート
std::vector<Port> ports;
bool configured;
bool isMaster;
bool blink;
AmbientPixel::ColorAttr current_color;
AmbientPixel::ColorAttr color_at_index(uint8_t index);
public:
struct Flag {
enum {
Glow = 0b00000000,
Blink = 0b00001000,
TurnOff = 0b00010000,
Control = 0b00011000
};
};
struct ControlFlag {
enum {
Network = 0b00000000,
Reset = 0b00000001,
Accept = 0b00000010,
Deny = 0b00000011
};
};
struct Color {
enum {
Red = 0b00000000,
Green = 0b00000001,
Blue = 0b00000010,
Orange = 0b00000011,
Purple = 0b00000100,
Indigo = 0b00000101,
White = 0b00000110,
Off = 0b00000111
};
};
struct Vertex {
enum {
Triangle = 3,
// Rectangle = 4,
// Pentagon = 5,
// Hexagon = 6,
};
};
// 自分のデバイスID
uint8_t device_id;
// 頂点数
uint8_t number_of_vertex;
Pixel(uint8_t number_of_vertex);
// 指定したポートにパケットを送信する
void send(uint8_t port_no, uint8_t packet);
void receive(uint8_t port_no, uint8_t data);
// ポートを監視する
uint8_t watch(uint8_t port_no);
// LEDを点灯させる
void change_led(uint8_t flag, AmbientPixel::ColorAttr color);
void setMasterEnabled(bool enabled) {
this->configured = enabled;
this->isMaster = enabled;
};
};
}