Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwhitehead committed Mar 1, 2024
1 parent 7aeb914 commit 64eed1f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 43 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ lib_deps =
adafruit/Adafruit ST7735 and ST7789 [email protected]
adafruit/Adafruit [email protected]
https://github.com/rlogiacco/[email protected]
Adafruit GFX [email protected].7
Adafruit GFX [email protected].9
lib_ignore =
Adafruit SleepyDog Library
${extra.lib_ignore}
14 changes: 7 additions & 7 deletions src/sp140/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ void updateDisplay(
// canvas.printf(" %3d %2d %2d", escTelemetry.lastReadBytes, escTelemetry.errorStopBytes, escTelemetry.errorChecksum);

// // DEBUG WATCHDOG
#ifdef RP_PIO
canvas.setTextSize(1);
canvas.setCursor(4, 118);
canvas.printf("watchdog %d %d", watchdogCausedReboot, watchdogEnableCausedReboot);
#endif
// #ifdef RP_PIO
// canvas.setTextSize(1);
// canvas.setCursor(4, 118);
// canvas.printf("watchdog %d %d", watchdogCausedReboot, watchdogEnableCausedReboot);
// #endif
//
// // DEBUG FREE MEMORY
// #ifdef RP_PIO
Expand All @@ -277,9 +277,9 @@ void updateDisplay(
void setTheme(int theme) {
if (theme == 1) {
currentTheme = &darkModeColors;
Serial.println("Switched to Dark Mode");
// Serial.println("Switched to Dark Mode");
} else {
currentTheme = &lightModeColors;
Serial.println("Switched to Light Mode");
// Serial.println("Switched to Light Mode");
}
}
40 changes: 10 additions & 30 deletions src/sp140/extra-data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ const int DEFAULT_BATT_SIZE = 4000; // 4kw
// read saved data from EEPROM
void refreshDeviceData() {
uint16_t crc;
EEPROM.get(EEPROM_OFFSET, deviceData);
#ifdef M0_PIO
if (0 != eep.read(EEPROM_OFFSET, deviceData, sizeof(deviceData))) {
// Serial.println(F("error reading EEPROM"));
}
#elif RP_PIO
EEPROM.get(EEPROM_OFFSET, deviceData);
#endif
crc = crc16((uint8_t*)&deviceData, sizeof(deviceData) - 2);

// If the CRC does not match, reset the device data
Expand All @@ -28,17 +34,6 @@ void refreshDeviceData() {
//updateRevisionIfRequired();
}

// Read device data from EEPROM
void readDeviceDataFromEEPROM(uint8_t* buffer) {
#ifdef M0_PIO
if (0 != eep.read(EEPROM_OFFSET, buffer, sizeof(deviceData))) {
// Serial.println(F("error reading EEPROM"));
}
#elif RP_PIO
EEPROM.get(EEPROM_OFFSET, buffer);
#endif
}

// Update the revision if required
void updateRevisionIfRequired() {
#ifdef RP_PIO
Expand All @@ -49,30 +44,15 @@ void updateRevisionIfRequired() {
#endif
}

// One time freeRTOS task that wraps writeDeviceData()
void writeDeviceDataTask(void *pvParameters) {
if (eepromSemaphore != NULL) {
if (xSemaphoreTake(eepromSemaphore, (TickType_t)10) == pdTRUE) {
// Your EEPROM write logic here
writeDeviceData();
// Once done, release the semaphore
xSemaphoreGive(eepromSemaphore);
}
}

// Delete the task after completion
vTaskDelete(NULL);
}

// Write to EEPROM
void writeDeviceData() {
deviceData.crc = crc16((uint8_t*)&deviceData, sizeof(deviceData) - 2);
printDeviceData();
EEPROM.put(EEPROM_OFFSET, deviceData);
if (EEPROM.commit()) {
Serial.println("EEPROM commit successful");
// Serial.println("EEPROM commit successful");
} else {
Serial.println("EEPROM commit failed");
// Serial.println("EEPROM commit failed");
}
}

Expand All @@ -84,7 +64,7 @@ void resetDeviceData() {
#ifdef M0_PIO
deviceData.revision = 0;
#elif RP_PIO
deviceData.revision = 2; // Default to new 2040 board revision
deviceData.revision = 2; // Default to new 2040 board revision // TODO
#endif

deviceData.version_major = VERSION_MAJOR;
Expand Down
6 changes: 1 addition & 5 deletions src/sp140/sp140.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
#include "pico/unique_id.h"
#endif


#include "../../inc/sp140/globals.h" // device config

//#include "../../inc/sp140/utilities.h"
#include "../../inc/sp140/display.h"
#include "../../inc/sp140/altimeter.h"

Expand Down Expand Up @@ -74,7 +72,6 @@ uint32_t cruisedAtMillisMilis = 0;
unsigned int armedSecs = 0;
unsigned int last_throttle = 0;

TaskHandle_t checkButtonTaskHandle = NULL;
TaskHandle_t blinkLEDTaskHandle = NULL;
TaskHandle_t throttleTaskHandle = NULL;
TaskHandle_t telemetryTaskHandle = NULL;
Expand Down Expand Up @@ -207,7 +204,6 @@ void setup() {
modeSwitch(false);
}
vTaskResume(updateDisplayTaskHandle);
//vTaskResume(checkButtonTaskHandle);

setLEDColor(LED_GREEN);
}
Expand Down Expand Up @@ -268,7 +264,6 @@ void psTop() {
Serial.printf("\nthrottleTask - Free Stack Space: %d", uxTaskGetStackHighWaterMark(throttleTaskHandle));
Serial.printf("\ntelemetryTask - Free Stack Space: %d", uxTaskGetStackHighWaterMark(telemetryTaskHandle));
Serial.printf("\ntrackPowerTask - Free Stack Space: %d", uxTaskGetStackHighWaterMark(trackPowerTaskHandle));
Serial.printf("\ncheckButtonTask - Free Stack Space: %d", uxTaskGetStackHighWaterMark(checkButtonTaskHandle));
Serial.printf("\nupdateDisplayTask - Free Stack Space: %d", uxTaskGetStackHighWaterMark(updateDisplayTaskHandle));
Serial.println("");
}
Expand All @@ -295,6 +290,7 @@ void loop() {
if (!armed && usb_web.available()) parse_usb_serial();
#endif

// more stable in main loop
checkButtons();
delay(5);
//ps();
Expand Down

0 comments on commit 64eed1f

Please sign in to comment.