* Added forward gear count to telemetry and use it to fix skewed gear display.
authorUrban Wallasch <urban.wallasch@freenet.de>
Sun, 28 Jul 2019 09:21:02 +0000 (11:21 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sun, 28 Jul 2019 09:21:02 +0000 (11:21 +0200)
dash.html
telehttpd.c
telelogger.c
telemetry.h
teleshmem.cpp

index d4049417fa04caa860ed34bbbd7767f6791e4baf..2f961c2820939ac87db0cac2b9a37c4bbfd225d2 100644 (file)
--- a/dash.html
+++ b/dash.html
@@ -126,9 +126,13 @@ x-bar {
 
 <script type="text/javascript">
 
-function dgear(x, m) {
-  if ( x > 0 ) return ( m ? '' : 'A' ) + x;
-  if ( x < 0 ) return 'R' + Math.abs(x);
+function dgear(x, f, m) {
+  // We try to deduce the correct forward gear number to display from
+  // the number of gears available. This likely just plain nonsense!
+  if ( x > 0 )
+    return ( m ? '' : 'A' ) + ( f>12 ? ( x<3 ? 'C'+x : x-2 ) : x );
+  if ( x < 0 )
+    return 'R' + -x;
   return 'N';
 }
 
@@ -203,7 +207,7 @@ function loadDoc() {
 
       cctrl.innerHTML = Math.round(tele.cctrl * 3.6);
 
-      gear.innerHTML = dgear(tele.gear_disp, tele.shifter);
+      gear.innerHTML = dgear(tele.gear_disp, tele.gear_fwdcnt, tele.shifter);
       if ( tele.clutch_eff > 0 )
         gear.classList.add("hilite");
       else
index 35d3b1591aad9cc6d3367bdbb4e308a7dc62a175..c465c1457f6a3a2cf1f76cf56edd1a4d74c5955c 100644 (file)
@@ -79,6 +79,7 @@ static void write_telejson( int fd ) {
     write(fd, buf, sprintf( buf, "  \"rpm\": %f,\n", telemetry->rpm ) );
     write(fd, buf, sprintf( buf, "  \"gear\": %d,\n", telemetry->gear ) );
     write(fd, buf, sprintf( buf, "  \"gear_disp\": %d,\n", telemetry->gear_disp ) );
+    write(fd, buf, sprintf( buf, "  \"gear_fwdcnt\": %u,\n", telemetry->gear_fwdcnt ) );
     write(fd, buf, sprintf( buf, "  \"clutch_eff\": %f,\n", telemetry->clutch_eff ) );
     write(fd, buf, sprintf( buf, "  \"shifter\": %d,\n", telemetry->shifter ) );
 
index 3bb66208fa2a5b39129eed0b4b1f19130d7f002b..164774241d6fd953a22c3def74bcd6b67167d2b4 100644 (file)
@@ -59,6 +59,7 @@ static int log_console(void) {
         printf( "rpm: %.0f /min\n", telemetry->rpm );
         printf( "gear: %d\n", telemetry->gear );
         printf( "gear d: %d\n", telemetry->gear_disp );
+        printf( "gear fwd cnt: %u\n", telemetry->gear_fwdcnt );
         printf( "clutch eff: %.1f\n", telemetry->clutch_eff );
         printf( "shifter: %s\n", telemetry->shifter ? "manual" : "automatic" );
 
index 6e8613c0fea16488954085b4b3118ab389fdf98b..e29db93db9066f17282f719b7e5a5ac40274a9d7 100644 (file)
@@ -31,6 +31,7 @@ struct telemetry_state_t {
     float   rpm;        // engine rpm
     int     gear;       // engine gear
     int     gear_disp;  // displayed gear
+    unsigned gear_fwdcnt; // gearbox number of forward gears
     float   clutch_eff; // effective clutch
     int     shifter;    // 0 = automatic, 1 = manual
 
index 6de9e4e7249e19b68044e501c311ba9a19117730..3be153dc26bd144bbd2725b05a4850e4e7b50e4c 100644 (file)
@@ -278,7 +278,14 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e
 {
     const struct scs_telemetry_configuration_t *const info = static_cast<const scs_telemetry_configuration_t *>(event_info);
 
-    if ( 0 == strcmp( info->id, SCS_TELEMETRY_CONFIG_controls ) ) {
+    if ( 0 == strcmp( info->id, SCS_TELEMETRY_CONFIG_truck ) ) {
+        for (const scs_named_value_t *current = info->attributes; current->name; ++current) {
+            if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_forward_gear_count ) ) {
+                telemetry->gear_fwdcnt = current->value.value_u32.value;
+            }
+        }
+    }
+    else if ( 0 == strcmp( info->id, SCS_TELEMETRY_CONFIG_controls ) ) {
         for (const scs_named_value_t *current = info->attributes; current->name; ++current) {
             if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_shifter_type ) ) {
                 // SCS_SHIFTER_TYPE_arcade