SQ9MDD / TTGO-T-Beam-LoRa-APRS

Use TTGO T-Beam as LoRa APRS Tracker
64 stars 23 forks source link

Make compiler happy #91

Closed dl9sau closed 2 years ago

dl9sau commented 2 years ago

Compiler warns about incompatible type in sprintf, for Tcall and LoRa speed

@@ -551,7 +588,7 @@ String prepareCallsign(const String& callsign){
         uint8_t ac_c = (axp.getVbusCurrent()) / 10;
         // Pad telemetry message address to 9 characters
         char Tcall_message_char[9];
-        sprintf_P(Tcall_message_char, "%-9s", Tcall);
+        sprintf_P(Tcall_message_char, "%-9s", Tcall.c_str());
         String Tcall_message = String(Tcall_message_char);
         // Flash the light when telemetry is being sent
         #ifdef ENABLE_LED_SIGNALING
@@ -958,7 +995,7 @@ void setup(){
     rf95.setModemConfig(BG_RF95::Bw125Cr45Sf4096);
   }

-  Serial.printf("LoRa Speed:\t%d\n", lora_speed);
+  Serial.printf("LoRa Speed:\t%lu\n", lora_speed);

   rf95.setFrequency(lora_freq);
   Serial.printf("LoRa FREQ:\t%f\n", lora_freq);

Discussion: I had problems with sb_min_speed. Web-Interface said it was 3. My debug printf said it was 0. I re-entered -> no effect. I tried to change float sb_min_speed = 3; -> it worked. I tried to change to 0.0, it kept fixed. I returned to 0 -> still worked. Hmmm.

Anyway, perhaps it's a good idea to cast float to int and int to float while setting / reading preferences. This does not fixed above described problem, but I think it makes things cleaner.

@@ -782,15 +819,15 @@ void setup(){

     if (!preferences.getBool(PREF_APRS_SB_MIN_SPEED_PRESET_INIT)){
       preferences.putBool(PREF_APRS_SB_MIN_SPEED_PRESET_INIT, true);
-      preferences.putInt(PREF_APRS_SB_MIN_SPEED_PRESET, sb_min_speed);
+      preferences.putInt(PREF_APRS_SB_MIN_SPEED_PRESET, (int ) sb_min_speed);
     }
-    sb_min_speed = preferences.getInt(PREF_APRS_SB_MIN_SPEED_PRESET);
+    sb_min_speed = (float) preferences.getInt(PREF_APRS_SB_MIN_SPEED_PRESET);

     if (!preferences.getBool(PREF_APRS_SB_MAX_SPEED_PRESET_INIT)){
       preferences.putBool(PREF_APRS_SB_MAX_SPEED_PRESET_INIT, true);
-      preferences.putInt(PREF_APRS_SB_MAX_SPEED_PRESET, sb_max_speed);
+      preferences.putInt(PREF_APRS_SB_MAX_SPEED_PRESET, (int ) sb_max_speed);
     }
-    sb_max_speed = preferences.getInt(PREF_APRS_SB_MAX_SPEED_PRESET);
+    sb_max_speed = (float) preferences.getInt(PREF_APRS_SB_MAX_SPEED_PRESET);

     if (!preferences.getBool(PREF_APRS_SB_ANGLE_PRESET_INIT)){
       preferences.putBool(PREF_APRS_SB_ANGLE_PRESET_INIT, true);
dl9sau commented 2 years ago

Feature is stable in my development version