#ifdef ENABLE_MOON #include // https://github.com/kitesurfer1404/WS2812FX/blob/master/src/WS2812FX.h WS2812FX ws2812fx = WS2812FX(MOON_PIXEL_LEDS, MOON_PIXEL, NEO_GRB + NEO_KHZ800); long color = 0x00A4B3; // Starting color /* * Interface with other modules */ void module_message(const String& shorttopic, const String& message) { //@@@@FIXME@@@@ instead of brightness, adjust mode? char msgptr[10]; String buffer; if(shorttopic.equalsIgnoreCase("cmd")) { if(message.equals("off")) { ws2812fx.setColor(0x000000); ws2812fx.setMode(FX_MODE_STATIC); PRINTLN_SERIAL("Shutting off"); } else if(message.equals("on")) { // restore last (static) color state ws2812fx.setColor(color); ws2812fx.setMode(FX_MODE_STATIC); PRINTLN_SERIAL("Swtiching on (static)"); } else if(message.startsWith("0x")) { message.toCharArray(msgptr, 9); color = strtoll( &msgptr[2], NULL, 16); ws2812fx.setColor(color); ws2812fx.setMode(FX_MODE_STATIC); sprintf(printbuffer, "Switching to static color 0x%x", color); PRINTLN_SERIAL(printbuffer); } else if(message.startsWith("#")) { message.toCharArray(msgptr, 8); color = strtoll( &msgptr[1], NULL, 16); ws2812fx.setColor(color); ws2812fx.setMode(FX_MODE_STATIC); sprintf(printbuffer, "Switching to static color 0x%x", color); PRINTLN_SERIAL(printbuffer); } else if(message.equals("moon")) { ws2812fx.setSpeed(20000); ws2812fx.setLength(20); // Emulate a 20 pin cycle for a 7 pixel moon lamp ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE); PRINTLN_SERIAL("Switching to moon mode"); } else if(message.equals("rainbow")) { ws2812fx.setSpeed(2000); ws2812fx.setLength(MOON_PIXEL_LEDS); ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE); PRINTLN_SERIAL("Switching to rainbow mode"); // Testing area for new scenes } else if(message.equals("twinkle")) { ws2812fx.setMode(FX_MODE_LARSON_SCANNER); PRINTLN_SERIAL("Switching to twinkle mode"); } } else if(shorttopic.equalsIgnoreCase("brightness")) { PRINTLN_SERIAL("Setting brightness to " + message); ws2812fx.setBrightness(message.toInt()); // 0-255 buffer = "brightness="; buffer.concat(message.toInt()); mqtt_publish((deviceprefix + "log"), buffer.c_str()); // @@@FIXME@@@ this needs to go elsewhere } } /* * Setup and loop code. Be cooperative! No delays, timers. */ void moon_setup() { PRINTLN_SERIAL("initialising module Moon"); ws2812fx.init(); ws2812fx.setBrightness(5); ws2812fx.setSpeed(200); ws2812fx.setColor(0x000000); ws2812fx.setMode(FX_MODE_STATIC); ws2812fx.start(); } void moon_loop() { ws2812fx.service(); } #endif