Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwhitehead committed Feb 27, 2024
1 parent 3cd7ffc commit af42ada
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/sp140/extra-data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void updateRevisionIfRequired() {
#ifdef RP_PIO
if (deviceData.revision == 0) {
deviceData.revision = 1;
writeDeviceData(); // Save the updated revision to EEPROM
writeDeviceData(); // Save the updated revision to EEPROM
}
#endif
}
Expand Down Expand Up @@ -135,7 +135,7 @@ void parse_usb_serial() {
sanitizeDeviceData();
writeDeviceData();
resetRotation(deviceData.screen_rotation); // Screen orientation may have changed
setTheme(deviceData.theme); // may have changed
setTheme(deviceData.theme); // may have changed

vTaskResume(updateDisplayTaskHandle);

Expand Down
43 changes: 21 additions & 22 deletions src/sp140/sp140-helpers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ void handleSerialData(byte buffer[]) {
raw_telemdata.V_LO = buffer[0];

float voltage = (raw_telemdata.V_HI << 8 | raw_telemdata.V_LO) / 100.0;
telemetryData.volts = voltage; //Voltage
telemetryData.volts = voltage; // Voltage

if (telemetryData.volts > BATT_MIN_V) {
telemetryData.volts += 1.0; // calibration
telemetryData.volts += 1.0; // calibration
}

voltageBuffer.push(telemetryData.volts);
Expand All @@ -102,19 +102,19 @@ void handleSerialData(byte buffer[]) {
Rntc = SERIESRESISTOR / Rntc;

// Get the temperature
float temperature = Rntc / (float) NOMINAL_RESISTANCE; // (R/Ro)
float temperature = Rntc / (float) NOMINAL_RESISTANCE; // (R/Ro)
temperature = (float) log(temperature); // ln(R/Ro)
temperature /= BCOEFFICIENT; // 1/B * ln(R/Ro)

temperature += 1.0 / ((float) NOMINAL_TEMPERATURE + 273.15); // + (1/To)
temperature += 1.0 / ((float) NOMINAL_TEMPERATURE + 273.15); // + (1/To)
temperature = 1.0 / temperature; // Invert
temperature -= 273.15; // convert to Celsius

// filter bad values
if (temperature < 0 || temperature > 200) {
telemetryData.temperatureC = __FLT_MIN__;
} else {
temperature = (float) trunc(temperature * 100) / 100; // 2 decimal places
temperature = (float) trunc(temperature * 100) / 100; // 2 decimal places
telemetryData.temperatureC = temperature;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ void handleSerialData(byte buffer[]) {
raw_telemdata.DUTYIN_LO = buffer[12];

int throttleDuty = (int)(((raw_telemdata.DUTYIN_HI << 8) + raw_telemdata.DUTYIN_LO) / 10);
telemetryData.inPWM = (throttleDuty / 10); //Input throttle
telemetryData.inPWM = (throttleDuty / 10); // Input throttle

// Serial.print("throttle ");
// Serial.print(telemetryData.inPWM);
Expand All @@ -163,7 +163,7 @@ void handleSerialData(byte buffer[]) {
raw_telemdata.MOTORDUTY_LO = buffer[14];

int motorDuty = (int)(((raw_telemdata.MOTORDUTY_HI << 8) + raw_telemdata.MOTORDUTY_LO) / 10);
int currentMotorDuty = (motorDuty / 10); //Motor duty cycle
int currentMotorDuty = (motorDuty / 10); // Motor duty cycle

// Reserved
// raw_telemdata.R1 = buffer[17];
Expand All @@ -184,22 +184,21 @@ void handleSerialData(byte buffer[]) {
// Serial.println(" ");
}

// new v2
// new V2
int CheckFlectcher16(byte byteBuffer[]) {
int fCCRC16;
int i;
int c0 = 0;
int c1 = 0;

// Calculate checksum intermediate bytesUInt16
for (i = 0; i < 18; i++) //Check only first 18 bytes, skip crc bytes
{
c0 = (int)(c0 + ((int)byteBuffer[i])) % 255;
c1 = (int)(c1 + c0) % 255;
}
// Assemble the 16-bit checksum value
fCCRC16 = ( c1 << 8 ) | c0;
return (int)fCCRC16;
int fCCRC16;
int i;
int c0 = 0;
int c1 = 0;

// Calculate checksum intermediate bytesUInt16
for (i = 0; i < 18; i++) { //Check only first 18 bytes, skip crc bytes
c0 = (int)(c0 + ((int)byteBuffer[i])) % 255;
c1 = (int)(c1 + c0) % 255;
}
// Assemble the 16-bit checksum value
fCCRC16 = ( c1 << 8 ) | c0;
return (int)fCCRC16;
}

// for debugging
Expand Down
13 changes: 6 additions & 7 deletions src/sp140/sp140.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void telemetryTask(void *pvParameters) {
handleTelemetry();
delay(50); // wait for 50ms
}
vTaskDelete(NULL); // should never reach this
vTaskDelete(NULL); // should never reach this
}

void trackPowerTask(void *pvParameters) {
Expand All @@ -123,7 +123,7 @@ void trackPowerTask(void *pvParameters) {
trackPower();
delay(250); // wait for 250ms
}
vTaskDelete(NULL); // should never reach this
vTaskDelete(NULL); // should never reach this
}

void checkButtonTask(void *pvParameters) {
Expand All @@ -133,7 +133,7 @@ void checkButtonTask(void *pvParameters) {
checkButtons();
delay(5); // wait for 5ms
}
vTaskDelete(NULL); // should never reach this
vTaskDelete(NULL); // should never reach this
}

void updateDisplayTask(void *pvParameters) { //TODO set core affinity to one core only
Expand All @@ -143,15 +143,14 @@ void updateDisplayTask(void *pvParameters) { //TODO set core affinity to one cor
// TODO separate alt reading out to its own task. Avoid blocking display updates when alt reading is slow etc
// TODO use queues to pass data between tasks (xQueueOverwrite)
const float altitude = getAltitude(deviceData);
updateDisplay( deviceData, telemetryData, altitude, armed, cruising, armedAtMillis);
updateDisplay(deviceData, telemetryData, altitude, armed, cruising, armedAtMillis);
delay(250); // wait for 250ms
}
vTaskDelete(NULL); // should never reach this
vTaskDelete(NULL); // should never reach this
}

// the setup function runs once when you press reset or power the board
void setup() {

Serial.begin(115200);
SerialESC.begin(ESC_BAUD_RATE);
SerialESC.setTimeout(ESC_TIMEOUT);
Expand Down Expand Up @@ -242,7 +241,7 @@ void ps() {
int tasks = uxTaskGetNumberOfTasks();
TaskStatus_t *pxTaskStatusArray = new TaskStatus_t[tasks];
unsigned long runtime;
tasks = uxTaskGetSystemState( pxTaskStatusArray, tasks, &runtime );
tasks = uxTaskGetSystemState(pxTaskStatusArray, tasks, &runtime);
Serial.printf("# Tasks: %d\n", tasks);
Serial.println("ID, NAME, STATE, PRIO, CYCLES");
for (int i=0; i < tasks; i++) {
Expand Down

0 comments on commit af42ada

Please sign in to comment.