#include "Commander.h" #include "wifi/wifi_command.h" #include #include #include #include #include "screen-settings.h" #include "colors.h" SPIClass hspi(HSPI); Adafruit_SSD1351 screen(SCREEN_WIDTH, SCREEN_HEIGHT, &hspi, CS_PIN, DC_PIN, RST_PIN); Commander commander; RGB global_color; RGB parse_color(const std::vector ¶ms) { // todo: rgb and hsl colors return RGB(params.front().c_str()); } void draw_set_color(const std::vector ¶ms, CommanderClient *client) { if (params.empty()) { client->println("no color provided"); return; } global_color = parse_color(params); } void draw_fill_screen(const std::vector ¶ms, CommanderClient *client) { RGB color; if (params.empty()) { color = global_color; } else { color = parse_color(params); } screen.fillScreen(color.to_565()); } // [color] void draw_fill_rect(const std::vector ¶ms, CommanderClient *client) { if (params.size() < 4) { client->println("missing parameters"); return; } int16_t x, y, width, height; if (!params[0].ReadInto(&x)) { client->println("parameter x is not valid"); return; } if (!params[1].ReadInto(&y)) { client->println("parameter y is not valid"); return; } if (!params[2].ReadInto(&width)) { client->println("parameter width is not valid"); return; } if (!params[3].ReadInto(&height)) { client->println("parameter height is not valid"); return; } RGB color; if (params.size() < 5) { color = global_color; } else { color = parse_color(std::vector(params.begin()+4, params.end())); } screen.fillRect(x, y, width, height, color.to_565()); } // [color] void draw_draw_line(const std::vector ¶ms, CommanderClient *client) { if (params.size() < 4) { client->println("missing parameters"); return; } int16_t x1, y1, x2, y2; if (!params[0].ReadInto(&x1)) { client->println("parameter x1 is not valid"); return; } if (!params[1].ReadInto(&y1)) { client->println("parameter y1 is not valid"); return; } if (!params[2].ReadInto(&x2)) { client->println("parameter x2 is not valid"); return; } if (!params[3].ReadInto(&y2)) { client->println("parameter y2 is not valid"); return; } RGB color; if (params.size() < 5) { color = global_color; } else { color = parse_color(std::vector(params.begin()+4, params.end())); } screen.drawLine(x1, y1, x2, y2, color.to_565()); } void setup() { Serial.begin(9600); screen.begin(32000000); // // WiFi.mode(WIFI_AP); // WiFi.softAP("esp32", "very gay"); // todo: automatically enable AP if configured /*Serial.print("connecting to wifi..."); if (WiFi.begin() != WL_CONNECT_FAILED) { while (WiFi.status() != WL_CONNECTED && WiFi.status() != WL_CONNECT_FAILED) { vTaskDelay(pdMS_TO_TICKS(500)); Serial.print('.'); } Serial.println(); if (WiFi.status() == WL_CONNECT_FAILED) { Serial.println("connection failed"); WiFi.enableSTA(false); } else { Serial.println("connected"); } }*/ auto hello_cmd = commander.RegisterCommand("hello", [](const std::vector ¶ms, CommanderClient *client) { client->println("world"); }); auto draw_cmd = commander.RegisterCommandWithShell("draw"); draw_cmd->SetPrompt("esp32/draw> "); draw_cmd->RegisterCommand("set-color ( | HSL | RGB )", draw_set_color); draw_cmd->RegisterCommand("fill-screen [color]", draw_fill_screen); draw_cmd->RegisterCommand("fill-rect [color]", draw_fill_rect); draw_cmd->RegisterCommand("draw-line [color]", draw_draw_line); registerWifiCommands(commander); commander.EnableSerial(); // commander.EnableWifi(5000); commander.SetPrompt("esp32> "); commander.Begin(); } void loop() { // WiFiClient client = server.available(); // if (client) { // Serial.println("[client connected]"); // while (client.connected()) { // if (client.available()) { // char c = client.read(); // Serial.write(c); // } // } // client.stop(); // Serial.println("[client disconnected]"); // } }