-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.cpp
More file actions
101 lines (77 loc) · 2.31 KB
/
display.cpp
File metadata and controls
101 lines (77 loc) · 2.31 KB
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
#include <thread>
#include "main.h"
#include "display.h"
namespace sarah_matrix
{
display::display(event_notifier& n, leds& l)
: _notif(n), _leds(l)
{
_notif.function_register(event_notifier::INITIALISE, std::bind(&display::initialise, this));
_notif.function_register(event_notifier::DEINITIALISE, std::bind(&display::deinitialise, this));
_notif.function_register(event_notifier::HOTWORD_DETECTED, [&] (void*) { /* nothing */});
_notif.function_register(event_notifier::RECORD_START,
[&] (void*) {
_stop_speech = false;
std::thread t(&display::speech_started, this);
t.detach();
});
_notif.function_register(event_notifier::RECORD_END, [&] (void*) { _stop_speech = true; });
_notif.function_register(event_notifier::SPEAK_START,
[&] (void*) {
_stop_speak = false;
std::thread t(&display::speak_started, this);
t.detach();
});
_notif.function_register(event_notifier::SPEAK_END, [&] (void*) { _stop_speak = true; });
}
void display::initialise()
{
LOG(INFO) << "display initialising";
_leds.Off();
LOG(INFO) << "display initialised";
}
void display::deinitialise()
{
LOG(INFO) << "display deinitialising";
_leds.Off();
LOG(INFO) << "display deinitialised";
}
void display::speech_started()
{
_leds.On(leds::red);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
matrix_hal::LedValue c;
for (int i=0;; i++) {
for (int j=0; j<_leds.NumberLeds(); j++)
{
c.green = 50 * (((i + j) % 6 == 0) ? 1 : 0);
_leds.Set(j, c);
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
if (_stop_speech)
break;
}
_leds.On(leds::green);
std::this_thread::sleep_for(std::chrono::milliseconds(250));
_leds.Off();
}
void display::speak_started()
{
_leds.On(leds::blue);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
matrix_hal::LedValue c;
for (int i=0;; i++) {
for (int j=0; j<_leds.NumberLeds(); j++)
{
c.blue = 50 * (((i + j) % 3 == 0) ? 1 : 0);
_leds.Set(j, c);
}
std::this_thread::sleep_for(std::chrono::milliseconds(150));
if (_stop_speak)
break;
}
_leds.On(leds::blue);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
_leds.Off();
}
}