@@ -902,4 +902,106 @@ LogitechShifter::LogitechShifter(uint8_t pinX, uint8_t pinY, uint8_t pinRev, uin
902902 this ->setCalibration ({ 490 , 440 }, { 253 , 799 }, { 262 , 86 }, { 460 , 826 }, { 470 , 76 }, { 664 , 841 }, { 677 , 77 }, 0.70 , 0.50 , 0.70 );
903903}
904904
905+ // #########################################################
906+ // Handbrake #
907+ // #########################################################
908+
909+ Handbrake::Handbrake (uint8_t pinAx, uint8_t detectPin)
910+ : analogAxis(pinAx), detector(detectPin)
911+ {}
912+
913+ void Handbrake::begin () {
914+ update (); // set initial handbrake position
915+ }
916+
917+ bool Handbrake::update () {
918+ bool changed = false ;
919+
920+ detector.poll ();
921+ if (detector.getState () == DeviceConnection::Connected) {
922+ changed = analogAxis.read ();
923+ }
924+ else if (detector.getState () == DeviceConnection::Unplug) {
925+ analogAxis.setPosition (analogAxis.getMin ());
926+ }
927+
928+ return changed;
929+ }
930+
931+ long Handbrake::getPosition (long rMin, long rMax) const {
932+ return analogAxis.getPosition (rMin, rMax);
933+ }
934+
935+ int Handbrake::getPositionRaw () const {
936+ return analogAxis.getPositionRaw ();
937+ }
938+
939+ void Handbrake::setCalibration (AnalogInput::Calibration newCal) {
940+ analogAxis.setCalibration (newCal);
941+ analogAxis.setPosition (analogAxis.getMin ()); // reset to min
942+ }
943+
944+ void Handbrake::serialCalibration (Stream& iface) {
945+ if (isConnected () == false ) {
946+ iface.print (F (" Error! Cannot perform calibration, " ));
947+ iface.print (F (" handbrake" ));
948+ iface.println (F (" is not connected." ));
949+ return ;
950+ }
951+
952+ const char * separator = " ------------------------------------" ;
953+
954+ iface.println ();
955+ iface.println (F (" Sim Racing Library Handbrake Calibration" ));
956+ iface.println (separator);
957+ iface.println ();
958+
959+ AnalogInput::Calibration newCal;
960+
961+ // read minimum
962+ iface.println (F (" Keep your hand off of the handbrake to record its resting position" ));
963+ iface.println (F (" Send any character to continue." ));
964+ waitClient (iface);
965+
966+ analogAxis.read ();
967+ newCal.min = analogAxis.getPositionRaw ();
968+ iface.println ();
969+
970+ // read maximum
971+ iface.println (F (" Now pull on the handbrake and hold it at the end of its range" ));
972+ iface.println (F (" Send any character to continue." ));
973+ waitClient (iface);
974+
975+ analogAxis.read ();
976+ newCal.max = analogAxis.getPositionRaw ();
977+ iface.println ();
978+
979+ // set new calibration
980+ this ->setCalibration (newCal);
981+
982+ // print finished calibration
983+ iface.println (F (" Here is your calibration:" ));
984+ iface.println (separator);
985+ iface.println ();
986+
987+ iface.print (F (" handbrake.setCalibration(" ));
988+ iface.print (' {' );
989+ iface.print (newCal.min );
990+ iface.print (F (" , " ));
991+ iface.print (newCal.max );
992+ iface.print (" });" );
993+ iface.println ();
994+
995+ iface.println ();
996+ iface.println (separator);
997+ iface.println ();
998+
999+ iface.print (F (" Paste this line into the setup() function. The " ));
1000+ iface.print (F (" handbrake" ));
1001+ iface.print (F (" will be calibrated with these values on startup." ));
1002+ iface.println (F (" \n Calibration complete! :)\n\n " ));
1003+
1004+ flushClient (iface);
1005+ }
1006+
9051007}; // end SimRacing namespace
0 commit comments