SenseCapSolarBoard.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <Arduino.h>
  4. #include <helpers/NRF52Board.h>
  5. class SenseCapSolarBoard : public NRF52BoardDCDC {
  6. protected:
  7. #ifdef NRF52_POWER_MANAGEMENT
  8. void initiateShutdown(uint8_t reason) override;
  9. #endif
  10. public:
  11. SenseCapSolarBoard() : NRF52Board("SENSECAP_SOLAR_OTA") {}
  12. void begin();
  13. #if defined(P_LORA_TX_LED)
  14. void onBeforeTransmit() override {
  15. digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
  16. }
  17. void onAfterTransmit() override {
  18. digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
  19. }
  20. #endif
  21. uint16_t getBattMilliVolts() override {
  22. digitalWrite(VBAT_ENABLE, LOW);
  23. int adcvalue = 0;
  24. analogReadResolution(12);
  25. analogReference(AR_INTERNAL_3_0);
  26. delay(10);
  27. adcvalue = analogRead(BATTERY_PIN);
  28. return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
  29. }
  30. const char* getManufacturerName() const override {
  31. return "Seeed SenseCap Solar";
  32. }
  33. void powerOff() override {
  34. digitalWrite(LED_GREEN, LOW);
  35. digitalWrite(LED_BLUE, LOW);
  36. #ifdef PIN_USER_BTN
  37. while (digitalRead(PIN_USER_BTN) == LOW);
  38. // Keep pull-up enabled in system-off so the wake line doesn't float low.
  39. nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_USER_BTN]), NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
  40. #elif defined(PIN_BUTTON1)
  41. while (digitalRead(PIN_BUTTON1) == LOW);
  42. // Keep pull-up enabled in system-off so the wake line doesn't float low.
  43. nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_BUTTON1]), NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
  44. #endif
  45. #ifdef NRF52_POWER_MANAGEMENT
  46. initiateShutdown(SHUTDOWN_REASON_USER);
  47. #else
  48. sd_power_system_off();
  49. #endif
  50. }
  51. };