Skip to content

Commit

Permalink
More cleanup and debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwhitehead committed Apr 19, 2024
1 parent 03fd3a0 commit d3f6a00
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ framework = arduino
board_build.core = earlephilhower
build_flags = -DRP_PIO -DUSE_TINYUSB
test_framework = unity
monitor_filters =
time

; configure filesystem size. Default 0 Mbyte.
; Out of 16Mbyte available
Expand Down
6 changes: 3 additions & 3 deletions src/sp140/extra-data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void refreshDeviceData() {
crc = crc16((uint8_t*)&deviceData, sizeof(deviceData) - 2);

// If the CRC does not match, reset the device data
if (crc != deviceData.crc) {
if (crc != deviceData.crc || deviceData.sea_pressure < 0) {
Serial.println(F("EEPROM CRC mismatch - resetting device data"));
resetDeviceData();
}
Expand All @@ -50,9 +50,9 @@ void writeDeviceData() {
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 Down
57 changes: 37 additions & 20 deletions src/sp140/sp140.ino
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void watchdogTask(void* parameter) {
}
}

#define ENABLE_NEOPIXEL true // TODO make this a config option

void blinkLEDTask(void *pvParameters) {
(void) pvParameters; // this is a standard idiom to avoid compiler warnings about unused parameters.

Expand Down Expand Up @@ -201,6 +203,7 @@ void loadHardwareConfig() {
button_top = new AceButton(board_config.button_top);
buttonConfig = button_top->getButtonConfig();
}

void commonSetup() {
Serial.begin(115200);
SerialESC.begin(ESC_BAUD_RATE);
Expand All @@ -212,17 +215,38 @@ void commonSetup() {
usb_web.setLineStateCallback(line_state_callback);
#endif

//Serial.print(F("Booting up (USB) V"));
//Serial.print(VERSION_MAJOR + "." + VERSION_MINOR);
//wait for serial connection
while (!Serial) {
delay(10);
}

Serial.print(F("Booting up (USB) V"));
Serial.print(VERSION_MAJOR + "." + VERSION_MINOR);

pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
digitalWrite(9, HIGH); //barometer fix for V2

#ifdef M0_PIO
uint8_t eepStatus = eep.begin(eep.twiClock100kHz);
#elif RP_PIO
EEPROM.begin(255);
#endif
refreshDeviceData();

Serial.print(F("revision "));
Serial.println(deviceData.revision);

loadHardwareConfig();
printDeviceData();

pinMode(board_config.led_sw, OUTPUT); // set up the internal LED2 pin
pixels.begin();
setLEDColor(led_color);
if(ENABLE_NEOPIXEL){
pixels.begin();
setLEDColor(led_color);
}

analogReadResolution(12); // M0 family chip provides 12bit resolution

pot->setAnalogResolution(4096);
unsigned int startup_vibes[] = { 27, 27, 0 };

Expand All @@ -231,25 +255,18 @@ void commonSetup() {

#ifdef M0_PIO
Watchdog.enable(5000);
uint8_t eepStatus = eep.begin(eep.twiClock100kHz);
#elif RP_PIO
watchdog_enable(4000, 1);
EEPROM.begin(255);
#endif
refreshDeviceData();

Serial.print(F("revision "));
Serial.println(deviceData.revision);

loadHardwareConfig();
setup140();
#ifdef M0_PIO
Watchdog.reset();
#endif
setLEDColor(LED_YELLOW);
setupAltimeter();
setupTelemetry();

setupDisplay(deviceData);
if (button_top->isPressedRaw()) {
modeSwitch(false);
}
Expand All @@ -274,11 +291,12 @@ void setupM0() {
void setupRP() {
#ifdef RP_PIO
watchdog_enable(5000, 1);
EEPROM.begin(512);

return;

if (deviceData.revision == M0) {
deviceData.revision = V1;
writeDeviceData();
//writeDeviceData();
}

if (deviceData.revision == MODULE) {
Expand All @@ -293,13 +311,10 @@ void setupRP() {
}

void setup() {
delay(1000); // delay for 1 sec
commonSetup();

if (deviceData.revision == M0) {
setupM0();
} else if (deviceData.revision == V1 || deviceData.revision == MODULE) {
setupRP();
}
setupRP();
}

void setupTelemetry() {
Expand Down Expand Up @@ -375,6 +390,8 @@ void setup140() {

// main loop - everything runs in threads
void loop() {


#ifdef M0_PIO
Watchdog.reset();
#endif
Expand Down
1 change: 0 additions & 1 deletion src/sp140/utilities.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ String convertToDigits(byte digits) {
return digits_string;
}

#define ENABLE_NEOPIXEL false // TODO make this a config option

// set LED color
void setLEDColor(uint32_t color) {
Expand Down

0 comments on commit d3f6a00

Please sign in to comment.