/* * led-controller as a desktop program: the firmware's app_main (sim-controller/components/sim/sim_main.c) * with its settings from the command line or the environment. No ESP-IDF is needed to build or run it. * * led-controller [--db DIR] [--port N] * * The bridges (the USB bridge board, /dev/ttyACM1, or host:port over UDP such as led-simulator) are kept in * the store's settings: set them in the web UI under Settings > Network > Bridges. The environment works * too: LED_CONTROLLER_DB, LED_CONTROLLER_HTTP_PORT. Without a bridge the program runs, but its ESP-NOW frames * go nowhere. */ #include #include #include void app_main(void); static void set_from_env(const char *from, const char *to) { const char *v = getenv(from); if (v && v[0] && !(getenv(to) && getenv(to)[0])) { setenv(to, v, 1); } } static void usage(FILE *out) { fprintf(out, "usage: led-controller [--db DIR] [--port N]\n" " --db DIR store directory (default /db)\n" " --port N web UI and API port (default 8080)\n" " bridges are set in the web UI (Settings > Network > Bridges)\n"); } int main(int argc, char **argv) { for (int i = 1; i < argc; i++) { const char *a = argv[i]; if (!strcmp(a, "-h") || !strcmp(a, "--help")) { usage(stdout); return 0; } if ((!strcmp(a, "--db") || !strcmp(a, "--port")) && i + 1 < argc) { const char *val = argv[++i]; setenv(!strcmp(a, "--db") ? "LED_SIM_DB" : "LED_SIM_HTTP_PORT", val, 1); continue; } fprintf(stderr, "led-controller: unknown option %s\n", a); usage(stderr); return 2; } set_from_env("LED_CONTROLLER_DB", "LED_SIM_DB"); set_from_env("LED_CONTROLLER_HTTP_PORT", "LED_SIM_HTTP_PORT"); app_main(); // runs until the process is stopped return 0; }