feat: status control

This commit is contained in:
玖叁 2024-12-27 09:57:09 +08:00
parent d832f4a5fd
commit 5367c786c6
4 changed files with 44 additions and 8 deletions

View File

@ -2,6 +2,7 @@
#define __CONSTS_H__ #define __CONSTS_H__
#define STATUS_LED 2 #define STATUS_LED 2
#define STATUS_LED_ENABLE 1
#define DEVICE_NAME "WhiteTiger" #define DEVICE_NAME "WhiteTiger"

14
include/led.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef __LED_H__
#define __LED_H__
#include <Arduino.h>
class LED
{
public:
static int ledPin;
static void init(int pin);
static void updateStatusLED(bool status);
};
#endif // __LED_H__

15
src/led.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "led.h"
int LED::ledPin = 0;
void LED::init(int pin)
{
ledPin = pin;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void LED::updateStatusLED(bool status)
{
digitalWrite(ledPin, status);
}

View File

@ -1,8 +1,9 @@
#include <Arduino.h> #include <Arduino.h>
#include <motor.h> #include "motor.h"
#include <utils.h> #include "utils.h"
#include <storage.h> #include "storage.h"
#include <ble.h> #include "ble.h"
#include "led.h"
#include "consts.h" #include "consts.h"
void setup() void setup()
@ -23,14 +24,19 @@ void setup()
{MOTOR_C_PWMA, MOTOR_C_AIN1, MOTOR_C_AIN2}, {MOTOR_C_PWMA, MOTOR_C_AIN1, MOTOR_C_AIN2},
{MOTOR_D_PWMB, MOTOR_D_BIN1, MOTOR_D_BIN2}); {MOTOR_D_PWMB, MOTOR_D_BIN1, MOTOR_D_BIN2});
// 设置引脚模式 // 初始化状态灯
pinMode(STATUS_LED, OUTPUT); if (STATUS_LED_ENABLE)
digitalWrite(STATUS_LED, HIGH); {
LED::init(STATUS_LED);
}
} }
void loop() void loop()
{ {
updateStatusLED(BLEManager::deviceConnected, STATUS_LED); if (STATUS_LED_ENABLE)
{
LED::updateStatusLED(BLEManager::deviceConnected);
}
if (BLEManager::deviceConnected) if (BLEManager::deviceConnected)
{ {
sendStatus(*BLEManager::pTxCharacteristic); sendStatus(*BLEManager::pTxCharacteristic);