-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_controller.cpp
45 lines (42 loc) · 1.25 KB
/
sound_controller.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
#include "sound_controller.hpp"
#if USE_KEYBOARD_LEDS
#include <sys/ioctl.h>
#endif
namespace co_fsm::morse
{
sound_controller::sound_controller()
{
#if USE_KEYBOARD_LEDS
fd_console_ = open("/dev/console", O_WRONLY);
if (fd_console_ == -1)
{
std::cerr << "Error opening console file descriptor.\n"
<< "Run the application with sudo or 'make clean' and make without linux argument.\n";
std::terminate();
}
unsigned char led;
ioctl(fd_console_, KDGETLED, &led);
ioctl(fd_console_, KDSETLED, led & ~enable_code_); // Turn off
#endif
}
void sound_controller::set(status value)
{
sound_status_ = value;
#if USE_KEYBOARD_LEDS
{
unsigned char led;
ioctl(fd_console_, KDGETLED, &led);
switch (value)
{
case status::on:
ioctl(fd_console_, KDSETLED, led | enable_code_);
break;
case status::off:
ioctl(fd_console_, KDSETLED, led & ~enable_code_);
break;
}
}
#endif
// std::cout << "Sound = " << (sound_status_ == status::off ? "off" : "on") << '\n';
}
}