ThinkNodeM1Board.cpp 843 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include "ThinkNodeM1Board.h"
  4. #ifdef THINKNODE_M1
  5. void ThinkNodeM1Board::begin() {
  6. NRF52Board::begin();
  7. Wire.begin();
  8. #ifdef P_LORA_TX_LED
  9. pinMode(P_LORA_TX_LED, OUTPUT);
  10. digitalWrite(P_LORA_TX_LED, LOW);
  11. #endif
  12. pinMode(SX126X_POWER_EN, OUTPUT);
  13. digitalWrite(SX126X_POWER_EN, HIGH);
  14. delay(10); // give sx1262 some time to power up
  15. }
  16. uint16_t ThinkNodeM1Board::getBattMilliVolts() {
  17. int adcvalue = 0;
  18. analogReference(AR_INTERNAL_3_0);
  19. analogReadResolution(12);
  20. delay(10);
  21. // ADC range is 0..3000mV and resolution is 12-bit (0..4095)
  22. adcvalue = analogRead(PIN_VBAT_READ);
  23. // Convert the raw value to compensated mv, taking the resistor-
  24. // divider into account (providing the actual LIPO voltage)
  25. return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
  26. }
  27. #endif