MeshPocket.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <MeshCore.h>
  4. // built-ins
  5. #define PIN_VBAT_READ 29
  6. #define PIN_BAT_CTL 34
  7. #define MV_LSB (3000.0F / 4096.0F) // 12-bit ADC with 3.0V input range
  8. class HeltecMeshPocket : public mesh::MainBoard {
  9. protected:
  10. uint8_t startup_reason;
  11. public:
  12. void begin();
  13. uint8_t getStartupReason() const override { return startup_reason; }
  14. uint16_t getBattMilliVolts() override {
  15. int adcvalue = 0;
  16. analogReadResolution(12);
  17. analogReference(AR_INTERNAL_3_0);
  18. pinMode(PIN_BAT_CTL, OUTPUT); // battery adc can be read only ctrl pin set to high
  19. pinMode(PIN_VBAT_READ, INPUT);
  20. digitalWrite(PIN_BAT_CTL, HIGH);
  21. delay(10);
  22. adcvalue = analogRead(PIN_VBAT_READ);
  23. digitalWrite(PIN_BAT_CTL, LOW);
  24. return (uint16_t)((float)adcvalue * MV_LSB * 4.9);
  25. }
  26. const char* getManufacturerName() const override {
  27. return "Heltec MeshPocket";
  28. }
  29. void reboot() override {
  30. NVIC_SystemReset();
  31. }
  32. bool startOTAUpdate(const char* id, char reply[]) override;
  33. };