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.

292 lines
8.5 KiB

  1. /*
  2. HARDWARE MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. /*
  6. The goal of this file is to store board configuration values in EEPROM so
  7. the migration to future version 2 will be straigh forward.
  8. */
  9. #define RELAY_PROVIDER_RELAY 0
  10. #define RELAY_PROVIDER_DUAL 1
  11. #define RELAY_PROVIDER_LIGHT 2
  12. #define RELAY_PROVIDER_RFBRIDGE 3
  13. #define LIGHT_PROVIDER_NONE 0
  14. #define LIGHT_PROVIDER_WS2812 1
  15. #define LIGHT_PROVIDER_RGB 2
  16. #define LIGHT_PROVIDER_RGBW 3
  17. #define LIGHT_PROVIDER_MY9192 4
  18. void hwUpwardsCompatibility() {
  19. unsigned int board = getSetting("board", 0).toInt();
  20. if (board > 0) return;
  21. #ifdef NODEMCUV2
  22. setSetting("board", 2);
  23. setSetting("ledGPIO", 1, 2);
  24. setSetting("ledLogic", 1, 1);
  25. setSetting("btnGPIO", 1, 0);
  26. setSetting("btnRelay", 1, 1);
  27. setSetting("relayGPIO", 1, 12);
  28. setSetting("relayLogic", 1, 0);
  29. #endif
  30. #ifdef D1_RELAYSHIELD
  31. setSetting("board", 3);
  32. setSetting("ledGPIO", 1, 2);
  33. setSetting("ledLogic", 1, 1);
  34. setSetting("relayGPIO", 1, 5);
  35. setSetting("relayLogic", 1, 0);
  36. #endif
  37. #ifdef SONOFF
  38. setSetting("board", 4);
  39. setSetting("ledGPIO", 1, 13);
  40. setSetting("ledLogic", 1, 1);
  41. setSetting("btnGPIO", 1, 0);
  42. setSetting("btnRelay", 1, 1);
  43. setSetting("relayGPIO", 1, 12);
  44. setSetting("relayLogic", 1, 0);
  45. #endif
  46. #ifdef SONOFF_TH
  47. setSetting("board", 5);
  48. setSetting("ledGPIO", 1, 13);
  49. setSetting("ledLogic", 1, 1);
  50. setSetting("btnGPIO", 1, 0);
  51. setSetting("btnRelay", 1, 1);
  52. setSetting("relayGPIO", 1, 12);
  53. setSetting("relayLogic", 1, 0);
  54. #endif
  55. #ifdef SONOFF_SV
  56. setSetting("board", 6);
  57. setSetting("ledGPIO", 1, 13);
  58. setSetting("ledLogic", 1, 1);
  59. setSetting("btnGPIO", 1, 0);
  60. setSetting("btnRelay", 1, 1);
  61. setSetting("relayGPIO", 1, 12);
  62. setSetting("relayLogic", 1, 0);
  63. #endif
  64. #ifdef SONOFF_TOUCH
  65. setSetting("board", 7);
  66. setSetting("ledGPIO", 1, 13);
  67. setSetting("ledLogic", 1, 1);
  68. setSetting("btnGPIO", 1, 0);
  69. setSetting("btnRelay", 1, 1);
  70. setSetting("relayGPIO", 1, 12);
  71. setSetting("relayLogic", 1, 0);
  72. #endif
  73. #ifdef SONOFF_POW
  74. setSetting("board", 8);
  75. setSetting("ledGPIO", 1, 15);
  76. setSetting("ledLogic", 1, 1);
  77. setSetting("btnGPIO", 1, 0);
  78. setSetting("btnRelay", 1, 1);
  79. setSetting("relayGPIO", 1, 12);
  80. setSetting("relayLogic", 1, 0);
  81. #endif
  82. #ifdef SONOFF_DUAL
  83. setSetting("board", 9);
  84. setSetting("ledGPIO", 1, 13);
  85. setSetting("ledLogic", 1, 1);
  86. setSetting("btnRelay", 3, 1);
  87. setSetting("relayProvider", RELAY_PROVIDER_DUAL);
  88. #endif
  89. #ifdef ITEAD_1CH_INCHING
  90. setSetting("board", 10);
  91. setSetting("ledGPIO", 1, 13);
  92. setSetting("ledLogic", 1, 1);
  93. setSetting("btnGPIO", 1, 0);
  94. setSetting("btnRelay", 1, 1);
  95. setSetting("relayGPIO", 1, 12);
  96. setSetting("relayLogic", 1, 0);
  97. #endif
  98. #ifdef SONOFF_4CH
  99. setSetting("board", 11);
  100. setSetting("ledGPIO", 1, 13);
  101. setSetting("ledLogic", 1, 1);
  102. setSetting("btnGPIO", 1, 0);
  103. setSetting("btnGPIO", 2, 9);
  104. setSetting("btnGPIO", 3, 10);
  105. setSetting("btnGPIO", 4, 14);
  106. setSetting("btnRelay", 1, 2);
  107. setSetting("btnRelay", 2, 3);
  108. setSetting("btnRelay", 3, 4);
  109. setSetting("btnRelay", 4, 0);
  110. setSetting("relayGPIO", 1, 12);
  111. setSetting("relayGPIO", 2, 5);
  112. setSetting("relayGPIO", 3, 4);
  113. setSetting("relayGPIO", 4, 15);
  114. setSetting("relayLogic", 1, 0);
  115. setSetting("relayLogic", 2, 0);
  116. setSetting("relayLogic", 3, 0);
  117. setSetting("relayLogic", 4, 0);
  118. #endif
  119. #ifdef SLAMPHER
  120. setSetting("board", 12);
  121. setSetting("ledGPIO", 1, 13);
  122. setSetting("ledLogic", 1, 1);
  123. setSetting("btnGPIO", 1, 0);
  124. setSetting("btnRelay", 1, 1);
  125. setSetting("relayGPIO", 1, 12);
  126. setSetting("relayLogic", 1, 0);
  127. #endif
  128. #ifdef S20
  129. setSetting("board", 13);
  130. setSetting("ledGPIO", 1, 13);
  131. setSetting("ledLogic", 1, 1);
  132. setSetting("btnGPIO", 1, 0);
  133. setSetting("btnRelay", 1, 1);
  134. setSetting("relayGPIO", 1, 12);
  135. setSetting("relayLogic", 1, 0);
  136. #endif
  137. #ifdef ESP_RELAY_BOARD
  138. setSetting("board", 14);
  139. setSetting("ledGPIO", 1, 16);
  140. setSetting("ledLogic", 1, 0);
  141. setSetting("btnGPIO", 1, 0);
  142. setSetting("btnGPIO", 2, 2);
  143. setSetting("btnRelay", 1, 1);
  144. setSetting("btnRelay", 2, 2);
  145. setSetting("relayGPIO", 1, 12);
  146. setSetting("relayGPIO", 2, 13);
  147. setSetting("relayLogic", 1, 0);
  148. setSetting("relayLogic", 2, 0);
  149. #endif
  150. #ifdef ECOPLUG
  151. setSetting("board", 15);
  152. setSetting("ledGPIO", 1, 2);
  153. setSetting("ledLogic", 1, 0);
  154. setSetting("btnGPIO", 1, 13);
  155. setSetting("btnRelay", 1, 1);
  156. setSetting("relayGPIO", 1, 15);
  157. setSetting("relayLogic", 1, 0);
  158. #endif
  159. #ifdef WIFI_RELAY_NC
  160. setSetting("board", 16);
  161. setSetting("btnGPIO", 1, 12);
  162. setSetting("btnGPIO", 2, 13);
  163. setSetting("btnRelay", 1, 1);
  164. setSetting("btnRelay", 2, 2);
  165. setSetting("relayGPIO", 1, 2);
  166. setSetting("relayGPIO", 2, 14);
  167. setSetting("relayLogic", 1, 1);
  168. setSetting("relayLogic", 2, 1);
  169. #endif
  170. #ifdef WIFI_RELAY_NO
  171. setSetting("board", 17);
  172. setSetting("btnGPIO", 1, 12);
  173. setSetting("btnGPIO", 2, 13);
  174. setSetting("btnRelay", 1, 1);
  175. setSetting("btnRelay", 2, 2);
  176. setSetting("relayGPIO", 1, 2);
  177. setSetting("relayGPIO", 2, 14);
  178. setSetting("relayLogic", 1, 0);
  179. setSetting("relayLogic", 2, 0);
  180. #endif
  181. #ifdef MQTT_RELAY
  182. setSetting("board", 18);
  183. setSetting("ledGPIO", 1, 16);
  184. setSetting("ledLogic", 1, 1);
  185. setSetting("btnGPIO", 1, 0);
  186. setSetting("btnRelay", 1, 1);
  187. setSetting("relayGPIO", 1, 12);
  188. setSetting("relayLogic", 1, 0);
  189. #endif
  190. #ifdef WIFI_RELAYS_BOARD_KIT
  191. setSetting("board", 19);
  192. setSetting("relayGPIO", 1, 0);
  193. setSetting("relayLogic", 1, 1);
  194. setSetting("relayGPIO", 2, 2);
  195. setSetting("relayLogic", 2, 1);
  196. #endif
  197. #ifdef AI_LIGHT
  198. setSetting("board", 20);
  199. setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
  200. setSetting("lightProvider", LIGHT_PROVIDER_MY9192);
  201. setSetting("myDIGPIO", 13);
  202. setSetting("myDCKIGPIO", 15);
  203. #endif
  204. #ifdef LED_CONTROLLER
  205. setSetting("board", 21);
  206. setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
  207. setSetting("lightProvider", LIGHT_PROVIDER_RGB);
  208. setSetting("ledGPIO", 1, 2);
  209. setSetting("ledLogic", 1, 1);
  210. setSetting("redGPIO", 14);
  211. setSetting("greenGPIO", 5);
  212. setSetting("blueGPIO", 12);
  213. setSetting("whiteGPIO", 13);
  214. setSetting("lightLogic", 1);
  215. #endif
  216. #ifdef ITEAD_MOTOR
  217. setSetting("board", 22);
  218. setSetting("ledGPIO", 1, 13);
  219. setSetting("ledLogic", 1, 1);
  220. setSetting("btnGPIO", 1, 0);
  221. setSetting("btnRelay", 1, 1);
  222. setSetting("relayGPIO", 1, 12);
  223. setSetting("relayLogic", 1, 0);
  224. #endif
  225. #ifdef ESPURNA_H
  226. setSetting("board", 23);
  227. setSetting("ledGPIO", 1, 5);
  228. setSetting("ledLogic", 1, 0);
  229. setSetting("btnGPIO", 1, 4);
  230. setSetting("btnRelay", 1, 1);
  231. setSetting("relayGPIO", 1, 12);
  232. setSetting("relayLogic", 1, 1);
  233. #endif
  234. #ifdef H801_LED_CONTROLLER
  235. setSetting("board", 24);
  236. setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
  237. setSetting("lightProvider", LIGHT_PROVIDER_RGB2W);
  238. setSetting("ledGPIO", 5, 1);
  239. setSetting("ledLogic", 1, 1);
  240. setSetting("redGPIO", 15);
  241. setSetting("greenGPIO", 13);
  242. setSetting("blueGPIO", 12);
  243. setSetting("whiteGPIO", 14);
  244. setSetting("white2GPIO", 4);
  245. setSetting("lightLogic", 1);
  246. #endif
  247. #ifdef SONOFF_RFBRIDGE
  248. setSetting("board", 26);
  249. setSetting("ledGPIO", 1, 13);
  250. setSetting("ledLogic", 1, 1);
  251. setSetting("btnGPIO", 1, 0);
  252. setSetting("relayProvider", RELAY_PROVIDER_RFBRIDGE);
  253. #endif
  254. saveSettings();
  255. }