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.

259 lines
7.4 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 LIGHT_PROVIDER_NONE 0
  13. #define LIGHT_PROVIDER_WS2812 1
  14. #define LIGHT_PROVIDER_RGB 2
  15. #define LIGHT_PROVIDER_RGBW 3
  16. #define LIGHT_PROVIDER_MY9192 4
  17. void hwUpwardsCompatibility() {
  18. unsigned int board = getSetting("board", 0).toInt();
  19. if (board > 0) return;
  20. #if NODEMCUV2
  21. setSetting("board", 2);
  22. setSetting("ledGPIO", 1, 2);
  23. setSetting("ledLogic", 1, 1);
  24. setSetting("btnGPIO", 1, 0);
  25. setSetting("btnRelay", 1, 1);
  26. setSetting("relayGPIO", 1, 12);
  27. setSetting("relayLogic", 1, 0);
  28. #endif
  29. #if D1_RELAYSHIELD
  30. setSetting("board", 3);
  31. setSetting("ledGPIO", 1, 2);
  32. setSetting("ledLogic", 1, 1);
  33. setSetting("relayGPIO", 1, 5);
  34. setSetting("relayLogic", 1, 0);
  35. #endif
  36. #if SONOFF
  37. setSetting("board", 4);
  38. setSetting("ledGPIO", 1, 13);
  39. setSetting("ledLogic", 1, 1);
  40. setSetting("btnGPIO", 1, 0);
  41. setSetting("btnRelay", 1, 1);
  42. setSetting("relayGPIO", 1, 12);
  43. setSetting("relayLogic", 1, 0);
  44. #endif
  45. #if SONOFF_TH
  46. setSetting("board", 5);
  47. setSetting("ledGPIO", 1, 13);
  48. setSetting("ledLogic", 1, 1);
  49. setSetting("btnGPIO", 1, 0);
  50. setSetting("btnRelay", 1, 1);
  51. setSetting("relayGPIO", 1, 12);
  52. setSetting("relayLogic", 1, 0);
  53. #endif
  54. #if SONOFF_SV
  55. setSetting("board", 6);
  56. setSetting("ledGPIO", 1, 13);
  57. setSetting("ledLogic", 1, 1);
  58. setSetting("btnGPIO", 1, 0);
  59. setSetting("btnRelay", 1, 1);
  60. setSetting("relayGPIO", 1, 12);
  61. setSetting("relayLogic", 1, 0);
  62. #endif
  63. #if SONOFF_TOUCH
  64. setSetting("board", 7);
  65. setSetting("ledGPIO", 1, 13);
  66. setSetting("ledLogic", 1, 1);
  67. setSetting("btnGPIO", 1, 0);
  68. setSetting("btnRelay", 1, 1);
  69. setSetting("relayGPIO", 1, 12);
  70. setSetting("relayLogic", 1, 0);
  71. #endif
  72. #if SONOFF_POW
  73. setSetting("board", 8);
  74. setSetting("ledGPIO", 1, 15);
  75. setSetting("ledLogic", 1, 1);
  76. setSetting("btnGPIO", 1, 0);
  77. setSetting("btnRelay", 1, 1);
  78. setSetting("relayGPIO", 1, 12);
  79. setSetting("relayLogic", 1, 0);
  80. #endif
  81. #if SONOFF_DUAL
  82. setSetting("board", 9);
  83. setSetting("ledGPIO", 1, 13);
  84. setSetting("ledLogic", 1, 1);
  85. setSetting("btnRelay", 3, 1);
  86. setSetting("relayProvider", RELAY_PROVIDER_DUAL);
  87. #endif
  88. #if ITEAD_1CH_INCHING
  89. setSetting("board", 10);
  90. setSetting("ledGPIO", 1, 13);
  91. setSetting("ledLogic", 1, 1);
  92. setSetting("btnGPIO", 1, 0);
  93. setSetting("btnRelay", 1, 1);
  94. setSetting("relayGPIO", 1, 12);
  95. setSetting("relayLogic", 1, 0);
  96. #endif
  97. #if SONOFF_4CH
  98. setSetting("board", 11);
  99. setSetting("ledGPIO", 1, 13);
  100. setSetting("ledLogic", 1, 1);
  101. setSetting("btnGPIO", 1, 0);
  102. setSetting("btnGPIO", 2, 9);
  103. setSetting("btnGPIO", 3, 10);
  104. setSetting("btnGPIO", 4, 14);
  105. setSetting("btnRelay", 1, 2);
  106. setSetting("btnRelay", 2, 3);
  107. setSetting("btnRelay", 3, 4);
  108. setSetting("btnRelay", 4, 0);
  109. setSetting("relayGPIO", 1, 12);
  110. setSetting("relayGPIO", 2, 5);
  111. setSetting("relayGPIO", 3, 4);
  112. setSetting("relayGPIO", 4, 15);
  113. setSetting("relayLogic", 1, 0);
  114. setSetting("relayLogic", 2, 0);
  115. setSetting("relayLogic", 3, 0);
  116. setSetting("relayLogic", 4, 0);
  117. #endif
  118. #if SLAMPHER
  119. setSetting("board", 12);
  120. setSetting("ledGPIO", 1, 13);
  121. setSetting("ledLogic", 1, 1);
  122. setSetting("btnGPIO", 1, 0);
  123. setSetting("btnRelay", 1, 1);
  124. setSetting("relayGPIO", 1, 12);
  125. setSetting("relayLogic", 1, 0);
  126. #endif
  127. #if S20
  128. setSetting("board", 13);
  129. setSetting("ledGPIO", 1, 13);
  130. setSetting("ledLogic", 1, 1);
  131. setSetting("btnGPIO", 1, 0);
  132. setSetting("btnRelay", 1, 1);
  133. setSetting("relayGPIO", 1, 12);
  134. setSetting("relayLogic", 1, 0);
  135. #endif
  136. #if ESP_RELAY_BOARD
  137. setSetting("board", 14);
  138. setSetting("ledGPIO", 1, 16);
  139. setSetting("ledLogic", 1, 0);
  140. setSetting("btnGPIO", 1, 0);
  141. setSetting("btnGPIO", 2, 2);
  142. setSetting("btnRelay", 1, 1);
  143. setSetting("btnRelay", 2, 2);
  144. setSetting("relayGPIO", 1, 12);
  145. setSetting("relayGPIO", 2, 13);
  146. setSetting("relayLogic", 1, 0);
  147. setSetting("relayLogic", 2, 0);
  148. #endif
  149. #if ECOPLUG
  150. setSetting("board", 15);
  151. setSetting("ledGPIO", 1, 2);
  152. setSetting("ledLogic", 1, 0);
  153. setSetting("btnGPIO", 1, 13);
  154. setSetting("btnRelay", 1, 1);
  155. setSetting("relayGPIO", 1, 15);
  156. setSetting("relayLogic", 1, 0);
  157. #endif
  158. #if WIFI_RELAY_NC
  159. setSetting("board", 16);
  160. setSetting("btnGPIO", 1, 12);
  161. setSetting("btnGPIO", 2, 13);
  162. setSetting("btnRelay", 1, 1);
  163. setSetting("btnRelay", 2, 2);
  164. setSetting("relayGPIO", 1, 2);
  165. setSetting("relayGPIO", 2, 14);
  166. setSetting("relayLogic", 1, 1);
  167. setSetting("relayLogic", 2, 1);
  168. #endif
  169. #if WIFI_RELAY_NO
  170. setSetting("board", 17);
  171. setSetting("btnGPIO", 1, 12);
  172. setSetting("btnGPIO", 2, 13);
  173. setSetting("btnRelay", 1, 1);
  174. setSetting("btnRelay", 2, 2);
  175. setSetting("relayGPIO", 1, 2);
  176. setSetting("relayGPIO", 2, 14);
  177. setSetting("relayLogic", 1, 0);
  178. setSetting("relayLogic", 2, 0);
  179. #endif
  180. #if MQTT_RELAY
  181. setSetting("board", 18);
  182. setSetting("ledGPIO", 1, 16);
  183. setSetting("ledLogic", 1, 1);
  184. setSetting("btnGPIO", 1, 0);
  185. setSetting("btnRelay", 1, 1);
  186. setSetting("relayGPIO", 1, 12);
  187. setSetting("relayLogic", 1, 0);
  188. #endif
  189. #if WIFI_RELAYS_BOARD_KIT
  190. setSetting("board", 19);
  191. setSetting("relayGPIO", 1, 0);
  192. setSetting("relayLogic", 1, 1);
  193. setSetting("relayGPIO", 2, 2);
  194. setSetting("relayLogic", 2, 1);
  195. #endif
  196. #if AI_LIGHT
  197. setSetting("board", 20);
  198. setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
  199. setSetting("lightProvider", LIGHT_PROVIDER_MY9192);
  200. setSetting("myDIGPIO", 13);
  201. setSetting("myDCKIGPIO", 15);
  202. #endif
  203. #if LED_CONTROLLER
  204. setSetting("board", 21);
  205. setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
  206. setSetting("lightProvider", LIGHT_PROVIDER_RGB);
  207. setSetting("ledGPIO", 1, 2);
  208. setSetting("ledLogic", 1, 1);
  209. setSetting("redGPIO", 14);
  210. setSetting("greenGPIO", 5);
  211. setSetting("blueGPIO", 12);
  212. setSetting("whiteGPIO", 13);
  213. setSetting("lightLogic", 1);
  214. #endif
  215. #if ITEAD_MOTOR
  216. setSetting("board", 22);
  217. setSetting("ledGPIO", 1, 13);
  218. setSetting("ledLogic", 1, 1);
  219. setSetting("btnGPIO", 1, 0);
  220. setSetting("btnRelay", 1, 1);
  221. setSetting("relayGPIO", 1, 12);
  222. setSetting("relayLogic", 1, 0);
  223. #endif
  224. saveSettings();
  225. }