🧼 Removes battery service
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user