fix: status led
This commit is contained in:
parent
94eb8c2339
commit
cba7320b00
|
@ -57,6 +57,9 @@
|
|||
#define PID_KI 0.01
|
||||
#define PID_KD 0.001
|
||||
|
||||
// LED闪烁间隔(ms)
|
||||
#define LED_FLASH_INTERVAL 1000
|
||||
|
||||
// Nordic UART Service UUID
|
||||
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#define __LED_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "consts.h"
|
||||
|
||||
class LED
|
||||
{
|
||||
public:
|
||||
static int ledPin;
|
||||
static unsigned long lastLedToggle;
|
||||
static bool ledState;
|
||||
static void init(int pin);
|
||||
static void updateStatusLED(bool status);
|
||||
};
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
|
||||
[env:esp32s3]
|
||||
platform = espressif32
|
||||
board = adafruit_feather_esp32s3_tft
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
|
|
|
@ -36,6 +36,7 @@ class BLEManagerCharacteristicCallbacks : public BLECharacteristicCallbacks
|
|||
|
||||
void BLEManager::init(String deviceName)
|
||||
{
|
||||
Serial.println("BLE Init, deviceName: " + deviceName);
|
||||
BLEDevice::init(deviceName.c_str());
|
||||
pServer = BLEDevice::createServer();
|
||||
pServer->setCallbacks(new BLEManagerServerCallbacks());
|
||||
|
|
|
@ -5,6 +5,7 @@ IRData IR::data;
|
|||
|
||||
void IR::init(IRConfig config)
|
||||
{
|
||||
Serial.println("IR Init");
|
||||
IR::config = config;
|
||||
if (config.mode == IRMode::IR_MODE_GPIO)
|
||||
{
|
||||
|
|
18
src/led.cpp
18
src/led.cpp
|
@ -1,9 +1,12 @@
|
|||
#include "led.h"
|
||||
|
||||
int LED::ledPin = 0;
|
||||
unsigned long LED::lastLedToggle = 0;
|
||||
bool LED::ledState = false;
|
||||
|
||||
void LED::init(int pin)
|
||||
{
|
||||
Serial.println("LED Init");
|
||||
ledPin = pin;
|
||||
pinMode(ledPin, OUTPUT);
|
||||
digitalWrite(ledPin, HIGH);
|
||||
|
@ -11,5 +14,18 @@ void LED::init(int pin)
|
|||
|
||||
void LED::updateStatusLED(bool status)
|
||||
{
|
||||
digitalWrite(ledPin, status);
|
||||
if (status)
|
||||
{
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - lastLedToggle >= LED_FLASH_INTERVAL)
|
||||
{
|
||||
lastLedToggle = currentMillis;
|
||||
ledState = !ledState;
|
||||
digitalWrite(ledPin, ledState);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,8 @@ void MotorController::init(
|
|||
MotorPin cPin,
|
||||
MotorPin dPin)
|
||||
{
|
||||
Serial.println("Motor Init");
|
||||
|
||||
motorA.pin = aPin;
|
||||
motorB.pin = bPin;
|
||||
motorC.pin = cPin;
|
||||
|
|
|
@ -10,8 +10,11 @@ void Storage::init()
|
|||
isMounted = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("SPIFFS Mount Success");
|
||||
isMounted = true;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Storage::getSensitivity()
|
||||
{
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#include "utils.h"
|
||||
|
||||
#define LED_FLASH_INTERVAL 1000 // LED闪烁间隔(ms)
|
||||
unsigned long lastLedToggle = 0; // 上次LED切换状态的时间
|
||||
bool ledState = false; // LED当前状态
|
||||
|
||||
void floatToBytes(float val, uint8_t *bytes)
|
||||
{
|
||||
union
|
||||
|
@ -33,21 +29,3 @@ float bytesToFloat(uint8_t *bytes)
|
|||
}
|
||||
return u.f;
|
||||
}
|
||||
|
||||
void updateStatusLED(bool deviceConnected, int ledPin)
|
||||
{
|
||||
if (deviceConnected)
|
||||
{
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - lastLedToggle >= LED_FLASH_INTERVAL)
|
||||
{
|
||||
lastLedToggle = currentMillis;
|
||||
ledState = !ledState;
|
||||
digitalWrite(ledPin, ledState);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue