AP_BattMonitor_FuelLevel_PWM.h 967 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include "AP_BattMonitor.h"
  3. #include "AP_BattMonitor_Backend.h"
  4. class AP_BattMonitor_FuelLevel_PWM : public AP_BattMonitor_Backend
  5. {
  6. public:
  7. /// Constructor
  8. AP_BattMonitor_FuelLevel_PWM(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params &params);
  9. /// Read the battery voltage and current. Should be called at 10hz
  10. void read() override;
  11. /// returns true if battery monitor provides consumed energy info
  12. bool has_consumed_energy() const override { return true; }
  13. /// returns true if battery monitor provides current info
  14. bool has_current() const override { return true; }
  15. void init(void) override {}
  16. private:
  17. void irq_handler(uint8_t pin, bool pin_state, uint32_t timestamp);
  18. struct IrqState {
  19. uint32_t last_pulse_us;
  20. uint32_t pulse_width_us;
  21. uint32_t pulse_count1;
  22. } irq_state;
  23. int8_t last_pin = -1;
  24. uint32_t pulse_count2;
  25. };