Boboter
Loading...
Searching...
No Matches
leds.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <soc/gpio_num.h>
11
12#include "include/hal/gpio.h"
13#include "types/rgb_color.h"
14#include "include/log_sources.h"
15
16class Robot;
17
18namespace Device {
19 class Leds {
20 private:
21 static constexpr const char* TAG = "Device::Leds";
22 static constexpr log_source LOG_SOURCE = LOG_SOURCE_DEVICE_LEDS;
23
24 static constexpr uint8_t NUM_LEDS = 4;
25 static constexpr gpio_num_t MOSI_PIN = GPIO_NUM_23;
26 static constexpr gpio_num_t SCK_PIN = GPIO_NUM_18;
27
28 Robot& robot;
29 rgb_color_t leds[NUM_LEDS];
30 HAL::GPIO::fast_gpio_path_t mosi_fast_path;
31 HAL::GPIO::fast_gpio_path_t sck_fast_path;
32
33 private:
34 void send_bit(bool bit) const;
35 void send_byte(uint8_t byte) const;
36 void send_frame(rgb_color_t color) const;
37
38 public:
39 enum class led_id_t : uint8_t {
44 };
45
46 public:
47 explicit Leds(Robot& robot);
48 ~Leds();
49
53 void initialize();
54
59 void shutdown();
60
64 void update() const;
65
73 void set_color(led_id_t led_id, rgb_color_t color, bool do_update = false);
74
80 void set_color_all(rgb_color_t color);
81
88 void turn_off(led_id_t led_id, bool do_update = true);
89
93 void turn_all_off();
94 };
95}
void set_color_all(rgb_color_t color)
Sets the color of all LEDs.
Definition leds.cpp:80
Leds(Robot &robot)
Definition leds.cpp:15
void turn_all_off()
Turns off all LEDs.
Definition leds.cpp:95
void update() const
Updates the physical LEDs.
Definition leds.cpp:59
void shutdown()
Prepares the LEDs for a shut-down state, for example for getting destroyed or entering deep sleep.
Definition leds.cpp:54
void initialize()
Sets up the necessary 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:88
~Leds()
Definition leds.cpp:22
led_id_t
Definition leds.h:39
@ BACK_LEFT
Definition leds.h:42
@ FRONT_LEFT
Definition leds.h:40
@ FRONT_RIGHT
Definition leds.h:41
@ BACK_RIGHT
Definition leds.h:43
void set_color(led_id_t led_id, rgb_color_t color, bool do_update=false)
Sets the color of a specific LED.
Definition leds.cpp:71
Class containing all the components of the robot.
Definition robot.h:32
log_source
Definition log_sources.h:12
@ LOG_SOURCE_DEVICE_LEDS
Definition log_sources.h:20
Definition battery.cpp:14
Definition gpio.h:32
A type for storing a 16-bit RGB color.
Definition rgb_color.h:14