Boboter
Loading...
Searching...
No Matches
leds.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <cstdint>
11#include <soc/gpio_num.h>
12#include "types/rgb_color.h"
13
14class Robot;
15
16namespace Device {
17 class Leds {
18 private:
19 static constexpr const char* TAG = "Device::Leds";
20
21 static constexpr uint8_t NUM_LEDS = 4;
22 static constexpr gpio_num_t MOSI_PIN = GPIO_NUM_23;
23 static constexpr gpio_num_t SCK_PIN = GPIO_NUM_18;
24
25 Robot& robot;
26 rgb_color_t leds[NUM_LEDS];
27
28 private:
29 void send_bit(bool bit) const;
30 void send_byte(uint8_t byte) const;
31 void send_frame(rgb_color_t color) const;
32
33 public:
34 enum class led_id_t : uint8_t {
39 };
40
41 public:
42 explicit Leds(Robot& robot);
43 ~Leds();
44
48 void initialize();
49
54 void shutdown();
55
59 void update() const;
60
68 void set_color(led_id_t led_id, rgb_color_t color, bool do_update = true);
69
75 void set_color_all(rgb_color_t color);
76
83 void turn_off(led_id_t led_id, bool do_update = true);
84
88 void turn_all_off();
89 };
90}
void set_color_all(rgb_color_t color)
Sets the color of all LEDs.
Definition leds.cpp:68
Leds(Robot &robot)
Definition leds.cpp:15
void turn_all_off()
Turns off all LEDs.
Definition leds.cpp:83
void update() const
Updates the physical LEDs.
Definition leds.cpp:55
void shutdown()
Prepares the LEDs for a shut-down state, for example for getting destroyed or entering deep sleep.
Definition leds.cpp:51
void initialize()
Sets up the neccessary GPIO pins.
Definition leds.cpp:27
void turn_off(led_id_t led_id, bool do_update=true)
Turns off a specific LED.
Definition leds.cpp:76
~Leds()
Definition leds.cpp:22
void set_color(led_id_t led_id, rgb_color_t color, bool do_update=true)
Sets the color of a specific LED.
Definition leds.cpp:61
led_id_t
Definition leds.h:34
@ BACK_LEFT
Definition leds.h:37
@ FRONT_LEFT
Definition leds.h:35
@ FRONT_RIGHT
Definition leds.h:36
@ BACK_RIGHT
Definition leds.h:38
Class containing all the components of the robot.
Definition robot.h:24
Definition battery.cpp:14
A type for storing a 16-bit RGB color.
Definition rgb_color.h:14