One Framework 0.1.0
RoboMaster嵌入式框架“一键”解决方案,为你的“创意”服务。
载入中...
搜索中...
未找到
NotifyHub.hpp
浏览该文件的文档.
1#ifndef OF_NOTIFYHUB_HPP
2#define OF_NOTIFYHUB_HPP
3
5
6#include <zephyr/kernel.h>
8#include <ems_parser.hpp>
9#include <optional>
10#include <span>
11
12namespace OF
13{
14 constexpr size_t MAX_KEY_LEN = 32;
15
17 {
18 std::span<const ems::Note> notes;
19 uint8_t volume;
20 bool once = false;
21
22 bool operator==(const BuzzerStatus& other) const
23 {
24 if (volume != other.volume || once != other.once) return false;
25 if (notes.size() != other.notes.size()) return false;
26 return notes.data() == other.notes.data(); // compare pointer (same span source)
27 }
28 };
29
30 enum class LEDMode : uint8_t
31 {
32 Solid, // 常亮
33 Blink, // 闪烁
34 Breathing, // 呼吸
35 };
36
37 struct LEDStatus
38 {
40
42 uint8_t toggle_times;
44 bool once = false;
45
46 bool operator==(const LEDStatus& other) const
47 {
48 return color.r == other.color.r &&
49 color.g == other.color.g &&
50 color.b == other.color.b &&
51 mode == other.mode &&
52 toggle_times == other.toggle_times &&
54 once == other.once;
55 }
56 };
57
58 enum class CommandType: uint8_t { SET, REMOVE };
59
67
75
76 class NotifyHub final
77 {
78 public:
79 static constexpr auto name = "NotifyHub";
80
81 void setup();
82
83 static void setBuzzerStatus(const FixedString<MAX_KEY_LEN>& key, const BuzzerStatus& status);
84 static void removeBuzzerStatus(const FixedString<MAX_KEY_LEN>& key);
85
86 static void setLEDStatus(const FixedString<MAX_KEY_LEN>& key, const LEDStatus& status);
87 static void removeLEDStatus(const FixedString<MAX_KEY_LEN>& key);
88
89 private:
90 const device* m_buzzer{nullptr};
91 const device* m_led_pixel{nullptr};
92
93 [[noreturn]] static void m_buzzer_thread_entry(void* p1, void* p2, void* p3);
94 [[noreturn]] static void m_led_thread_entry(void* p1, void* p2, void* p3);
95
96 k_thread m_buzzer_thread{};
97 k_thread m_led_thread{};
98 k_tid_t m_buzzer_tid{};
99 k_tid_t m_led_tid{};
100 };
101}
102
103#endif //OF_NOTIFYHUB_HPP
定义 FixedString.hpp:12
定义 NotifyHub.hpp:77
static void setBuzzerStatus(const FixedString< MAX_KEY_LEN > &key, const BuzzerStatus &status)
定义 NotifyHub.cpp:131
void setup()
定义 NotifyHub.cpp:99
static void removeLEDStatus(const FixedString< MAX_KEY_LEN > &key)
定义 NotifyHub.cpp:158
static constexpr auto name
定义 NotifyHub.hpp:79
static void setLEDStatus(const FixedString< MAX_KEY_LEN > &key, const LEDStatus &status)
定义 NotifyHub.cpp:149
static void removeBuzzerStatus(const FixedString< MAX_KEY_LEN > &key)
定义 NotifyHub.cpp:140
定义 JointSetpointGenerator.hpp:9
CommandType
定义 NotifyHub.hpp:58
@ REMOVE
定义 NotifyHub.hpp:58
@ SET
定义 NotifyHub.hpp:58
constexpr size_t MAX_KEY_LEN
定义 NotifyHub.hpp:14
LEDMode
定义 NotifyHub.hpp:31
@ Breathing
定义 NotifyHub.hpp:34
@ Blink
定义 NotifyHub.hpp:33
@ Solid
定义 NotifyHub.hpp:32
定义 NotifyHub.hpp:61
BuzzerStatus status
定义 NotifyHub.hpp:65
CommandType type
定义 NotifyHub.hpp:62
FixedString< MAX_KEY_LEN > key
定义 NotifyHub.hpp:63
定义 NotifyHub.hpp:17
uint8_t volume
定义 NotifyHub.hpp:19
std::span< const ems::Note > notes
定义 NotifyHub.hpp:18
bool operator==(const BuzzerStatus &other) const
定义 NotifyHub.hpp:22
bool once
定义 NotifyHub.hpp:20
定义 NotifyHub.hpp:69
LEDStatus status
定义 NotifyHub.hpp:73
CommandType type
定义 NotifyHub.hpp:70
FixedString< MAX_KEY_LEN > key
定义 NotifyHub.hpp:71
定义 NotifyHub.hpp:38
bool operator==(const LEDStatus &other) const
定义 NotifyHub.hpp:46
LEDMode mode
定义 NotifyHub.hpp:41
uint8_t toggle_times
定义 NotifyHub.hpp:42
led_color color
定义 NotifyHub.hpp:39
bool once
定义 NotifyHub.hpp:44
uint16_t toggle_interval_ms
定义 NotifyHub.hpp:43
定义 led_pixel.h:36
uint8_t g
定义 led_pixel.h:38
uint8_t b
定义 led_pixel.h:39
uint8_t r
定义 led_pixel.h:37