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.

672 lines
19 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. LIGHT MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
  6. #ifndef LIGHT_PROVIDER_EXPERIMENTAL_RGB_ONLY_HSV_IR
  7. #include <Ticker.h>
  8. #include <ArduinoJson.h>
  9. #include <vector>
  10. #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
  11. #define PWM_CHANNEL_NUM_MAX LIGHT_CHANNELS
  12. extern "C" {
  13. #include "pwm.h"
  14. }
  15. #endif
  16. Ticker colorTicker;
  17. typedef struct {
  18. unsigned char pin;
  19. bool reverse;
  20. unsigned char value;
  21. unsigned char shadow;
  22. } channel_t;
  23. std::vector<channel_t> _channels;
  24. bool _lightState = false;
  25. unsigned int _brightness = LIGHT_MAX_BRIGHTNESS;
  26. #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
  27. #include <my9291.h>
  28. my9291 * _my9291;
  29. #endif
  30. // Gamma Correction lookup table (8 bit)
  31. // TODO: move to PROGMEM
  32. const unsigned char gamma_table[] = {
  33. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
  35. 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6,
  36. 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11,
  37. 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19,
  38. 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28,
  39. 29, 30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40,
  40. 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54,
  41. 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71,
  42. 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 86, 87, 88, 89,
  43. 91, 92, 93, 94, 96, 97, 98, 100, 101, 102, 104, 105, 106, 108, 109, 110,
  44. 112, 113, 115, 116, 118, 119, 121, 122, 123, 125, 126, 128, 130, 131, 133, 134,
  45. 136, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 155, 157, 159, 160,
  46. 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 187, 189,
  47. 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221,
  48. 223, 225, 227, 229, 231, 233, 235, 238, 240, 242, 244, 246, 248, 251, 253, 255
  49. };
  50. // -----------------------------------------------------------------------------
  51. // UTILS
  52. // -----------------------------------------------------------------------------
  53. void _fromRGB(const char * rgb) {
  54. char * p = (char *) rgb;
  55. if (strlen(p) == 0) return;
  56. // if color begins with a # then assume HEX RGB
  57. if (p[0] == '#') {
  58. if (lightHasColor()) {
  59. ++p;
  60. unsigned long value = strtoul(p, NULL, 16);
  61. // RGBA values are interpreted like RGB + brightness
  62. if (strlen(p) > 7) {
  63. _channels[0].value = (value >> 24) & 0xFF;
  64. _channels[1].value = (value >> 16) & 0xFF;
  65. _channels[2].value = (value >> 8) & 0xFF;
  66. _brightness = (value & 0xFF) * LIGHT_MAX_BRIGHTNESS / 255;
  67. } else {
  68. _channels[0].value = (value >> 16) & 0xFF;
  69. _channels[1].value = (value >> 8) & 0xFF;
  70. _channels[2].value = (value) & 0xFF;
  71. }
  72. }
  73. // it's a temperature in mireds
  74. } else if (p[0] == 'M') {
  75. if (lightHasColor()) {
  76. unsigned long mireds = atol(p + 1);
  77. _fromMireds(mireds);
  78. }
  79. // it's a temperature in kelvin
  80. } else if (p[0] == 'K') {
  81. if (lightHasColor()) {
  82. unsigned long kelvin = atol(p + 1);
  83. _fromKelvin(kelvin);
  84. }
  85. // otherwise assume decimal values separated by commas
  86. } else {
  87. char * tok;
  88. unsigned char count = 0;
  89. unsigned char channels = _channels.size();
  90. tok = strtok(p, ",");
  91. while (tok != NULL) {
  92. _channels[count].value = atoi(tok);
  93. if (++count == channels) break;
  94. tok = strtok(NULL, ",");
  95. }
  96. // RGB but less than 3 values received
  97. if (lightHasColor() && (count < 3)) {
  98. _channels[1].value = _channels[0].value;
  99. _channels[2].value = _channels[0].value;
  100. }
  101. }
  102. }
  103. void _toRGB(char * rgb, size_t len, bool applyBrightness) {
  104. if (!lightHasColor()) return;
  105. float b = applyBrightness ? (float) _brightness / LIGHT_MAX_BRIGHTNESS : 1;
  106. unsigned long value = 0;
  107. value += _channels[0].value * b;
  108. value <<= 8;
  109. value += _channels[1].value * b;
  110. value <<= 8;
  111. value += _channels[2].value * b;
  112. snprintf_P(rgb, len, PSTR("#%06X"), value);
  113. }
  114. void _toRGB(char * rgb, size_t len) {
  115. _toRGB(rgb, len, false);
  116. }
  117. void _toLong(char * color, size_t len, bool applyBrightness) {
  118. if (!lightHasColor()) return;
  119. float b = applyBrightness ? (float) _brightness / LIGHT_MAX_BRIGHTNESS : 1;
  120. snprintf_P(color, len, PSTR("%d,%d,%d"),
  121. (int) (_channels[0].value * b),
  122. (int) (_channels[1].value * b),
  123. (int) (_channels[2].value * b)
  124. );
  125. }
  126. void _toLong(char * color, size_t len) {
  127. _toLong(color, len, false);
  128. }
  129. // Thanks to Sacha Telgenhof for sharing this code in his AiLight library
  130. // https://github.com/stelgenhof/AiLight
  131. void _fromKelvin(unsigned long kelvin) {
  132. // Check we have RGB channels
  133. if (!lightHasColor()) return;
  134. // Calculate colors
  135. unsigned int red = (kelvin <= 66)
  136. ? LIGHT_MAX_VALUE
  137. : 329.698727446 * pow((kelvin - 60), -0.1332047592);
  138. unsigned int green = (kelvin <= 66)
  139. ? 99.4708025861 * log(kelvin) - 161.1195681661
  140. : 288.1221695283 * pow(kelvin, -0.0755148492);
  141. unsigned int blue = (kelvin >= 66)
  142. ? LIGHT_MAX_VALUE
  143. : ((kelvin <= 19)
  144. ? 0
  145. : 138.5177312231 * log(kelvin - 10) - 305.0447927307);
  146. // Save values
  147. _channels[0].value = constrain(red, 0, LIGHT_MAX_VALUE);
  148. _channels[1].value = constrain(green, 0, LIGHT_MAX_VALUE);
  149. _channels[2].value = constrain(blue, 0, LIGHT_MAX_VALUE);
  150. }
  151. // Color temperature is measured in mireds (kelvin = 1e6/mired)
  152. void _fromMireds(unsigned long mireds) {
  153. if (mireds == 0) mireds = 1;
  154. unsigned long kelvin = constrain(1000000UL / mireds, 1000, 40000) / 100;
  155. _fromKelvin(kelvin);
  156. }
  157. unsigned int _toPWM(unsigned long value, bool bright, bool gamma, bool reverse) {
  158. value = constrain(value, 0, LIGHT_MAX_VALUE);
  159. if (bright) value *= ((float) _brightness / LIGHT_MAX_BRIGHTNESS);
  160. if (gamma) value = gamma_table[value];
  161. if (LIGHT_MAX_VALUE != LIGHT_LIMIT_PWM) value = map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_LIMIT_PWM);
  162. if (reverse) value = LIGHT_LIMIT_PWM - value;
  163. return value;
  164. }
  165. // Returns a PWM valule for the given channel ID
  166. unsigned int _toPWM(unsigned char id) {
  167. if (id < _channels.size()) {
  168. bool isColor = lightHasColor() && (id < 3);
  169. bool bright = isColor;
  170. bool gamma = isColor & (getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1);
  171. return _toPWM(_channels[id].shadow, bright, gamma, _channels[id].reverse);
  172. }
  173. return 0;
  174. }
  175. // -----------------------------------------------------------------------------
  176. // PROVIDER
  177. // -----------------------------------------------------------------------------
  178. void _shadow() {
  179. for (unsigned int i=0; i < _channels.size(); i++) {
  180. _channels[i].shadow = _lightState ? _channels[i].value : 0;
  181. }
  182. if (lightHasColor()) {
  183. bool useWhite = getSetting("useWhite", LIGHT_USE_WHITE).toInt() == 1;
  184. if (_lightState && useWhite && (_channels.size() > 3)) {
  185. if (_channels[0].shadow == _channels[1].shadow && _channels[1].shadow == _channels[2].shadow ) {
  186. _channels[3].shadow = _channels[0].shadow * ((float) _brightness / LIGHT_MAX_BRIGHTNESS);
  187. _channels[2].shadow = 0;
  188. _channels[1].shadow = 0;
  189. _channels[0].shadow = 0;
  190. }
  191. }
  192. }
  193. }
  194. void _lightProviderUpdate() {
  195. _shadow();
  196. #ifdef LIGHT_ENABLE_PIN
  197. digitalWrite(LIGHT_ENABLE_PIN, _lightState);
  198. #endif
  199. #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
  200. if (_lightState) {
  201. unsigned int red = _toPWM(0);
  202. unsigned int green = _toPWM(1);
  203. unsigned int blue = _toPWM(2);
  204. unsigned int white = _toPWM(3)
  205. unsigned int warm = _toPWM(4);
  206. _my9291->setColor((my9291_color_t) { red, green, blue, white, warm });
  207. _my9291->setState(true);
  208. } else {
  209. _my9291->setColor((my9291_color_t) { 0, 0, 0, 0, 0 });
  210. _my9291->setState(false);
  211. }
  212. #endif
  213. #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
  214. for (unsigned int i=0; i < _channels.size(); i++) {
  215. pwm_set_duty(_toPWM(i), i);
  216. }
  217. pwm_start();
  218. #endif
  219. }
  220. // -----------------------------------------------------------------------------
  221. // PERSISTANCE
  222. // -----------------------------------------------------------------------------
  223. void _lightColorSave() {
  224. for (unsigned int i=0; i < _channels.size(); i++) {
  225. setSetting("ch", i, _channels[i].value);
  226. }
  227. setSetting("brightness", _brightness);
  228. saveSettings();
  229. }
  230. void _lightColorRestore() {
  231. for (unsigned int i=0; i < _channels.size(); i++) {
  232. _channels[i].value = getSetting("ch", i, i==0 ? 255 : 0).toInt();
  233. }
  234. _brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt();
  235. lightUpdate(false, false);
  236. }
  237. // -----------------------------------------------------------------------------
  238. // MQTT
  239. // -----------------------------------------------------------------------------
  240. void _lightMQTTCallback(unsigned int type, const char * topic, const char * payload) {
  241. if (type == MQTT_CONNECT_EVENT) {
  242. if (lightHasColor()) {
  243. mqttSubscribe(MQTT_TOPIC_BRIGHTNESS);
  244. mqttSubscribe(MQTT_TOPIC_MIRED);
  245. mqttSubscribe(MQTT_TOPIC_KELVIN);
  246. mqttSubscribe(MQTT_TOPIC_COLOR);
  247. }
  248. char buffer[strlen(MQTT_TOPIC_CHANNEL) + 3];
  249. snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_CHANNEL);
  250. mqttSubscribe(buffer);
  251. }
  252. if (type == MQTT_MESSAGE_EVENT) {
  253. // Match topic
  254. String t = mqttSubtopic((char *) topic);
  255. // Color temperature in mireds
  256. if (t.equals(MQTT_TOPIC_MIRED)) {
  257. _fromMireds(atol(payload));
  258. lightUpdate(true, mqttForward());
  259. }
  260. // Color temperature in kelvins
  261. if (t.equals(MQTT_TOPIC_KELVIN)) {
  262. _fromKelvin(atol(payload));
  263. lightUpdate(true, mqttForward());
  264. }
  265. // Color
  266. if (t.equals(MQTT_TOPIC_COLOR)) {
  267. lightColor(payload);
  268. lightUpdate(true, mqttForward());
  269. }
  270. // Brightness
  271. if (t.equals(MQTT_TOPIC_BRIGHTNESS)) {
  272. _brightness = constrain(atoi(payload), 0, LIGHT_MAX_BRIGHTNESS);
  273. lightUpdate(true, mqttForward());
  274. }
  275. // Channel
  276. if (t.startsWith(MQTT_TOPIC_CHANNEL)) {
  277. unsigned int channelID = t.substring(strlen(MQTT_TOPIC_CHANNEL)+1).toInt();
  278. if (channelID >= _channels.size()) {
  279. DEBUG_MSG_P(PSTR("[LIGHT] Wrong channelID (%d)\n"), channelID);
  280. return;
  281. }
  282. lightChannel(channelID, atoi(payload));
  283. lightUpdate(true, mqttForward());
  284. }
  285. }
  286. }
  287. // -----------------------------------------------------------------------------
  288. // API
  289. // -----------------------------------------------------------------------------
  290. unsigned char lightChannels() {
  291. return _channels.size();
  292. }
  293. bool lightHasColor() {
  294. bool useColor = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
  295. return useColor && (_channels.size() > 2);
  296. }
  297. unsigned char lightWhiteChannels() {
  298. return _channels.size() % 3;
  299. }
  300. void lightMQTT() {
  301. char buffer[12];
  302. if (lightHasColor()) {
  303. // Color
  304. if (getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1) {
  305. _toRGB(buffer, 12, false);
  306. } else {
  307. _toLong(buffer, 12, false);
  308. }
  309. mqttSend(MQTT_TOPIC_COLOR, buffer);
  310. // Brightness
  311. snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _brightness);
  312. mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
  313. }
  314. // Channels
  315. for (unsigned int i=0; i < _channels.size(); i++) {
  316. snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _channels[i].value);
  317. mqttSend(MQTT_TOPIC_CHANNEL, i, buffer);
  318. }
  319. }
  320. void lightUpdate(bool save, bool forward) {
  321. _lightProviderUpdate();
  322. // Report color & brightness to MQTT broker
  323. if (forward) lightMQTT();
  324. // Report color to WS clients (using current brightness setting)
  325. #if WEB_SUPPORT
  326. {
  327. DynamicJsonBuffer jsonBuffer;
  328. JsonObject& root = jsonBuffer.createObject();
  329. root["colorVisible"] = 1;
  330. root["useColor"] = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
  331. root["useWhite"] = getSetting("useWhite", LIGHT_USE_WHITE).toInt() == 1;
  332. root["useGamma"] = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1;
  333. if (lightHasColor()) {
  334. root["color"] = lightColor();
  335. root["brightness"] = lightBrightness();
  336. }
  337. JsonArray& channels = root.createNestedArray("channels");
  338. for (unsigned char id=0; id < lightChannels(); id++) {
  339. channels.add(lightChannel(id));
  340. }
  341. String output;
  342. root.printTo(output);
  343. wsSend(output.c_str());
  344. }
  345. #endif
  346. #if LIGHT_SAVE_ENABLED
  347. // Delay saving to EEPROM 5 seconds to avoid wearing it out unnecessarily
  348. if (save) colorTicker.once(LIGHT_SAVE_DELAY, _lightColorSave);
  349. #endif
  350. };
  351. #if LIGHT_SAVE_ENABLED == 0
  352. void lightSave() {
  353. _lightColorSave();
  354. }
  355. #endif
  356. void lightState(bool state) {
  357. _lightState = state;
  358. }
  359. bool lightState() {
  360. return _lightState;
  361. }
  362. void lightColor(const char * color) {
  363. _fromRGB(color);
  364. }
  365. String lightColor() {
  366. char rgb[8];
  367. _toRGB(rgb, 8, false);
  368. return String(rgb);
  369. }
  370. unsigned int lightChannel(unsigned char id) {
  371. if (id <= _channels.size()) {
  372. return _channels[id].value;
  373. }
  374. return 0;
  375. }
  376. void lightChannel(unsigned char id, unsigned int value) {
  377. if (id <= _channels.size()) {
  378. _channels[id].value = constrain(value, 0, LIGHT_MAX_VALUE);
  379. }
  380. }
  381. unsigned int lightBrightness() {
  382. return _brightness;
  383. }
  384. void lightBrightness(unsigned int b) {
  385. _brightness = constrain(b, 0, LIGHT_MAX_BRIGHTNESS);
  386. }
  387. // -----------------------------------------------------------------------------
  388. // SETUP
  389. // -----------------------------------------------------------------------------
  390. void _lightAPISetup() {
  391. #if WEB_SUPPORT
  392. // API entry points (protected with apikey)
  393. if (lightHasColor()) {
  394. apiRegister(MQTT_TOPIC_COLOR, MQTT_TOPIC_COLOR,
  395. [](char * buffer, size_t len) {
  396. if (getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1) {
  397. _toRGB(buffer, len, false);
  398. } else {
  399. _toLong(buffer, len, false);
  400. }
  401. },
  402. [](const char * payload) {
  403. lightColor(payload);
  404. lightUpdate(true, true);
  405. }
  406. );
  407. apiRegister(MQTT_TOPIC_BRIGHTNESS, MQTT_TOPIC_BRIGHTNESS,
  408. [](char * buffer, size_t len) {
  409. snprintf_P(buffer, len, PSTR("%d"), _brightness);
  410. },
  411. [](const char * payload) {
  412. lightBrightness(atoi(payload));
  413. lightUpdate(true, true);
  414. }
  415. );
  416. apiRegister(MQTT_TOPIC_KELVIN, MQTT_TOPIC_KELVIN,
  417. [](char * buffer, size_t len) {},
  418. [](const char * payload) {
  419. _fromKelvin(atol(payload));
  420. lightUpdate(true, true);
  421. }
  422. );
  423. apiRegister(MQTT_TOPIC_MIRED, MQTT_TOPIC_MIRED,
  424. [](char * buffer, size_t len) {},
  425. [](const char * payload) {
  426. _fromMireds(atol(payload));
  427. lightUpdate(true, true);
  428. }
  429. );
  430. }
  431. for (unsigned int id=0; id<lightChannels(); id++) {
  432. char url[15];
  433. snprintf_P(url, sizeof(url), PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
  434. char key[10];
  435. snprintf_P(key, sizeof(key), PSTR("%s%d"), MQTT_TOPIC_CHANNEL, id);
  436. apiRegister(url, key,
  437. [id](char * buffer, size_t len) {
  438. snprintf_P(buffer, len, PSTR("%d"), lightChannel(id));
  439. },
  440. [id](const char * payload) {
  441. lightChannel(id, atoi(payload));
  442. lightUpdate(true, true);
  443. }
  444. );
  445. }
  446. #endif // WEB_SUPPORT
  447. }
  448. #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
  449. unsigned long getIOMux(unsigned long gpio) {
  450. unsigned long muxes[16] = {
  451. PERIPHS_IO_MUX_GPIO0_U, PERIPHS_IO_MUX_U0TXD_U, PERIPHS_IO_MUX_GPIO2_U, PERIPHS_IO_MUX_U0RXD_U,
  452. PERIPHS_IO_MUX_GPIO4_U, PERIPHS_IO_MUX_GPIO5_U, PERIPHS_IO_MUX_SD_CLK_U, PERIPHS_IO_MUX_SD_DATA0_U,
  453. PERIPHS_IO_MUX_SD_DATA1_U, PERIPHS_IO_MUX_SD_DATA2_U, PERIPHS_IO_MUX_SD_DATA3_U, PERIPHS_IO_MUX_SD_CMD_U,
  454. PERIPHS_IO_MUX_MTDI_U, PERIPHS_IO_MUX_MTCK_U, PERIPHS_IO_MUX_MTMS_U, PERIPHS_IO_MUX_MTDO_U
  455. };
  456. return muxes[gpio];
  457. }
  458. unsigned long getIOFunc(unsigned long gpio) {
  459. unsigned long funcs[16] = {
  460. FUNC_GPIO0, FUNC_GPIO1, FUNC_GPIO2, FUNC_GPIO3,
  461. FUNC_GPIO4, FUNC_GPIO5, FUNC_GPIO6, FUNC_GPIO7,
  462. FUNC_GPIO8, FUNC_GPIO9, FUNC_GPIO10, FUNC_GPIO11,
  463. FUNC_GPIO12, FUNC_GPIO13, FUNC_GPIO14, FUNC_GPIO15
  464. };
  465. return funcs[gpio];
  466. }
  467. #endif
  468. void lightSetup() {
  469. #ifdef LIGHT_ENABLE_PIN
  470. pinMode(LIGHT_ENABLE_PIN, OUTPUT);
  471. #endif
  472. #if LIGHT_PROVIDER == LIGHT_PROVIDER_MY9192
  473. _my9291 = new my9291(MY9291_DI_PIN, MY9291_DCKI_PIN, MY9291_COMMAND, MY9291_CHANNELS);
  474. for (unsigned char i=0; i<MY9291_CHANNELS; i++) {
  475. _channels.push_back((channel_t) {0, false, 0});
  476. }
  477. #endif
  478. #if LIGHT_PROVIDER == LIGHT_PROVIDER_DIMMER
  479. #ifdef LIGHT_CH1_PIN
  480. _channels.push_back((channel_t) {LIGHT_CH1_PIN, LIGHT_CH1_INVERSE, 0});
  481. #endif
  482. #ifdef LIGHT_CH2_PIN
  483. _channels.push_back((channel_t) {LIGHT_CH2_PIN, LIGHT_CH2_INVERSE, 0});
  484. #endif
  485. #ifdef LIGHT_CH3_PIN
  486. _channels.push_back((channel_t) {LIGHT_CH3_PIN, LIGHT_CH3_INVERSE, 0});
  487. #endif
  488. #ifdef LIGHT_CH4_PIN
  489. _channels.push_back((channel_t) {LIGHT_CH4_PIN, LIGHT_CH4_INVERSE, 0});
  490. #endif
  491. #ifdef LIGHT_CH5_PIN
  492. _channels.push_back((channel_t) {LIGHT_CH5_PIN, LIGHT_CH5_INVERSE, 0});
  493. #endif
  494. uint32 pwm_duty_init[PWM_CHANNEL_NUM_MAX];
  495. uint32 io_info[PWM_CHANNEL_NUM_MAX][3];
  496. for (unsigned int i=0; i < _channels.size(); i++) {
  497. pwm_duty_init[i] = 0;
  498. io_info[i][0] = getIOMux(_channels[i].pin);
  499. io_info[i][1] = getIOFunc(_channels[i].pin);
  500. io_info[i][2] = _channels[i].pin;
  501. pinMode(_channels[i].pin, OUTPUT);
  502. }
  503. pwm_init(LIGHT_MAX_PWM, pwm_duty_init, PWM_CHANNEL_NUM_MAX, io_info);
  504. pwm_start();
  505. #endif
  506. DEBUG_MSG_P(PSTR("[LIGHT] LIGHT_PROVIDER = %d\n"), LIGHT_PROVIDER);
  507. DEBUG_MSG_P(PSTR("[LIGHT] Number of channels: %d\n"), _channels.size());
  508. _lightColorRestore();
  509. _lightAPISetup();
  510. mqttRegister(_lightMQTTCallback);
  511. }
  512. void lightLoop(){
  513. }
  514. #endif // LIGHT_PROVIDER_EXPERIMENTAL_RGB_ONLY_HSV_IR
  515. #endif // LIGHT_PROVIDER != LIGHT_PROVIDER_NONE