@@ -52,6 +52,7 @@ Configurer::Configurer(QString const &configFilePath)
5252 loadServoMotorTypes (root);
5353 loadAnalogSensorTypes (root);
5454 loadDigitalSensorTypes (root);
55+ loadEncoderTypes (root);
5556 loadSound (root);
5657
5758 mAccelerometer = loadSensor3d (root, " accelerometer" );
@@ -141,6 +142,11 @@ int Configurer::digitalSensorTypeMax(QString const &digitalSensorType) const
141142 return mDigitalSensorTypes [digitalSensorType].max ;
142143}
143144
145+ double Configurer::encoderTypeRawToDegrees (QString const &encoderType) const
146+ {
147+ return mEncoderTypes [encoderType].rawToDegrees ;
148+ }
149+
144150QStringList Configurer::servoMotorPorts () const
145151{
146152 return mServoMotorMappings .keys ();
@@ -226,6 +232,11 @@ int Configurer::encoderI2cCommandNumber(QString const &port) const
226232 return mEncoderMappings [port].i2cCommandNumber ;
227233}
228234
235+ QString Configurer::encoderDefaultType (QString const &port) const
236+ {
237+ return mEncoderMappings [port].defaultType ;
238+ }
239+
229240QStringList Configurer::digitalSensorPorts () const
230241{
231242 return mDigitalSensorMappings .keys ();
@@ -579,6 +590,7 @@ void Configurer::loadEncoders(QDomElement const &root)
579590 EncoderMapping mapping;
580591 mapping.port = childElement.attribute (" port" );
581592 mapping.i2cCommandNumber = childElement.attribute (" i2cCommandNumber" ).toInt (NULL , 0 );
593+ mapping.defaultType = childElement.attribute (" defaultType" );
582594
583595 mEncoderMappings .insert (mapping.port , mapping);
584596 }
@@ -700,6 +712,31 @@ void Configurer::loadDigitalSensorTypes(QDomElement const &root)
700712 }
701713}
702714
715+ void Configurer::loadEncoderTypes (const QDomElement &root)
716+ {
717+ if (root.elementsByTagName (" encoderTypes" ).isEmpty ()) {
718+ qDebug () << " config.xml does not have <encoderTypes> tag" ;
719+ throw " config.xml parsing failed" ;
720+ }
721+
722+ QDomElement const encoderTypes = root.elementsByTagName (" encoderTypes" ).at (0 ).toElement ();
723+ for (QDomNode child = encoderTypes.firstChild ()
724+ ; !child.isNull ()
725+ ; child = child.nextSibling ())
726+ {
727+ if (!child.isElement ()) {
728+ continue ;
729+ }
730+
731+ QDomElement const childElement = child.toElement ();
732+ QString const typeName = childElement.nodeName ();
733+
734+ EncoderType encoderType;
735+ encoderType.rawToDegrees = childElement.attribute (" rawToDegrees" ).toDouble ();
736+ mEncoderTypes .insert (typeName, encoderType);
737+ }
738+ }
739+
703740void Configurer::loadSound (QDomElement const &root)
704741{
705742 if (root.elementsByTagName (" playWavFile" ).isEmpty ()) {
0 commit comments