MeshtinyBoard.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <MeshCore.h>
  4. #include <helpers/NRF52Board.h>
  5. class MeshtinyBoard : public NRF52BoardDCDC {
  6. protected:
  7. uint8_t btn_prev_state;
  8. public:
  9. MeshtinyBoard() : NRF52Board("Meshtiny OTA") {}
  10. void begin();
  11. #if defined(P_LORA_TX_LED)
  12. void onBeforeTransmit() override {
  13. digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
  14. }
  15. void onAfterTransmit() override {
  16. digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
  17. }
  18. #endif
  19. uint16_t getBattMilliVolts() override {
  20. int adcvalue = 0;
  21. analogReadResolution(12);
  22. analogReference(AR_INTERNAL_3_0);
  23. delay(10);
  24. adcvalue = analogRead(PIN_VBAT_READ);
  25. return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
  26. }
  27. const char *getManufacturerName() const override { return "Meshtiny"; }
  28. void reboot() override { NVIC_SystemReset(); }
  29. void powerOff() override {
  30. #ifdef PIN_USER_BTN
  31. while (digitalRead(PIN_USER_BTN) == LOW) {
  32. delay(10);
  33. }
  34. #endif
  35. #ifdef PIN_3V3_EN
  36. pinMode(PIN_3V3_EN, OUTPUT);
  37. digitalWrite(PIN_3V3_EN, LOW);
  38. #endif
  39. #ifdef PIN_LED1
  40. digitalWrite(PIN_LED1, LOW);
  41. #endif
  42. #ifdef PIN_LED2
  43. digitalWrite(PIN_LED2, LOW);
  44. #endif
  45. #ifdef PIN_USER_BTN
  46. nrf_gpio_cfg_sense_input(g_ADigitalPinMap[PIN_USER_BTN], NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
  47. #endif
  48. sd_power_system_off();
  49. }
  50. };