Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: akmanalogsensor.cpp
- Revision:
- 37:c76d2edf3426
- Parent:
- 29:b488d2c89fba
- Child:
- 40:42e48427e4b7
--- a/akmanalogsensor.cpp Fri May 19 23:13:23 2017 +0000 +++ b/akmanalogsensor.cpp Wed May 24 20:23:22 2017 +0000 @@ -25,51 +25,49 @@ primaryId = id; subId = subid; - if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ430L) sensorName = "EQ-430L"; - else if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ431L) sensorName = "EQ-431L"; - else if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ432L) sensorName = "EQ-432L"; - else if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ433L) sensorName = "EQ-433L"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ3300) sensorName = "CQ-3300"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ3301) sensorName = "CQ-3301"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ3302) sensorName = "CQ-3302"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ3303) sensorName = "CQ-3303"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ330A) sensorName = "CQ-330A"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ330B) sensorName = "CQ-330B"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ330E) sensorName = "CQ-330E"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ330F) sensorName = "CQ-330F"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ330G) sensorName = "CQ-330G"; - else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR && subId == AkmAnalogSensor::SUB_ID_CQ330H) sensorName = "CQ-330H"; - else if(primaryId == AKM_PRIMARY_ID_MISC_ANALOG && subId == AkmAnalogSensor::SUB_ID_EM3242) sensorName = "EM3242"; - else if(primaryId == AKM_PRIMARY_ID_MISC_ANALOG && subId == AkmAnalogSensor::SUB_ID_AK9710) sensorName = "AK9710"; + if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ430L) sensorName = "EQ-430L"; + else if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ431L) sensorName = "EQ-431L"; + else if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ432L) sensorName = "EQ-432L"; + else if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR && subId == AkmAnalogSensor::SUB_ID_EQ433L) sensorName = "EQ-433L"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ3200) sensorName = "CQ-3200"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ3201) sensorName = "CQ-3201"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ3202) sensorName = "CQ-3202"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ3203) sensorName = "CQ-3203"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ3204) sensorName = "CQ-3204"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ320A) sensorName = "CQ-320A"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V && subId == AkmAnalogSensor::SUB_ID_CQ320B) sensorName = "CQ-320B"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ3300) sensorName = "CQ-3300"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ3301) sensorName = "CQ-3301"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ3302) sensorName = "CQ-3302"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ3303) sensorName = "CQ-3303"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330A) sensorName = "CQ-330A"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330B) sensorName = "CQ-330B"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330E) sensorName = "CQ-330E"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330F) sensorName = "CQ-330F"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330G) sensorName = "CQ-330G"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330H) sensorName = "CQ-330H"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CQ330J) sensorName = "CQ-330J"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CZ3813) sensorName = "CZ-3813"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CZ3814) sensorName = "CZ-3814"; + else if(primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V && subId == AkmAnalogSensor::SUB_ID_CZ3815) sensorName = "CZ-3815"; + else if(primaryId == AKM_PRIMARY_ID_MISC_ANALOG && subId == AkmAnalogSensor::SUB_ID_EM3242) sensorName = "EM3242"; + else if(primaryId == AKM_PRIMARY_ID_MISC_ANALOG && subId == AkmAnalogSensor::SUB_ID_AK9710) sensorName = "AK9710"; + else return AkmSensor::ERROR; + + MCP342X::AdcChannel channel = MCP342X::ADC_CH3; // 0-5.0V out as default + if( (primaryId == AKM_PRIMARY_ID_MISC_ANALOG) && (subId < 0x08) || primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V){ + channel = MCP342X::ADC_CH4; // 0-3.0V out + } -// if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR_LEGACY){ -// // Internal ADC, Legacy -// ain = new AnalogIn(ANALOG_IN_PIN); -// sensorName = "EQ43XL"; -// } - if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR || - primaryId == AKM_PRIMARY_ID_MISC_ANALOG || - primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR) - { - MCP342X::AdcChannel channel = MCP342X::ADC_CH3; // 0-5.0V out as default - - if( (primaryId == AKM_PRIMARY_ID_MISC_ANALOG) && (subId < 0x08) ){ - channel = MCP342X::ADC_CH4; // 0-3.0V out - } - - // 16bit ADC - I2C* i2c = new I2C(I2C_SDA,I2C_SCL); - i2c->frequency(I2C_SPEED_100KHZ); - - // ADC setting - mcp3428 = new MCP342X(i2c, MCP342X::SLAVE_ADDRESS_6EH); - mcp3428->setChannel(channel); - mcp3428->setSampleSetting(MCP342X::SAMPLE_15HZ_16BIT); - mcp3428->setConversionMode(MCP342X::CONTINUOUS); - } - else{ - return AkmSensor::ERROR; - } + // 16bit ADC + I2C* i2c = new I2C(I2C_SDA,I2C_SCL); + i2c->frequency(I2C_SPEED_100KHZ); + + // ADC setting + mcp3428 = new MCP342X(i2c, MCP342X::SLAVE_ADDRESS_6EH); + mcp3428->setChannel(channel); + mcp3428->setSampleSetting(MCP342X::SAMPLE_15HZ_16BIT); + mcp3428->setConversionMode(MCP342X::CONTINUOUS); interval = SENSOR_SAMPLING_RATE; // 10Hz @@ -100,7 +98,8 @@ if(primaryId == AKM_PRIMARY_ID_LINEAR_SENSOR || primaryId == AKM_PRIMARY_ID_MISC_ANALOG || - primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR){ + primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_3V || + primaryId == AKM_PRIMARY_ID_CURRENT_SENSOR_5V ){ MCP342X::Data data; do { mcp3428->getData(&data);