🧼 Removes battery service
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import { telemetry } from '$lib/stores/telemetry';
|
||||
|
||||
import RssiIndicator from '$lib/components/statusbar/RSSIIndicator.svelte';
|
||||
import BatteryIndicator from '$lib/components/statusbar/BatteryIndicator.svelte';
|
||||
import UpdateIndicator from '$lib/components/statusbar/UpdateIndicator.svelte';
|
||||
import SleepButton from './SleepButton.svelte';
|
||||
import ThemeButton from './ThemeButton.svelte';
|
||||
@@ -33,8 +32,6 @@
|
||||
|
||||
<RssiIndicator rssi={$telemetry.rssi.rssi} />
|
||||
|
||||
<BatteryIndicator battery={$telemetry.battery} />
|
||||
|
||||
<SleepButton />
|
||||
|
||||
<StopButton />
|
||||
|
||||
@@ -8,7 +8,6 @@ export const servoAngles: Writable<number[]> = writable([
|
||||
0, 45, -90, 0, 45, -90, 0, 45, -90, 0, 45, -90
|
||||
]);
|
||||
export const logs = writable([] as string[]);
|
||||
export const battery = writable({});
|
||||
export const mpu = writable({ heading: 0 });
|
||||
export const sonar = writable([0, 0]);
|
||||
export const distances = writable({});
|
||||
@@ -16,7 +15,6 @@ export const distances = writable({});
|
||||
export interface socketDataCollection {
|
||||
angles: Writable<angles>;
|
||||
logs: Writable<string[]>;
|
||||
battery: Writable<unknown>;
|
||||
mpu: Writable<unknown>;
|
||||
distances: Writable<unknown>;
|
||||
}
|
||||
@@ -24,7 +22,6 @@ export interface socketDataCollection {
|
||||
export const socketData = {
|
||||
angles: servoAngles,
|
||||
logs,
|
||||
battery,
|
||||
mpu,
|
||||
distances
|
||||
};
|
||||
|
||||
@@ -1,45 +1,35 @@
|
||||
import type { Battery, DownloadOTA } from '$lib/types/models';
|
||||
import type { DownloadOTA } from '$lib/types/models';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
let telemetry_data = {
|
||||
rssi: {
|
||||
rssi: 0
|
||||
},
|
||||
battery: {
|
||||
voltage: 0,
|
||||
current: 0
|
||||
},
|
||||
download_ota: {
|
||||
status: 'none',
|
||||
progress: 0,
|
||||
error: ''
|
||||
}
|
||||
rssi: {
|
||||
rssi: 0
|
||||
},
|
||||
download_ota: {
|
||||
status: 'none',
|
||||
progress: 0,
|
||||
error: ''
|
||||
}
|
||||
};
|
||||
|
||||
function createTelemetry() {
|
||||
const { subscribe, set, update } = writable(telemetry_data);
|
||||
const { subscribe, set, update } = writable(telemetry_data);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
setRSSI: (data: number) => {
|
||||
update((telemetry_data) => ({
|
||||
...telemetry_data,
|
||||
rssi: { rssi: data }
|
||||
}));
|
||||
},
|
||||
setBattery: (data: Battery) => {
|
||||
update((telemetry_data) => ({
|
||||
...telemetry_data,
|
||||
battery: { voltage: data.voltage, current: data.current }
|
||||
}));
|
||||
},
|
||||
setDownloadOTA: (data: DownloadOTA) => {
|
||||
update((telemetry_data) => ({
|
||||
...telemetry_data,
|
||||
download_ota: { status: data.status, progress: data.progress, error: data.error }
|
||||
}));
|
||||
}
|
||||
};
|
||||
return {
|
||||
subscribe,
|
||||
setRSSI: (data: number) => {
|
||||
update(telemetry_data => ({
|
||||
...telemetry_data,
|
||||
rssi: { rssi: data }
|
||||
}));
|
||||
},
|
||||
setDownloadOTA: (data: DownloadOTA) => {
|
||||
update(telemetry_data => ({
|
||||
...telemetry_data,
|
||||
download_ota: { status: data.status, progress: data.progress, error: data.error }
|
||||
}));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const telemetry = createTelemetry();
|
||||
|
||||
@@ -89,11 +89,6 @@ export type NTPStatus = {
|
||||
uptime: number;
|
||||
};
|
||||
|
||||
export type Battery = {
|
||||
voltage: number;
|
||||
current: number;
|
||||
};
|
||||
|
||||
export type DownloadOTA = {
|
||||
status: string;
|
||||
progress: number;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
location,
|
||||
useFeatureFlags
|
||||
} from '$lib/stores';
|
||||
import type { Analytics, Battery, DownloadOTA } from '$lib/types/models';
|
||||
import type { Analytics, DownloadOTA } from '$lib/types/models';
|
||||
|
||||
const features = useFeatureFlags();
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
if (angles.length) servoAngles.set(angles);
|
||||
});
|
||||
features.subscribe(data => {
|
||||
if (data?.battery) socket.on('battery', handleBattery);
|
||||
if (data?.download_firmware) socket.on('otastatus', handleOAT);
|
||||
if (data?.sonar) socket.on('sonar', data => console.log(data));
|
||||
});
|
||||
@@ -63,7 +62,6 @@
|
||||
socket.off('open', handleOpen);
|
||||
socket.off('close', handleClose);
|
||||
socket.off('rssi', handleNetworkStatus);
|
||||
socket.off('battery', handleBattery);
|
||||
socket.off('otastatus', handleOAT);
|
||||
};
|
||||
|
||||
@@ -82,8 +80,6 @@
|
||||
|
||||
const handleNetworkStatus = (data: number) => telemetry.setRSSI(data);
|
||||
|
||||
const handleBattery = (data: Battery) => telemetry.setBattery(data);
|
||||
|
||||
const handleOAT = (data: DownloadOTA) => telemetry.setDownloadOTA(data);
|
||||
|
||||
let menuOpen = false;
|
||||
|
||||
@@ -27,7 +27,6 @@ The back end exposes a number of API endpoints which are referenced in the table
|
||||
|
||||
<!-- | HTTP Method | Endpoint | Description | Parameters |
|
||||
|-------------|----------------|----------------------------|---------------------------|
|
||||
| GET | /api/sensor/battery | Retrieve the battery state | |
|
||||
| GET | /api/sensor/mpu | Retrieve the mpu state | |
|
||||
| GET | /api/sensor/magnetometer | Retrieve the magnetometer state | |
|
||||
| GET | /api/sensor/distances | Retrieve the distances state | |
|
||||
|
||||
@@ -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