ThinknodeM3Board.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <MeshCore.h>
  4. #include <helpers/NRF52Board.h>
  5. #define ADC_FACTOR ((1000.0*ADC_MULTIPLIER*AREF_VOLTAGE)/ADC_MAX)
  6. class ThinknodeM3Board : public Nrf52BoardDCDC {
  7. protected:
  8. uint8_t btn_prev_state;
  9. public:
  10. void begin();
  11. uint16_t getBattMilliVolts() override {
  12. int adcvalue = 0;
  13. analogReference(AR_INTERNAL_2_4);
  14. analogReadResolution(ADC_RESOLUTION);
  15. delay(10);
  16. // ADC range is 0..2400mV and resolution is 12-bit (0..4095)
  17. adcvalue = analogRead(PIN_VBAT_READ);
  18. // Convert the raw value to compensated mv, taking the resistor-
  19. // divider into account (providing the actual LIPO voltage)
  20. return (uint16_t)((float)adcvalue * ADC_FACTOR);
  21. }
  22. #if defined(P_LORA_TX_LED)
  23. #if !defined(P_LORA_TX_LED_ON)
  24. #define P_LORA_TX_LED_ON HIGH
  25. #endif
  26. void onBeforeTransmit() override {
  27. digitalWrite(P_LORA_TX_LED, P_LORA_TX_LED_ON); // turn TX LED on
  28. }
  29. void onAfterTransmit() override {
  30. digitalWrite(P_LORA_TX_LED, !P_LORA_TX_LED_ON); // turn TX LED off
  31. }
  32. #endif
  33. const char* getManufacturerName() const override {
  34. return "Elecrow ThinkNode M3";
  35. }
  36. int buttonStateChanged() {
  37. #ifdef BUTTON_PIN
  38. uint8_t v = digitalRead(BUTTON_PIN);
  39. if (v != btn_prev_state) {
  40. btn_prev_state = v;
  41. return (v == LOW) ? 1 : -1;
  42. }
  43. #endif
  44. return 0;
  45. }
  46. void powerOff() override { sd_power_system_off(); }
  47. };