forked from kost/dcled
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreen.h
66 lines (55 loc) · 2.07 KB
/
screen.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
// dcled-hidapi - userland driver for the Dream Cheeky LED Message Board
// Copyright 2018 Jahn Fuchs <[email protected]>
// Distributed under the MIT License. See accompanying LICENSE file.
#pragma once
#include <vector>
#include <list>
#include <memory>
namespace dcled
{
class PixMap;
class Screen {
public:
static constexpr uint8_t WIDTH = 21;
static constexpr uint8_t HEIGHT = 7;
enum class Brightness : uint8_t { Low = 0, Mid = 1, High = 2 };
enum class Direction : uint8_t { Left, Right, Up, Down };
enum class Flip : uint8_t { Horizontal, Vertical };
constexpr Screen(): msgs_{LedMsg(0), LedMsg(2), LedMsg(4), LedMsg(6)} {}
Screen(const PixMap& pixmap, uint32_t x_offset = 0, uint32_t y_offset = 0);
Screen(const Screen& other) = default;
Screen(Screen&& other) = default;
virtual ~Screen() = default;
Screen& operator=(const Screen& other) = default;
Screen& operator=(Screen&& other) = default;
Screen& operator&(const Screen& other);
Screen& operator|(const Screen& other);
Screen& operator^(const Screen& other);
Screen& invert();
Screen& flip(Flip direction);
Screen& shift(Direction dir, uint8_t num = 1);
Screen& setBrightness(Brightness brightness);
Screen& setAll(bool on);
Screen& setRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, bool on);
Screen& set(uint8_t x, uint8_t y, bool on);
Screen& set(const Screen& other);
/// Get the LED state at \a x, \a y.
bool get(uint8_t x, uint8_t y) const;
void print(bool ttyColored = false) const;
protected:
struct LedMsg
{
constexpr LedMsg(uint8_t row) : row(row) {}
const LedMsg& operator&=(const LedMsg& other);
const LedMsg& operator|=(const LedMsg& other);
const LedMsg& operator^=(const LedMsg& other);
void invert();
void setAll(bool on);
uint8_t report_id = 0;
Brightness brightness = Brightness::High;
uint8_t row;
uint8_t data[2][3] = {{0xff, 0xff, 0xff}, {0xff, 0xff, 0xff}}; // all LEDs off
};
LedMsg msgs_[4];
};
} // end namespace dcled