diff --git a/libraries/SITL/SIM_BattMonitor_SMBus.cpp b/libraries/SITL/SIM_BattMonitor_SMBus.cpp index 4d827335b2..3e31f57167 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus.cpp +++ b/libraries/SITL/SIM_BattMonitor_SMBus.cpp @@ -16,7 +16,7 @@ SITL::SIM_BattMonitor_SMBus::SIM_BattMonitor_SMBus() : add_register("Manufacture Name", SMBusBattDevReg::MANUFACTURE_NAME, O_RDONLY); add_register("Manufacture Data", SMBusBattDevReg::MANUFACTURE_DATA, O_RDONLY); - set_register(SMBusBattDevReg::TEMP, (int16_t)(15 + 273.15)); + set_register(SMBusBattDevReg::TEMP, (int16_t)((15 + 273.15)*10)); // see update for voltage // see update for current // TODO: remaining capacity diff --git a/libraries/SITL/SIM_BattMonitor_SMBus.h b/libraries/SITL/SIM_BattMonitor_SMBus.h index f4eb89ec28..22a5ae54c6 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus.h +++ b/libraries/SITL/SIM_BattMonitor_SMBus.h @@ -1,5 +1,7 @@ #include "SIM_I2CDevice.h" +#pragma once + namespace SITL { class SMBusBattDevReg : public I2CRegEnum { diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Generic.h b/libraries/SITL/SIM_BattMonitor_SMBus_Generic.h index aecd12a885..e24ae5466d 100644 --- a/libraries/SITL/SIM_BattMonitor_SMBus_Generic.h +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Generic.h @@ -1,5 +1,7 @@ #include "SIM_BattMonitor_SMBus.h" +#pragma once + namespace SITL { class SMBusBattGenericDevReg : public SMBusBattDevReg { diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp new file mode 100644 index 0000000000..c4e9d85d08 --- /dev/null +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.cpp @@ -0,0 +1,20 @@ +#include "SIM_BattMonitor_SMBus_Rotoye.h" + +SITL::Rotoye::Rotoye() : + SIM_BattMonitor_SMBus_Generic() +{ + add_register("External Temperature", SMBusBattRotoyeDevReg::TEMP_EXT, O_RDONLY); + + set_register(SMBusBattRotoyeDevReg::SERIAL, (uint16_t)39); +} + +void SITL::Rotoye::update(const class Aircraft &aircraft) +{ + SIM_BattMonitor_SMBus_Generic::update(aircraft); + + const uint32_t now = AP_HAL::millis(); + if (now - last_temperature_update_ms > 1000) { + last_temperature_update_ms = now; + set_register(SMBusBattRotoyeDevReg::TEMP_EXT, int16_t(be16toh(word[SMBusBattRotoyeDevReg::TEMP]) + 100)); // it's a little warmer inside.... (10 degrees here) + } +} diff --git a/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h new file mode 100644 index 0000000000..853472b430 --- /dev/null +++ b/libraries/SITL/SIM_BattMonitor_SMBus_Rotoye.h @@ -0,0 +1,35 @@ +#include "SIM_BattMonitor_SMBus_Generic.h" + +#include + +/* + +Testing: + +param set BATT_MONITOR 19 +reboot + +*/ + +namespace SITL { + +class SMBusBattRotoyeDevReg : public SMBusBattGenericDevReg { +public: + static const uint8_t TEMP_EXT = 0x07; +}; + +class Rotoye : public SIM_BattMonitor_SMBus_Generic +{ +public: + + Rotoye(); + + uint8_t cellcount() const override { return 3; } + + void update(const class Aircraft &aircraft) override; + +private: + uint32_t last_temperature_update_ms; +}; + +} // namespace SITL diff --git a/libraries/SITL/SIM_I2C.cpp b/libraries/SITL/SIM_I2C.cpp index 5068ae521a..fe22ea396c 100644 --- a/libraries/SITL/SIM_I2C.cpp +++ b/libraries/SITL/SIM_I2C.cpp @@ -24,6 +24,7 @@ #include "SIM_ToshibaLED.h" #include "SIM_MaxSonarI2CXL.h" #include "SIM_BattMonitor_SMBus_Maxell.h" +#include "SIM_BattMonitor_SMBus_Rotoye.h" #include @@ -45,6 +46,7 @@ static IgnoredI2CDevice ignored; static ToshibaLED toshibaled; static MaxSonarI2CXL maxsonari2cxl; static Maxell maxell; +static Rotoye rotoye; struct i2c_device_at_address { uint8_t bus; @@ -57,7 +59,7 @@ struct i2c_device_at_address { { 1, 0x40, ignored }, // KellerLD { 1, 0x70, maxsonari2cxl }, { 1, 0x76, ignored }, // MS56XX - { 2, 0x0B, maxell }, + { 2, 0x0B, rotoye }, }; void I2C::init()