change led color and add flashing of led

This commit is contained in:
zhangjing 2026-03-26 17:06:33 +08:00
parent 0c6cfe4571
commit 7c49416c68
2 changed files with 19 additions and 4 deletions

View File

@ -3,16 +3,19 @@
compatible = "led-strip-indicator";
en-gpios = <&gpiob 13 GPIO_ACTIVE_HIGH>;
standby {
rgb = <0 0 180>; // Blue
// rgb = <0 0 180>; // Blue
rgb = <0 0 255>; // Blue
};
running {
rgb = <0 172 0>; // Green
// rgb = <0 172 0>; // Green
rgb = <0 255 0>; // Green
};
// pause {
// rgb = <254 254 0>;
// interval-ms = <500>;
// };
error {
rgb = <160 0 0>; //Red
// rgb = <160 0 0>; //Red
rgb = <255 0 0>; //Red
};
};

View File

@ -1,3 +1,4 @@
#include <ctime>
#include <etl/vector.h>
#include <zephyr/drivers/hwinfo.h>
#include <zephyr/drivers/sensor.h>
@ -7,7 +8,10 @@
#include <zpp/device.hpp>
#include "watchdog.hpp"
#include "zephyr/drivers/gpio.h"
#include "zephyr/kernel.h"
#include "zpp/fmt.hpp"
#include "zpp/timer.hpp"
namespace {
auto sensor = DEVICE_DT_GET(DT_NODELABEL(godtek));
auto &pmc = ZPP_DRV_GET(uart_com::Protocal, DT_NODELABEL(pm_protocal));
@ -15,11 +19,19 @@ auto &led_strip = ZPP_DRV_GET(ledstrip::Indicator, DT_NODELABEL(indicator));
enum Command { kTemp = 0x00, kGetId, kRunningState };
enum RunningState {};
constexpr auto kDeviceIdSize = 20;
enum StatusId : uint8_t { kStandby, kRunning, kPause, kError };
// enum StatusId : uint8_t { kStandby, kRunning, kPause, kError };
enum StatusId : uint8_t { kStandby, kRunning, kError };
volatile bool flag{false};
gpio_dt_spec led_g = GPIO_DT_SPEC_GET(DT_NODELABEL(led_g), gpios);
k_timer led_timer;
} // namespace
auto main(void) -> int {
gpio_pin_configure_dt(&led_g, GPIO_OUTPUT_ACTIVE);
k_timer_init(&led_timer, [](k_timer* tim) {
gpio_pin_toggle_dt(&led_g);
}, [](k_timer* tim) {});
k_timer_start(&led_timer, K_NO_WAIT, K_SECONDS(1));
pmc.SetRxCallback(kGetId, [](uart_com::DataType data) -> void {
uint8_t buffer[kDeviceIdSize];
auto size = hwinfo_get_device_id(buffer, sizeof(buffer));