🧼 Removes battery service
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
[features]
|
||||
build_flags =
|
||||
-D USE_BATTERY=1
|
||||
-D USE_NTP=1
|
||||
-D USE_SLEEP=0
|
||||
-D USE_UPLOAD_FIRMWARE=1
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <BatteryService.h>
|
||||
#include <filesystem.h>
|
||||
#include <firmware_download_service.h>
|
||||
#include <firmware_upload_service.h>
|
||||
@@ -71,7 +70,6 @@ class Spot {
|
||||
// _peripherals.loop();
|
||||
EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); });
|
||||
// _peripherals.emitSonar();
|
||||
// _peripherals.emitBattery();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -88,9 +86,6 @@ class Spot {
|
||||
#if FT_ENABLED(USE_DOWNLOAD_FIRMWARE)
|
||||
DownloadFirmwareService _downloadFirmwareService;
|
||||
#endif
|
||||
#if FT_ENABLED(USE_BATTERY)
|
||||
BatteryService _batteryService;
|
||||
#endif
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
MotionService _motionService;
|
||||
#endif
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* ESP32 SvelteKit
|
||||
*
|
||||
* A simple, secure and extensible framework for IoT projects for ESP32 platforms
|
||||
* with responsive Sveltekit front-end built with TailwindCSS and DaisyUI.
|
||||
* https://github.com/theelims/ESP32-sveltekit
|
||||
*
|
||||
* Copyright (C) 2023 theelims
|
||||
* Copyright (C) 2024 runeharlyk
|
||||
*
|
||||
* All Rights Reserved. This software may be modified and distributed under
|
||||
* the terms of the LGPL v3 license. See the LICENSE file for details.
|
||||
**/
|
||||
|
||||
#include <BatteryService.h>
|
||||
|
||||
BatteryService::BatteryService(Peripherals *peripherals) : _peripherals(peripherals) {}
|
||||
|
||||
void BatteryService::begin() {}
|
||||
|
||||
void BatteryService::batteryEvent() {
|
||||
JsonDocument doc;
|
||||
char message[64];
|
||||
doc["voltage"] = _voltage;
|
||||
doc["current"] = _current;
|
||||
serializeJson(doc, message);
|
||||
socket.emit(EVENT_BATTERY, message);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* ESP32 SvelteKit
|
||||
*
|
||||
* A simple, secure and extensible framework for IoT projects for ESP32 platforms
|
||||
* with responsive Sveltekit front-end built with TailwindCSS and DaisyUI.
|
||||
* https://github.com/theelims/ESP32-sveltekit
|
||||
*
|
||||
* Copyright (C) 2023 theelims
|
||||
* Copyright (C) 2024 runeharlyk
|
||||
*
|
||||
* All Rights Reserved. This software may be modified and distributed under
|
||||
* the terms of the LGPL v3 license. See the LICENSE file for details.
|
||||
**/
|
||||
|
||||
#include <event_socket.h>
|
||||
#include <utils/json_utils.h>
|
||||
#include <Peripherals.h>
|
||||
#include <utils/timing.h>
|
||||
|
||||
#define ADC_VOLTAGE 0
|
||||
#define ADC_CURRENT 1
|
||||
#define ADC_BUTTON 2
|
||||
|
||||
#define EVENT_BATTERY "battery"
|
||||
#define BATTERY_INTERVAL 10000
|
||||
#define BATTERY_CHECK_INTERVAL 1000
|
||||
|
||||
// #define CURRENT_FACTOR 0.185 // 5A
|
||||
// #define CURRENT_FACTOR 0.100 // 20A
|
||||
#define CURRENT_FACTOR 0.066 // 30A
|
||||
|
||||
#define VOLTAGE_THRESHOLD 6.4
|
||||
#define CURRENT_THRESHOLD 5
|
||||
|
||||
class BatteryService {
|
||||
public:
|
||||
BatteryService(Peripherals *peripherals);
|
||||
|
||||
void begin();
|
||||
|
||||
void loop() {
|
||||
EXECUTE_EVERY_N_MS(BATTERY_CHECK_INTERVAL, updateBattery());
|
||||
EXECUTE_EVERY_N_MS(BATTERY_INTERVAL, batteryEvent());
|
||||
}
|
||||
|
||||
void updateBattery() {
|
||||
_voltage = _peripherals->readADCVoltage(ADC_VOLTAGE);
|
||||
float voltage = _peripherals->readADCVoltage(ADC_CURRENT);
|
||||
_current = (voltage - 2.5) / CURRENT_FACTOR;
|
||||
}
|
||||
|
||||
float getVoltage() { return _voltage; }
|
||||
|
||||
float getCurrent() { return _current; }
|
||||
|
||||
private:
|
||||
void batteryEvent();
|
||||
Peripherals *_peripherals;
|
||||
|
||||
float _voltage = 0;
|
||||
float _current = 0;
|
||||
};
|
||||
@@ -7,7 +7,6 @@ void features(JsonObject &root) {
|
||||
root["upload_firmware"] = USE_UPLOAD_FIRMWARE;
|
||||
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
|
||||
root["sleep"] = USE_SLEEP;
|
||||
root["battery"] = USE_BATTERY;
|
||||
root["camera"] = USE_CAMERA;
|
||||
root["imu"] = USE_IMU;
|
||||
root["mag"] = USE_MAG;
|
||||
|
||||
@@ -27,11 +27,6 @@
|
||||
#define USE_SLEEP 0
|
||||
#endif
|
||||
|
||||
// ESP32 battery state off by default
|
||||
#ifndef USE_BATTERY
|
||||
#define USE_BATTERY 0
|
||||
#endif
|
||||
|
||||
// ESP32 camera off by default
|
||||
#ifndef USE_CAMERA
|
||||
#define USE_CAMERA 0
|
||||
|
||||
+1
-8
@@ -3,11 +3,7 @@
|
||||
static const char *TAG = "Spot";
|
||||
|
||||
Spot::Spot(PsychicHttpServer *server)
|
||||
:
|
||||
#if FT_ENABLED(USE_BATTERY)
|
||||
_batteryService(&_peripherals),
|
||||
#endif
|
||||
_servoController(&_peripherals),
|
||||
: _servoController(&_peripherals),
|
||||
#if FT_ENABLED(USE_MOTION)
|
||||
_motionService(&_servoController),
|
||||
#endif
|
||||
@@ -187,9 +183,6 @@ void Spot::startServices() {
|
||||
#endif
|
||||
#if FT_ENABLED(USE_NTP)
|
||||
_ntpService.begin();
|
||||
#endif
|
||||
#if FT_ENABLED(USE_BATTERY)
|
||||
_batteryService.begin();
|
||||
#endif
|
||||
_peripherals.begin();
|
||||
_servoController.begin();
|
||||
|
||||
Reference in New Issue
Block a user