@@ -216,6 +216,7 @@ byte short_writetime_counter = 0; //Counter for fast-loop
216216#endif
217217volatile unsigned long last_wheel_time = millis(); // last time of wheel sensor change 0->1
218218volatile unsigned long wheel_time = 65535 ; // time for one revolution of the wheel
219+ volatile byte wheel_counter=0 ; // counter for events that should happen once per wheel revolution. only needed if wheel_magnets>1
219220volatile unsigned long last_pas_event = millis(); // last change-time of PAS sensor status
220221#define pas_time 60000 /pas_magnets // conversion factor for pas_time to rpm (cadence)
221222volatile boolean pedaling = false ; // pedaling? (in forward direction!)
@@ -976,19 +977,22 @@ void speed_change() //Wheel Sensor Change------------------------------------
976977
977978 // Speed and Km
978979 if (last_wheel_time>(millis ()-50 )) return ; // debouncing reed-sensor
979- ++odo ;
980- wheel_time=millis ()-last_wheel_time;
980+ wheel_counter++ ;
981+ wheel_time=( millis ()-last_wheel_time)*wheel_magnets ;
981982 spd = (spd+3600 *wheel_circumference/wheel_time)/2 ; // a bit of averaging for smoother speed-cutoff
982- if (spd<100 )
983- {km=km+wheel_circumference/1000.0 ;}
984- else
985- {spd=0 ;}
983+
984+ if (wheel_counter>(wheel_magnets-1 )) // wheel has made one complete revolution
985+ {
986+ wheel_counter=0 ;
987+ km=km+wheel_circumference/1000.0 ;
988+ ++odo;
986989#if defined(SUPPORT_BMP085) || defined(SUPPORT_DSPC01)
987990// slope-stuff start-------------------------------
988- slope=0.98 *slope+2 *(altitude-last_altitude)/wheel_circumference;
989- last_altitude=altitude;
991+ slope=0.98 *slope+2 *(altitude-last_altitude)/wheel_circumference;
992+ last_altitude=altitude;
990993// slope-stuff end---------------------------------
991- #endif
994+ #endif
995+ }
992996 last_wheel_time=millis ();
993997}
994998
0 commit comments