Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧼 Removes battery service #112

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/src/lib/components/statusbar/statusbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -33,8 +32,6 @@

<RssiIndicator rssi={$telemetry.rssi.rssi} />

<BatteryIndicator battery={$telemetry.battery} />

<SleepButton />

<StopButton />
Expand Down
3 changes: 0 additions & 3 deletions app/src/lib/stores/socket-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ 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({});

export interface socketDataCollection {
angles: Writable<angles>;
logs: Writable<string[]>;
battery: Writable<unknown>;
mpu: Writable<unknown>;
distances: Writable<unknown>;
}

export const socketData = {
angles: servoAngles,
logs,
battery,
mpu,
distances
};
60 changes: 25 additions & 35 deletions app/src/lib/stores/telemetry.ts
Original file line number Diff line number Diff line change
@@ -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();
5 changes: 0 additions & 5 deletions app/src/lib/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ export type NTPStatus = {
uptime: number;
};

export type Battery = {
voltage: number;
current: number;
};

export type DownloadOTA = {
status: string;
progress: number;
Expand Down
6 changes: 1 addition & 5 deletions app/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
});
Expand All @@ -63,7 +62,6 @@
socket.off('open', handleOpen);
socket.off('close', handleClose);
socket.off('rssi', handleNetworkStatus);
socket.off('battery', handleBattery);
socket.off('otastatus', handleOAT);
};

Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
4 changes: 1 addition & 3 deletions esp32/features.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[features]
build_flags =
-D USE_BATTERY=1
-D USE_NTP=1
-D USE_SLEEP=0
-D USE_UPLOAD_FIRMWARE=1
Expand All @@ -14,5 +13,4 @@ build_flags =
-D USE_GPS=0
-D USE_WS2812=1
-D USE_USS=0
-D USE_SERVO=1
-D USE_ADS1115=0
-D USE_SERVO=1
5 changes: 0 additions & 5 deletions esp32/include/spot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <Arduino.h>

#include <BatteryService.h>
#include <filesystem.h>
#include <firmware_download_service.h>
#include <firmware_upload_service.h>
Expand Down Expand Up @@ -71,7 +70,6 @@ class Spot {
// _peripherals.loop();
EXECUTE_EVERY_N_MS(1000, { _peripherals.emitIMU(); });
// _peripherals.emitSonar();
// _peripherals.emitBattery();
}

private:
Expand All @@ -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
Expand Down
28 changes: 0 additions & 28 deletions esp32/lib/ESP32-sveltekit/BatteryService.cpp

This file was deleted.

64 changes: 0 additions & 64 deletions esp32/lib/ESP32-sveltekit/BatteryService.h

This file was deleted.

24 changes: 0 additions & 24 deletions esp32/lib/ESP32-sveltekit/Peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <Adafruit_BMP085_U.h>
#include <Adafruit_HMC5883_U.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADS1X15.h>
#include <NewPing.h>
#include <peripherals/imu.h>

Expand Down Expand Up @@ -115,13 +114,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
}
#endif

#if FT_ENABLED(FT_ADS1015) || FT_ENABLED(USE_ADS1115)
if (!_ads.begin()) {
ESP_LOGE("Peripherals", "ADS1015/ADS1115 not found");
}
_ads.startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_0_1, /*continuous=*/false);
#endif

#if FT_ENABLED(USE_USS)
_left_sonar = new NewPing(USS_LEFT_PIN, USS_LEFT_PIN, MAX_DISTANCE);
_right_sonar = new NewPing(USS_RIGHT_PIN, USS_RIGHT_PIN, MAX_DISTANCE);
Expand Down Expand Up @@ -231,16 +223,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
#endif
}

/* ADC FUNCTIONS*/
int16_t readADCVoltage(uint8_t channel) {
int16_t voltage = -1;
#if FT_ENABLED(FT_ADS1015) || FT_ENABLED(USE_ADS1115)
float adc0 = _ads.readADC_SingleEnded(channel);
voltage = _ads.computeVolts(adc0);
#endif
return voltage;
}

/* IMU FUNCTIONS */
bool readIMU() {
bool updated = false;
Expand Down Expand Up @@ -372,12 +354,6 @@ class Peripherals : public StatefulService<PeripheralsConfiguration> {
Adafruit_BMP085_Unified _bmp;
bool bmp_success {false};
#endif
#if FT_ENABLED(FT_ADS1015)
Adafruit_ADS1015 _ads;
#endif
#if FT_ENABLED(USE_ADS1115)
Adafruit_ADS1115 _ads;
#endif
#if FT_ENABLED(USE_USS)
NewPing *_left_sonar;
NewPing *_right_sonar;
Expand Down
1 change: 0 additions & 1 deletion esp32/lib/ESP32-sveltekit/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions esp32/lib/ESP32-sveltekit/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions esp32/src/spot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Loading