feat: status control
This commit is contained in:
parent
d832f4a5fd
commit
5367c786c6
|
@ -2,6 +2,7 @@
|
|||
#define __CONSTS_H__
|
||||
|
||||
#define STATUS_LED 2
|
||||
#define STATUS_LED_ENABLE 1
|
||||
|
||||
#define DEVICE_NAME "WhiteTiger"
|
||||
|
||||
|
|
|
@ -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__
|
|
@ -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);
|
||||
}
|
22
src/main.cpp
22
src/main.cpp
|
@ -1,8 +1,9 @@
|
|||
#include <Arduino.h>
|
||||
#include <motor.h>
|
||||
#include <utils.h>
|
||||
#include <storage.h>
|
||||
#include <ble.h>
|
||||
#include "motor.h"
|
||||
#include "utils.h"
|
||||
#include "storage.h"
|
||||
#include "ble.h"
|
||||
#include "led.h"
|
||||
#include "consts.h"
|
||||
|
||||
void setup()
|
||||
|
@ -23,14 +24,19 @@ void setup()
|
|||
{MOTOR_C_PWMA, MOTOR_C_AIN1, MOTOR_C_AIN2},
|
||||
{MOTOR_D_PWMB, MOTOR_D_BIN1, MOTOR_D_BIN2});
|
||||
|
||||
// 设置引脚模式
|
||||
pinMode(STATUS_LED, OUTPUT);
|
||||
digitalWrite(STATUS_LED, HIGH);
|
||||
// 初始化状态灯
|
||||
if (STATUS_LED_ENABLE)
|
||||
{
|
||||
LED::init(STATUS_LED);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
updateStatusLED(BLEManager::deviceConnected, STATUS_LED);
|
||||
if (STATUS_LED_ENABLE)
|
||||
{
|
||||
LED::updateStatusLED(BLEManager::deviceConnected);
|
||||
}
|
||||
if (BLEManager::deviceConnected)
|
||||
{
|
||||
sendStatus(*BLEManager::pTxCharacteristic);
|
||||
|
|
Loading…
Reference in New Issue