Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

557 lines
17 KiB

6 years ago
6 years ago
6 years ago
  1. /*
  2. UTILS MODULE
  3. Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #include <Ticker.h>
  6. Ticker _defer_reset;
  7. String getIdentifier() {
  8. char buffer[20];
  9. snprintf_P(buffer, sizeof(buffer), PSTR("%s_%06X"), APP_NAME, ESP.getChipId());
  10. return String(buffer);
  11. }
  12. void setDefaultHostname() {
  13. if (strlen(HOSTNAME) > 0) {
  14. setSetting("hostname", HOSTNAME);
  15. } else {
  16. setSetting("hostname", getIdentifier());
  17. }
  18. }
  19. void setBoardName() {
  20. #ifndef ESPURNA_CORE
  21. setSetting("boardName", DEVICE_NAME);
  22. #endif
  23. }
  24. String getBoardName() {
  25. return getSetting("boardName", DEVICE_NAME);
  26. }
  27. String getCoreVersion() {
  28. String version = ESP.getCoreVersion();
  29. #ifdef ARDUINO_ESP8266_RELEASE
  30. if (version.equals("00000000")) {
  31. version = String(ARDUINO_ESP8266_RELEASE);
  32. }
  33. #endif
  34. version.replace("_", ".");
  35. return version;
  36. }
  37. String getCoreRevision() {
  38. #ifdef ARDUINO_ESP8266_GIT_VER
  39. return String(ARDUINO_ESP8266_GIT_VER);
  40. #else
  41. return String("");
  42. #endif
  43. }
  44. unsigned long maxSketchSpace() {
  45. return (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
  46. }
  47. // WTF
  48. // Calling ESP.getFreeHeap() is making the system crash on a specific
  49. // AiLight bulb, but anywhere else...
  50. unsigned int getFreeHeap() {
  51. if (getSetting("wtfHeap", 0).toInt() == 1) return 9999;
  52. return ESP.getFreeHeap();
  53. }
  54. String buildTime() {
  55. const char time_now[] = __TIME__; // hh:mm:ss
  56. unsigned int hour = atoi(&time_now[0]);
  57. unsigned int minute = atoi(&time_now[3]);
  58. unsigned int second = atoi(&time_now[6]);
  59. const char date_now[] = __DATE__; // Mmm dd yyyy
  60. const char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  61. unsigned int month = 0;
  62. for ( int i = 0; i < 12; i++ ) {
  63. if (strncmp(date_now, months[i], 3) == 0 ) {
  64. month = i + 1;
  65. break;
  66. }
  67. }
  68. unsigned int day = atoi(&date_now[3]);
  69. unsigned int year = atoi(&date_now[7]);
  70. char buffer[20];
  71. snprintf_P(
  72. buffer, sizeof(buffer), PSTR("%04d-%02d-%02d %02d:%02d:%02d"),
  73. year, month, day, hour, minute, second
  74. );
  75. return String(buffer);
  76. }
  77. unsigned long getUptime() {
  78. static unsigned long last_uptime = 0;
  79. static unsigned char uptime_overflows = 0;
  80. if (millis() < last_uptime) ++uptime_overflows;
  81. last_uptime = millis();
  82. unsigned long uptime_seconds = uptime_overflows * (UPTIME_OVERFLOW / 1000) + (last_uptime / 1000);
  83. return uptime_seconds;
  84. }
  85. #if HEARTBEAT_ENABLED
  86. void heartbeat() {
  87. unsigned long uptime_seconds = getUptime();
  88. unsigned int free_heap = getFreeHeap();
  89. #if MQTT_SUPPORT
  90. bool serial = !mqttConnected();
  91. #else
  92. bool serial = true;
  93. #endif
  94. // -------------------------------------------------------------------------
  95. // Serial
  96. // -------------------------------------------------------------------------
  97. if (serial) {
  98. DEBUG_MSG_P(PSTR("[MAIN] Uptime: %lu seconds\n"), uptime_seconds);
  99. DEBUG_MSG_P(PSTR("[MAIN] Free heap: %lu bytes\n"), free_heap);
  100. #if ADC_MODE_VALUE == ADC_VCC
  101. DEBUG_MSG_P(PSTR("[MAIN] Power: %lu mV\n"), ESP.getVcc());
  102. #endif
  103. #if NTP_SUPPORT
  104. if (ntpSynced()) DEBUG_MSG_P(PSTR("[MAIN] Time: %s\n"), (char *) ntpDateTime().c_str());
  105. #endif
  106. }
  107. // -------------------------------------------------------------------------
  108. // MQTT
  109. // -------------------------------------------------------------------------
  110. #if MQTT_SUPPORT
  111. if (!serial) {
  112. #if (HEARTBEAT_REPORT_INTERVAL)
  113. mqttSend(MQTT_TOPIC_INTERVAL, HEARTBEAT_INTERVAL / 1000);
  114. #endif
  115. #if (HEARTBEAT_REPORT_APP)
  116. mqttSend(MQTT_TOPIC_APP, APP_NAME);
  117. #endif
  118. #if (HEARTBEAT_REPORT_VERSION)
  119. mqttSend(MQTT_TOPIC_VERSION, APP_VERSION);
  120. #endif
  121. #if (HEARTBEAT_REPORT_BOARD)
  122. mqttSend(MQTT_TOPIC_BOARD, getBoardName().c_str());
  123. #endif
  124. #if (HEARTBEAT_REPORT_HOSTNAME)
  125. mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str());
  126. #endif
  127. #if (HEARTBEAT_REPORT_IP)
  128. mqttSend(MQTT_TOPIC_IP, getIP().c_str());
  129. #endif
  130. #if (HEARTBEAT_REPORT_MAC)
  131. mqttSend(MQTT_TOPIC_MAC, WiFi.macAddress().c_str());
  132. #endif
  133. #if (HEARTBEAT_REPORT_RSSI)
  134. mqttSend(MQTT_TOPIC_RSSI, String(WiFi.RSSI()).c_str());
  135. #endif
  136. #if (HEARTBEAT_REPORT_UPTIME)
  137. mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
  138. #endif
  139. #if (HEARTBEAT_REPORT_DATETIME) && (NTP_SUPPORT)
  140. if (ntpSynced()) mqttSend(MQTT_TOPIC_DATETIME, ntpDateTime().c_str());
  141. #endif
  142. #if (HEARTBEAT_REPORT_FREEHEAP)
  143. mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
  144. #endif
  145. #if (HEARTBEAT_REPORT_RELAY)
  146. relayMQTT();
  147. #endif
  148. #if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) & (HEARTBEAT_REPORT_LIGHT)
  149. lightMQTT();
  150. #endif
  151. #if (HEARTBEAT_REPORT_VCC)
  152. #if ADC_MODE_VALUE == ADC_VCC
  153. mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str());
  154. #endif
  155. #endif
  156. #if (HEARTBEAT_REPORT_STATUS)
  157. mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true);
  158. #endif
  159. #if (LOADAVG_REPORT)
  160. mqttSend(MQTT_TOPIC_LOADAVG, String(systemLoadAverage()).c_str());
  161. #endif
  162. }
  163. #endif
  164. // -------------------------------------------------------------------------
  165. // InfluxDB
  166. // -------------------------------------------------------------------------
  167. #if INFLUXDB_SUPPORT
  168. #if (HEARTBEAT_REPORT_UPTIME)
  169. idbSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str());
  170. #endif
  171. #if (HEARTBEAT_REPORT_FREEHEAP)
  172. idbSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str());
  173. #endif
  174. #endif
  175. }
  176. #endif /// HEARTBEAT_ENABLED
  177. unsigned int sectors(size_t size) {
  178. return (int) (size + SPI_FLASH_SEC_SIZE - 1) / SPI_FLASH_SEC_SIZE;
  179. }
  180. void info() {
  181. DEBUG_MSG_P(PSTR("\n\n"));
  182. DEBUG_MSG_P(PSTR("[INIT] %s %s\n"), (char *) APP_NAME, (char *) APP_VERSION);
  183. DEBUG_MSG_P(PSTR("[INIT] %s\n"), (char *) APP_AUTHOR);
  184. DEBUG_MSG_P(PSTR("[INIT] %s\n\n"), (char *) APP_WEBSITE);
  185. DEBUG_MSG_P(PSTR("[INIT] CPU chip ID: 0x%06X\n"), ESP.getChipId());
  186. DEBUG_MSG_P(PSTR("[INIT] CPU frequency: %u MHz\n"), ESP.getCpuFreqMHz());
  187. DEBUG_MSG_P(PSTR("[INIT] SDK version: %s\n"), ESP.getSdkVersion());
  188. DEBUG_MSG_P(PSTR("[INIT] Core version: %s\n"), getCoreVersion().c_str());
  189. DEBUG_MSG_P(PSTR("[INIT] Core revision: %s\n"), getCoreRevision().c_str());
  190. DEBUG_MSG_P(PSTR("\n"));
  191. // -------------------------------------------------------------------------
  192. FlashMode_t mode = ESP.getFlashChipMode();
  193. DEBUG_MSG_P(PSTR("[INIT] Flash chip ID: 0x%06X\n"), ESP.getFlashChipId());
  194. DEBUG_MSG_P(PSTR("[INIT] Flash speed: %u Hz\n"), ESP.getFlashChipSpeed());
  195. DEBUG_MSG_P(PSTR("[INIT] Flash mode: %s\n"), mode == FM_QIO ? "QIO" : mode == FM_QOUT ? "QOUT" : mode == FM_DIO ? "DIO" : mode == FM_DOUT ? "DOUT" : "UNKNOWN");
  196. DEBUG_MSG_P(PSTR("\n"));
  197. DEBUG_MSG_P(PSTR("[INIT] Flash sector size: %8u bytes\n"), SPI_FLASH_SEC_SIZE);
  198. DEBUG_MSG_P(PSTR("[INIT] Flash size (CHIP): %8u bytes\n"), ESP.getFlashChipRealSize());
  199. DEBUG_MSG_P(PSTR("[INIT] Flash size (SDK): %8u bytes / %4d sectors\n"), ESP.getFlashChipSize(), sectors(ESP.getFlashChipSize()));
  200. DEBUG_MSG_P(PSTR("[INIT] Firmware size: %8u bytes / %4d sectors\n"), ESP.getSketchSize(), sectors(ESP.getSketchSize()));
  201. DEBUG_MSG_P(PSTR("[INIT] Max OTA size: %8u bytes / %4d sectors\n"), maxSketchSpace(), sectors(maxSketchSpace()));
  202. DEBUG_MSG_P(PSTR("[INIT] EEPROM size: %8u bytes / %4d sectors*\n"), EEPROMr.pool() * SPI_FLASH_SEC_SIZE, EEPROMr.pool());
  203. DEBUG_MSG_P(PSTR("[INIT] Reserved space: %8u bytes / 4 sectors\n"), 4 * SPI_FLASH_SEC_SIZE);
  204. DEBUG_MSG_P(PSTR("\n"));
  205. DEBUG_MSG_P(PSTR("[INIT] EEPROM sectors: %s\n"), (char *) eepromSectors().c_str());
  206. DEBUG_MSG_P(PSTR("\n"));
  207. // -------------------------------------------------------------------------
  208. #if SPIFFS_SUPPORT
  209. FSInfo fs_info;
  210. bool fs = SPIFFS.info(fs_info);
  211. if (fs) {
  212. DEBUG_MSG_P(PSTR("[INIT] SPIFFS total size: %8u bytes / %4d sectors\n"), fs_info.totalBytes, sectors(fs_info.totalBytes));
  213. DEBUG_MSG_P(PSTR("[INIT] used size: %8u bytes\n"), fs_info.usedBytes);
  214. DEBUG_MSG_P(PSTR("[INIT] block size: %8u bytes\n"), fs_info.blockSize);
  215. DEBUG_MSG_P(PSTR("[INIT] page size: %8u bytes\n"), fs_info.pageSize);
  216. DEBUG_MSG_P(PSTR("[INIT] max files: %8u\n"), fs_info.maxOpenFiles);
  217. DEBUG_MSG_P(PSTR("[INIT] max length: %8u\n"), fs_info.maxPathLength);
  218. } else {
  219. DEBUG_MSG_P(PSTR("[INIT] No SPIFFS partition\n"));
  220. }
  221. DEBUG_MSG_P(PSTR("\n"));
  222. #endif
  223. // -------------------------------------------------------------------------
  224. DEBUG_MSG_P(PSTR("[INIT] BOARD: %s\n"), getBoardName().c_str());
  225. DEBUG_MSG_P(PSTR("[INIT] SUPPORT:"));
  226. #if ALEXA_SUPPORT
  227. DEBUG_MSG_P(PSTR(" ALEXA"));
  228. #endif
  229. #if BROKER_SUPPORT
  230. DEBUG_MSG_P(PSTR(" BROKER"));
  231. #endif
  232. #if DEBUG_SERIAL_SUPPORT
  233. DEBUG_MSG_P(PSTR(" DEBUG_SERIAL"));
  234. #endif
  235. #if DEBUG_TELNET_SUPPORT
  236. DEBUG_MSG_P(PSTR(" DEBUG_TELNET"));
  237. #endif
  238. #if DEBUG_UDP_SUPPORT
  239. DEBUG_MSG_P(PSTR(" DEBUG_UDP"));
  240. #endif
  241. #if DEBUG_WEB_SUPPORT
  242. DEBUG_MSG_P(PSTR(" DEBUG_WEB"));
  243. #endif
  244. #if DOMOTICZ_SUPPORT
  245. DEBUG_MSG_P(PSTR(" DOMOTICZ"));
  246. #endif
  247. #if HOMEASSISTANT_SUPPORT
  248. DEBUG_MSG_P(PSTR(" HOMEASSISTANT"));
  249. #endif
  250. #if I2C_SUPPORT
  251. DEBUG_MSG_P(PSTR(" I2C"));
  252. #endif
  253. #if INFLUXDB_SUPPORT
  254. DEBUG_MSG_P(PSTR(" INFLUXDB"));
  255. #endif
  256. #if LLMNR_SUPPORT
  257. DEBUG_MSG_P(PSTR(" LLMNR"));
  258. #endif
  259. #if MDNS_SERVER_SUPPORT
  260. DEBUG_MSG_P(PSTR(" MDNS_SERVER"));
  261. #endif
  262. #if MDNS_CLIENT_SUPPORT
  263. DEBUG_MSG_P(PSTR(" MDNS_CLIENT"));
  264. #endif
  265. #if MQTT_SUPPORT
  266. DEBUG_MSG_P(PSTR(" MQTT"));
  267. #endif
  268. #if NETBIOS_SUPPORT
  269. DEBUG_MSG_P(PSTR(" NETBIOS"));
  270. #endif
  271. #if NOFUSS_SUPPORT
  272. DEBUG_MSG_P(PSTR(" NOFUSS"));
  273. #endif
  274. #if NTP_SUPPORT
  275. DEBUG_MSG_P(PSTR(" NTP"));
  276. #endif
  277. #if RF_SUPPORT
  278. DEBUG_MSG_P(PSTR(" RF"));
  279. #endif
  280. #if SCHEDULER_SUPPORT
  281. DEBUG_MSG_P(PSTR(" SCHEDULER"));
  282. #endif
  283. #if SENSOR_SUPPORT
  284. DEBUG_MSG_P(PSTR(" SENSOR"));
  285. #endif
  286. #if SPIFFS_SUPPORT
  287. DEBUG_MSG_P(PSTR(" SPIFFS"));
  288. #endif
  289. #if SSDP_SUPPORT
  290. DEBUG_MSG_P(PSTR(" SSDP"));
  291. #endif
  292. #if TELNET_SUPPORT
  293. DEBUG_MSG_P(PSTR(" TELNET"));
  294. #endif
  295. #if TERMINAL_SUPPORT
  296. DEBUG_MSG_P(PSTR(" TERMINAL"));
  297. #endif
  298. #if THINGSPEAK_SUPPORT
  299. DEBUG_MSG_P(PSTR(" THINGSPEAK"));
  300. #endif
  301. #if UART_MQTT_SUPPORT
  302. DEBUG_MSG_P(PSTR(" UART_MQTT"));
  303. #endif
  304. #if WEB_SUPPORT
  305. DEBUG_MSG_P(PSTR(" WEB"));
  306. #endif
  307. #if SENSOR_SUPPORT
  308. DEBUG_MSG_P(PSTR("\n"));
  309. DEBUG_MSG_P(PSTR("[INIT] SENSORS:"));
  310. #if AM2320_SUPPORT
  311. DEBUG_MSG_P(PSTR(" AM2320_I2C"));
  312. #endif
  313. #if ANALOG_SUPPORT
  314. DEBUG_MSG_P(PSTR(" ANALOG"));
  315. #endif
  316. #if BH1750_SUPPORT
  317. DEBUG_MSG_P(PSTR(" BH1750"));
  318. #endif
  319. #if BMX280_SUPPORT
  320. DEBUG_MSG_P(PSTR(" BMX280"));
  321. #endif
  322. #if CSE7766_SUPPORT
  323. DEBUG_MSG_P(PSTR(" CSE7766"));
  324. #endif
  325. #if DALLAS_SUPPORT
  326. DEBUG_MSG_P(PSTR(" DALLAS"));
  327. #endif
  328. #if DHT_SUPPORT
  329. DEBUG_MSG_P(PSTR(" DHTXX"));
  330. #endif
  331. #if DIGITAL_SUPPORT
  332. DEBUG_MSG_P(PSTR(" DIGITAL"));
  333. #endif
  334. #if ECH1560_SUPPORT
  335. DEBUG_MSG_P(PSTR(" ECH1560"));
  336. #endif
  337. #if EMON_ADC121_SUPPORT
  338. DEBUG_MSG_P(PSTR(" EMON_ADC121"));
  339. #endif
  340. #if EMON_ADS1X15_SUPPORT
  341. DEBUG_MSG_P(PSTR(" EMON_ADX1X15"));
  342. #endif
  343. #if EMON_ANALOG_SUPPORT
  344. DEBUG_MSG_P(PSTR(" EMON_ANALOG"));
  345. #endif
  346. #if EVENTS_SUPPORT
  347. DEBUG_MSG_P(PSTR(" EVENTS"));
  348. #endif
  349. #if GUVAS12SD_SUPPORT
  350. DEBUG_MSG_P(PSTR(" GUVAS12SD"));
  351. #endif
  352. #if HCSR04_SUPPORT
  353. DEBUG_MSG_P(PSTR(" HCSR04"));
  354. #endif
  355. #if HLW8012_SUPPORT
  356. DEBUG_MSG_P(PSTR(" HLW8012"));
  357. #endif
  358. #if MHZ19_SUPPORT
  359. DEBUG_MSG_P(PSTR(" MHZ19"));
  360. #endif
  361. #if PMSX003_SUPPORT
  362. DEBUG_MSG_P(PSTR(" PMSX003"));
  363. #endif
  364. #if PZEM004T_SUPPORT
  365. DEBUG_MSG_P(PSTR(" PZEM004T"));
  366. #endif
  367. #if SENSEAIR_SUPPORT
  368. DEBUG_MSG_P(PSTR(" SENSEAIR"));
  369. #endif
  370. #if SHT3X_I2C_SUPPORT
  371. DEBUG_MSG_P(PSTR(" SHT3X_I2C"));
  372. #endif
  373. #if SI7021_SUPPORT
  374. DEBUG_MSG_P(PSTR(" SI7021"));
  375. #endif
  376. #if TMP3X_SUPPORT
  377. DEBUG_MSG_P(PSTR(" TMP3X"));
  378. #endif
  379. #if V9261F_SUPPORT
  380. DEBUG_MSG_P(PSTR(" V9261F"));
  381. #endif
  382. #endif // SENSOR_SUPPORT
  383. DEBUG_MSG_P(PSTR("\n\n"));
  384. // -------------------------------------------------------------------------
  385. unsigned char reason = resetReason();
  386. if (reason > 0) {
  387. char buffer[32];
  388. strcpy_P(buffer, custom_reset_string[reason-1]);
  389. DEBUG_MSG_P(PSTR("[INIT] Last reset reason: %s\n"), buffer);
  390. } else {
  391. DEBUG_MSG_P(PSTR("[INIT] Last reset reason: %s\n"), (char *) ESP.getResetReason().c_str());
  392. }
  393. DEBUG_MSG_P(PSTR("[INIT] Settings size: %u bytes\n"), settingsSize());
  394. DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), getFreeHeap());
  395. #if ADC_MODE_VALUE == ADC_VCC
  396. DEBUG_MSG_P(PSTR("[INIT] Power: %u mV\n"), ESP.getVcc());
  397. #endif
  398. DEBUG_MSG_P(PSTR("[INIT] Power saving delay value: %lu ms\n"), systemLoopDelay());
  399. #if SYSTEM_CHECK_ENABLED
  400. if (!systemCheck()) DEBUG_MSG_P(PSTR("\n[INIT] Device is in SAFE MODE\n"));
  401. #endif
  402. DEBUG_MSG_P(PSTR("\n"));
  403. }
  404. // -----------------------------------------------------------------------------
  405. // SSL
  406. // -----------------------------------------------------------------------------
  407. #if ASYNC_TCP_SSL_ENABLED
  408. bool sslCheckFingerPrint(const char * fingerprint) {
  409. return (strlen(fingerprint) == 59);
  410. }
  411. bool sslFingerPrintArray(const char * fingerprint, unsigned char * bytearray) {
  412. // check length (20 2-character digits ':' or ' ' separated => 20*2+19 = 59)
  413. if (!sslCheckFingerPrint(fingerprint)) return false;
  414. // walk the fingerprint
  415. for (unsigned int i=0; i<20; i++) {
  416. bytearray[i] = strtol(fingerprint + 3*i, NULL, 16);
  417. }
  418. return true;
  419. }
  420. bool sslFingerPrintChar(const char * fingerprint, char * destination) {
  421. // check length (20 2-character digits ':' or ' ' separated => 20*2+19 = 59)
  422. if (!sslCheckFingerPrint(fingerprint)) return false;
  423. // copy it
  424. strncpy(destination, fingerprint, 59);
  425. // walk the fingerprint replacing ':' for ' '
  426. for (unsigned char i = 0; i<59; i++) {
  427. if (destination[i] == ':') destination[i] = ' ';
  428. }
  429. return true;
  430. }
  431. #endif
  432. // -----------------------------------------------------------------------------
  433. // Reset
  434. // -----------------------------------------------------------------------------
  435. unsigned char resetReason() {
  436. static unsigned char status = 255;
  437. if (status == 255) {
  438. status = EEPROMr.read(EEPROM_CUSTOM_RESET);
  439. if (status > 0) resetReason(0);
  440. if (status > CUSTOM_RESET_MAX) status = 0;
  441. }
  442. return status;
  443. }
  444. void resetReason(unsigned char reason) {
  445. EEPROMr.write(EEPROM_CUSTOM_RESET, reason);
  446. EEPROMr.commit();
  447. }
  448. void reset(unsigned char reason) {
  449. resetReason(reason);
  450. ESP.restart();
  451. }
  452. void deferredReset(unsigned long delay, unsigned char reason) {
  453. _defer_reset.once_ms(delay, reset, reason);
  454. }
  455. // -----------------------------------------------------------------------------
  456. char * ltrim(char * s) {
  457. char *p = s;
  458. while ((unsigned char) *p == ' ') ++p;
  459. return p;
  460. }
  461. double roundTo(double num, unsigned char positions) {
  462. double multiplier = 1;
  463. while (positions-- > 0) multiplier *= 10;
  464. return round(num * multiplier) / multiplier;
  465. }
  466. void nice_delay(unsigned long ms) {
  467. unsigned long start = millis();
  468. while (millis() - start < ms) delay(1);
  469. }
  470. // This method is called by the SDK to know where to connect the ADC
  471. int __get_adc_mode() {
  472. return (int) (ADC_MODE_VALUE);
  473. }