diff --git a/src/sp140/extra-data.ino b/src/sp140/extra-data.ino index a3bf476..aff28bb 100644 --- a/src/sp140/extra-data.ino +++ b/src/sp140/extra-data.ino @@ -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 } @@ -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); diff --git a/src/sp140/sp140-helpers.ino b/src/sp140/sp140-helpers.ino index 7383d7a..abad4ec 100644 --- a/src/sp140/sp140-helpers.ino +++ b/src/sp140/sp140-helpers.ino @@ -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); @@ -102,11 +102,11 @@ 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 @@ -114,7 +114,7 @@ void handleSerialData(byte buffer[]) { 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; } @@ -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); @@ -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]; @@ -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 diff --git a/src/sp140/sp140.ino b/src/sp140/sp140.ino index ee826b4..5db55ed 100644 --- a/src/sp140/sp140.ino +++ b/src/sp140/sp140.ino @@ -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) { @@ -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) { @@ -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 @@ -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); @@ -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++) {