🧼 Removes battery service
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
import { telemetry } from '$lib/stores/telemetry';
|
import { telemetry } from '$lib/stores/telemetry';
|
||||||
|
|
||||||
import RssiIndicator from '$lib/components/statusbar/RSSIIndicator.svelte';
|
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 UpdateIndicator from '$lib/components/statusbar/UpdateIndicator.svelte';
|
||||||
import SleepButton from './SleepButton.svelte';
|
import SleepButton from './SleepButton.svelte';
|
||||||
import ThemeButton from './ThemeButton.svelte';
|
import ThemeButton from './ThemeButton.svelte';
|
||||||
@@ -33,8 +32,6 @@
|
|||||||
|
|
||||||
<RssiIndicator rssi={$telemetry.rssi.rssi} />
|
<RssiIndicator rssi={$telemetry.rssi.rssi} />
|
||||||
|
|
||||||
<BatteryIndicator battery={$telemetry.battery} />
|
|
||||||
|
|
||||||
<SleepButton />
|
<SleepButton />
|
||||||
|
|
||||||
<StopButton />
|
<StopButton />
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export const servoAngles: Writable<number[]> = writable([
|
|||||||
0, 45, -90, 0, 45, -90, 0, 45, -90, 0, 45, -90
|
0, 45, -90, 0, 45, -90, 0, 45, -90, 0, 45, -90
|
||||||
]);
|
]);
|
||||||
export const logs = writable([] as string[]);
|
export const logs = writable([] as string[]);
|
||||||
export const battery = writable({});
|
|
||||||
export const mpu = writable({ heading: 0 });
|
export const mpu = writable({ heading: 0 });
|
||||||
export const sonar = writable([0, 0]);
|
export const sonar = writable([0, 0]);
|
||||||
export const distances = writable({});
|
export const distances = writable({});
|
||||||
@@ -16,7 +15,6 @@ export const distances = writable({});
|
|||||||
export interface socketDataCollection {
|
export interface socketDataCollection {
|
||||||
angles: Writable<angles>;
|
angles: Writable<angles>;
|
||||||
logs: Writable<string[]>;
|
logs: Writable<string[]>;
|
||||||
battery: Writable<unknown>;
|
|
||||||
mpu: Writable<unknown>;
|
mpu: Writable<unknown>;
|
||||||
distances: Writable<unknown>;
|
distances: Writable<unknown>;
|
||||||
}
|
}
|
||||||
@@ -24,7 +22,6 @@ export interface socketDataCollection {
|
|||||||
export const socketData = {
|
export const socketData = {
|
||||||
angles: servoAngles,
|
angles: servoAngles,
|
||||||
logs,
|
logs,
|
||||||
battery,
|
|
||||||
mpu,
|
mpu,
|
||||||
distances
|
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';
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
let telemetry_data = {
|
let telemetry_data = {
|
||||||
rssi: {
|
rssi: {
|
||||||
rssi: 0
|
rssi: 0
|
||||||
},
|
},
|
||||||
battery: {
|
download_ota: {
|
||||||
voltage: 0,
|
status: 'none',
|
||||||
current: 0
|
progress: 0,
|
||||||
},
|
error: ''
|
||||||
download_ota: {
|
}
|
||||||
status: 'none',
|
|
||||||
progress: 0,
|
|
||||||
error: ''
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function createTelemetry() {
|
function createTelemetry() {
|
||||||
const { subscribe, set, update } = writable(telemetry_data);
|
const { subscribe, set, update } = writable(telemetry_data);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
setRSSI: (data: number) => {
|
setRSSI: (data: number) => {
|
||||||
update((telemetry_data) => ({
|
update(telemetry_data => ({
|
||||||
...telemetry_data,
|
...telemetry_data,
|
||||||
rssi: { rssi: data }
|
rssi: { rssi: data }
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
setBattery: (data: Battery) => {
|
setDownloadOTA: (data: DownloadOTA) => {
|
||||||
update((telemetry_data) => ({
|
update(telemetry_data => ({
|
||||||
...telemetry_data,
|
...telemetry_data,
|
||||||
battery: { voltage: data.voltage, current: data.current }
|
download_ota: { status: data.status, progress: data.progress, error: data.error }
|
||||||
}));
|
}));
|
||||||
},
|
}
|
||||||
setDownloadOTA: (data: DownloadOTA) => {
|
};
|
||||||
update((telemetry_data) => ({
|
|
||||||
...telemetry_data,
|
|
||||||
download_ota: { status: data.status, progress: data.progress, error: data.error }
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const telemetry = createTelemetry();
|
export const telemetry = createTelemetry();
|
||||||
|
|||||||
@@ -89,11 +89,6 @@ export type NTPStatus = {
|
|||||||
uptime: number;
|
uptime: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Battery = {
|
|
||||||
voltage: number;
|
|
||||||
current: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type DownloadOTA = {
|
export type DownloadOTA = {
|
||||||
status: string;
|
status: string;
|
||||||
progress: number;
|
progress: number;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
location,
|
location,
|
||||||
useFeatureFlags
|
useFeatureFlags
|
||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
import type { Analytics, Battery, DownloadOTA } from '$lib/types/models';
|
import type { Analytics, DownloadOTA } from '$lib/types/models';
|
||||||
|
|
||||||
const features = useFeatureFlags();
|
const features = useFeatureFlags();
|
||||||
|
|
||||||
@@ -52,7 +52,6 @@
|
|||||||
if (angles.length) servoAngles.set(angles);
|
if (angles.length) servoAngles.set(angles);
|
||||||
});
|
});
|
||||||
features.subscribe(data => {
|
features.subscribe(data => {
|
||||||
if (data?.battery) socket.on('battery', handleBattery);
|
|
||||||
if (data?.download_firmware) socket.on('otastatus', handleOAT);
|
if (data?.download_firmware) socket.on('otastatus', handleOAT);
|
||||||
if (data?.sonar) socket.on('sonar', data => console.log(data));
|
if (data?.sonar) socket.on('sonar', data => console.log(data));
|
||||||
});
|
});
|
||||||
@@ -63,7 +62,6 @@
|
|||||||
socket.off('open', handleOpen);
|
socket.off('open', handleOpen);
|
||||||
socket.off('close', handleClose);
|
socket.off('close', handleClose);
|
||||||
socket.off('rssi', handleNetworkStatus);
|
socket.off('rssi', handleNetworkStatus);
|
||||||
socket.off('battery', handleBattery);
|
|
||||||
socket.off('otastatus', handleOAT);
|
socket.off('otastatus', handleOAT);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,8 +80,6 @@
|
|||||||
|
|
||||||
const handleNetworkStatus = (data: number) => telemetry.setRSSI(data);
|
const handleNetworkStatus = (data: number) => telemetry.setRSSI(data);
|
||||||
|
|
||||||
const handleBattery = (data: Battery) => telemetry.setBattery(data);
|
|
||||||
|
|
||||||
const handleOAT = (data: DownloadOTA) => telemetry.setDownloadOTA(data);
|
const handleOAT = (data: DownloadOTA) => telemetry.setDownloadOTA(data);
|
||||||
|
|
||||||
let menuOpen = false;
|
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 |
|
<!-- | HTTP Method | Endpoint | Description | Parameters |
|
||||||
|-------------|----------------|----------------------------|---------------------------|
|
|-------------|----------------|----------------------------|---------------------------|
|
||||||
| GET | /api/sensor/battery | Retrieve the battery state | |
|
|
||||||
| GET | /api/sensor/mpu | Retrieve the mpu state | |
|
| GET | /api/sensor/mpu | Retrieve the mpu state | |
|
||||||
| GET | /api/sensor/magnetometer | Retrieve the magnetometer state | |
|
| GET | /api/sensor/magnetometer | Retrieve the magnetometer state | |
|
||||||
| GET | /api/sensor/distances | Retrieve the distances state | |
|
| GET | /api/sensor/distances | Retrieve the distances state | |
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
[features]
|
[features]
|
||||||
build_flags =
|
build_flags =
|
||||||
-D USE_BATTERY=1
|
|
||||||
-D USE_NTP=1
|
-D USE_NTP=1
|
||||||
-D USE_SLEEP=0
|
-D USE_SLEEP=0
|
||||||
-D USE_UPLOAD_FIRMWARE=1
|
-D USE_UPLOAD_FIRMWARE=1
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <BatteryService.h>
|
|
||||||
#include <filesystem.h>
|
#include <filesystem.h>
|
||||||
#include <firmware_download_service.h>
|
#include <firmware_download_service.h>
|
||||||
#include <firmware_upload_service.h>
|
#include <firmware_upload_service.h>
|
||||||
@@ -71,7 +70,6 @@ class Spot {
|
|||||||
// _peripherals.loop();
|
// _peripherals.loop();
|
||||||
EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); });
|
EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); });
|
||||||
// _peripherals.emitSonar();
|
// _peripherals.emitSonar();
|
||||||
// _peripherals.emitBattery();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -88,9 +86,6 @@ class Spot {
|
|||||||
#if FT_ENABLED(USE_DOWNLOAD_FIRMWARE)
|
#if FT_ENABLED(USE_DOWNLOAD_FIRMWARE)
|
||||||
DownloadFirmwareService _downloadFirmwareService;
|
DownloadFirmwareService _downloadFirmwareService;
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_BATTERY)
|
|
||||||
BatteryService _batteryService;
|
|
||||||
#endif
|
|
||||||
#if FT_ENABLED(USE_MOTION)
|
#if FT_ENABLED(USE_MOTION)
|
||||||
MotionService _motionService;
|
MotionService _motionService;
|
||||||
#endif
|
#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["upload_firmware"] = USE_UPLOAD_FIRMWARE;
|
||||||
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
|
root["download_firmware"] = USE_DOWNLOAD_FIRMWARE;
|
||||||
root["sleep"] = USE_SLEEP;
|
root["sleep"] = USE_SLEEP;
|
||||||
root["battery"] = USE_BATTERY;
|
|
||||||
root["camera"] = USE_CAMERA;
|
root["camera"] = USE_CAMERA;
|
||||||
root["imu"] = USE_IMU;
|
root["imu"] = USE_IMU;
|
||||||
root["mag"] = USE_MAG;
|
root["mag"] = USE_MAG;
|
||||||
|
|||||||
@@ -27,11 +27,6 @@
|
|||||||
#define USE_SLEEP 0
|
#define USE_SLEEP 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ESP32 battery state off by default
|
|
||||||
#ifndef USE_BATTERY
|
|
||||||
#define USE_BATTERY 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ESP32 camera off by default
|
// ESP32 camera off by default
|
||||||
#ifndef USE_CAMERA
|
#ifndef USE_CAMERA
|
||||||
#define USE_CAMERA 0
|
#define USE_CAMERA 0
|
||||||
|
|||||||
+1
-8
@@ -3,11 +3,7 @@
|
|||||||
static const char *TAG = "Spot";
|
static const char *TAG = "Spot";
|
||||||
|
|
||||||
Spot::Spot(PsychicHttpServer *server)
|
Spot::Spot(PsychicHttpServer *server)
|
||||||
:
|
: _servoController(&_peripherals),
|
||||||
#if FT_ENABLED(USE_BATTERY)
|
|
||||||
_batteryService(&_peripherals),
|
|
||||||
#endif
|
|
||||||
_servoController(&_peripherals),
|
|
||||||
#if FT_ENABLED(USE_MOTION)
|
#if FT_ENABLED(USE_MOTION)
|
||||||
_motionService(&_servoController),
|
_motionService(&_servoController),
|
||||||
#endif
|
#endif
|
||||||
@@ -187,9 +183,6 @@ void Spot::startServices() {
|
|||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_NTP)
|
#if FT_ENABLED(USE_NTP)
|
||||||
_ntpService.begin();
|
_ntpService.begin();
|
||||||
#endif
|
|
||||||
#if FT_ENABLED(USE_BATTERY)
|
|
||||||
_batteryService.begin();
|
|
||||||
#endif
|
#endif
|
||||||
_peripherals.begin();
|
_peripherals.begin();
|
||||||
_servoController.begin();
|
_servoController.begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user