-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled_controller.h
More file actions
66 lines (55 loc) · 1.82 KB
/
led_controller.h
File metadata and controls
66 lines (55 loc) · 1.82 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
/* ---------------------------------------------------------------------------
** This software is in the public domain, furnished "as is", without technical
** support, and with no warranty, express or implied, as to its usefulness for
** any purpose. You are free to modify it and use it in any way you want,
** but you have to leave this header intact.
**
**
** led_controller.h
** A Helper class to control the LEDs of the ReSpeaker 4mic_hat for the RasPi
**
** Author: Oliver Pahl
** -------------------------------------------------------------------------*/
#include <stdint.h>
class LedController {
public:
// Singleton because we only ever have one
// LED array to control in this usecase
static LedController &GetInstance() {
static LedController instance;
return instance;
}
// Powers up the GPIO and SPI connections
bool PowerUp(int number_of_leds);
// Powers down and cleans up
void PowerDown();
// Clears all LEDs and turns them off
void Clear();
// Sets the color of the specified pixel and its brightness
void SetPixelColor(int pixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t brightness = 31);
// Display the pixels set with SetColor
void Show();
// Copy constructor and operator removed for Singleton
LedController(LedController const &) = delete;
void operator=(LedController const &) = delete;
private:
LedController(){};
bool SetGpioPower(bool power);
bool InitSpiDevice();
void WriteStart();
void WriteEnd();
void MakeTransfer(uint8_t *data, int len, int speed_in_hz, int bits_per_word);
private:
// LED SPI Control
int led_spi_file_descriptor_;
uint8_t *pixel_map_;
int speed_in_hz_;
uint8_t bits_per_word_;
uint8_t spi_mode_;
// LED GPIO Control
int led_gpio_file_descriptor_;
// Other
bool powered_up_;
int number_of_leds_;
};