浏览代码

Added web page for rgb2hdmo

Per Mårtensson 3 年之前
父节点
当前提交
0d557854f0

+ 3 - 3
sw/key800/include/abc800_gpio.h

@@ -15,9 +15,9 @@
 #define A800_TRXC           4
 
 #define KEY800_LED          18
-#define KEY800_RST_BUTTON   14
-#define KEY800_UP_BUTTON    13
-#define KEY800_DOWN_BUTTON  12
+#define KEY800_MENU_BUTTON  14
+#define KEY800_UP_BUTTON    12
+#define KEY800_DOWN_BUTTON  13
 
 #define KEY800_PWM_CHANNEL  0
 #define KEY800_PWM_FREQ     10000

+ 2 - 2
sw/key800/include/abc800_web.h

@@ -13,10 +13,10 @@ namespace abc800
             bool connected = false;
             void fbuttonsinit();
             void initWebSocket();
-            
+            void handleWebSocketMessage(void *arg, uint8_t *data, size_t len);
         private:
             void notifyClients();
-            void handleWebSocketMessage(void *arg, uint8_t *data, size_t len);
+            
             void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type,void *arg, uint8_t *data, size_t len);
             
             String processor(const String& var);

+ 19 - 9
sw/key800/include/abc800_webcontent.h

@@ -1,7 +1,7 @@
 #ifndef __ABC800_WEBCONTENT_H
 #define __ABC800_WEBCONTENT_H
 #include <ArduinoOTA.h>
-const char index_html[] PROGMEM = R"rawliteral(
+const char rgbtohdmi[] PROGMEM = R"rawliteral(
 <!DOCTYPE HTML><html>
 <head>
   <title>ABC800 keyboard controller</title>
@@ -41,6 +41,7 @@ const char index_html[] PROGMEM = R"rawliteral(
   }
   .button {
     padding: 15px 50px;
+    width: 400px;
     font-size: 24px;
     text-align: center;
     outline: none;
@@ -68,19 +69,20 @@ const char index_html[] PROGMEM = R"rawliteral(
      font-weight: bold;
    }
   </style>
-<title>ABC800 Keyboard controller</title>
+<title>ABC800 Keyboard RGBtoHDMI</title>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="icon" href="data:,">
 </head>
 <body>
   <div class="topnav">
-    <h1>ABC80 Keyboard controller</h1>
+    <h1>ABC800 Keyboard RGBtoHDMI</h1>
   </div>
   <div class="content">
     <div class="card">
-      <h2>Output - GPIO 2</h2>
-      <p class="state">state: <span id="state">%STATE%</span></p>
-      <p><button id="button" class="button">Toggle</button></p>
+      <h2>RGBtoHDMI</h2>
+      <p><button id="button_menu" class="button">Menu</button></p>
+      <p><button id="button_up" class="button">Up / Genlock</button></p>
+      <p><button id="button_down" class="button">Down / Screen Capture</button></p>
     </div>
   </div>
 <script>
@@ -116,10 +118,18 @@ const char index_html[] PROGMEM = R"rawliteral(
     initButton();
   }
   function initButton() {
-    document.getElementById('button').addEventListener('click', toggle);
+    document.getElementById('button_menu').addEventListener('click', button_menu);
+    document.getElementById('button_up').addEventListener('click', button_up);
+    document.getElementById('button_down').addEventListener('click', button_down);
   }
-  function toggle(){
-    websocket.send('toggle');
+  function button_menu(){
+    websocket.send('button_menu');
+  }
+  function button_up(){
+    websocket.send('button_up');
+  }
+  function button_down(){
+    websocket.send('button_down');
   }
 </script>
 </body>

+ 1 - 1
sw/key800/src/abc800_gpio.cpp

@@ -34,7 +34,7 @@ namespace abc800 {
         pinMode(A800_TRXC ,OUTPUT);
         pinMode(K800_KD ,INPUT);
         pinMode(A800_KD ,OUTPUT);
-        pinMode(KEY800_RST_BUTTON,INPUT);
+        pinMode(KEY800_MENU_BUTTON,INPUT);
         pinMode(KEY800_UP_BUTTON,INPUT);
         pinMode(KEY800_DOWN_BUTTON,INPUT);
         //Attach PWM

+ 3 - 3
sw/key800/src/abc800_keyboard.cpp

@@ -216,10 +216,10 @@ namespace abc800
         }
         if (keyqueue.special == 0x42 && (keyqueue.modifier == 0x06 ||  keyqueue.modifier == 0x36)) //F9 + alt +shift
         {
-            pinMode(KEY800_RST_BUTTON,OUTPUT);
-            digitalWrite(KEY800_RST_BUTTON,LOW);
+            pinMode(KEY800_MENU_BUTTON,OUTPUT);
+            digitalWrite(KEY800_MENU_BUTTON,LOW);
             delay(100);
-            pinMode(KEY800_RST_BUTTON,INPUT);
+            pinMode(KEY800_MENU_BUTTON,INPUT);
         }
         if (keyqueue.special == 0x43 && (keyqueue.modifier == 0x06 ||  keyqueue.modifier == 0x36)) //F10 + alt +shift
         {

+ 44 - 11
sw/key800/src/abc800_web.cpp

@@ -8,6 +8,7 @@
 #include "abc800_func.h"
 #include "abc800_webcontent.h"
 #include "abc800_hidboot.h"
+#include "abc800_gpio.h"
 #include <WebSerial.h>
 #include "ESPAsyncWiFiManager.h"
 static const char TAG[] = __FILE__;
@@ -23,8 +24,26 @@ extern AsyncElegantOtaClass AsyncElegantOTA;
 extern DNSServer dns;
 extern AsyncWiFiManager wifiManager;
 extern AsyncWebSocket ws("/ws");
-
-
+bool connected2=false;
+bool ledState;
+ static   void web_onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type,void *arg, uint8_t *data, size_t len) {
+        switch (type) {
+            case WS_EVT_CONNECT:
+            ESP_LOGI(TAG,"WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
+            connected2 = true;
+            break;
+            case WS_EVT_DISCONNECT:
+            ESP_LOGI(TAG,"WebSocket client #%u disconnected\n", client->id());
+            connected2 = false;
+            break;
+            case WS_EVT_DATA:
+            abc800_web.handleWebSocketMessage(arg, data, len);
+            break;
+            case WS_EVT_PONG:
+            case WS_EVT_ERROR:
+            break;
+        }
+ }
 namespace abc800
 {
     void OTAtask(void * parameter){
@@ -61,27 +80,41 @@ namespace abc800
     
     
     void web::notifyClients() {
-        //ws.textAll(String(ledState));
+        ws.textAll(String(ledState));
     }
 
     void web::handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
         AwsFrameInfo *info = (AwsFrameInfo*)arg;
         if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
             data[len] = 0;
-            if (strcmp((char*)data, "toggle") == 0) {
-            //ledState = !ledState;
-            notifyClients();
+            if (strcmp((char*)data, "button_up") == 0) {
+                pinMode(KEY800_UP_BUTTON,OUTPUT);
+                digitalWrite(KEY800_UP_BUTTON,LOW);
+                delay(100);
+                pinMode(KEY800_UP_BUTTON,INPUT);
+            }
+            if (strcmp((char*)data, "button_down") == 0) {
+                pinMode(KEY800_DOWN_BUTTON,OUTPUT);
+                digitalWrite(KEY800_DOWN_BUTTON,LOW);
+                delay(100);
+                pinMode(KEY800_DOWN_BUTTON,INPUT);
+            }
+            if (strcmp((char*)data, "button_menu") == 0) {
+                pinMode(KEY800_MENU_BUTTON,OUTPUT);
+                digitalWrite(KEY800_MENU_BUTTON,LOW);
+                delay(100);
+                pinMode(KEY800_MENU_BUTTON,INPUT);
             }
         }
     }
     void web::onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type,void *arg, uint8_t *data, size_t len) {
         switch (type) {
             case WS_EVT_CONNECT:
-            Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
+            ESP_LOGI(TAG,"WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
             connected = true;
             break;
             case WS_EVT_DISCONNECT:
-            Serial.printf("WebSocket client #%u disconnected\n", client->id());
+            ESP_LOGI(TAG,"WebSocket client #%u disconnected\n", client->id());
             connected = false;
             break;
             case WS_EVT_DATA:
@@ -94,7 +127,7 @@ namespace abc800
     }
 
     void web::initWebSocket() {
-        //ws.onEvent(abc800_web.onEvent);
+        ws.onEvent(web_onEvent);
         server.addHandler(&ws);
     }
     String web::processor(const String& var){
@@ -143,8 +176,8 @@ namespace abc800
         initWebSocket();
 
         // Route for root / web page
-        server.on("/command", HTTP_GET, [](AsyncWebServerRequest *request){
-            request->send_P(200, "text/html", index_html);//, processor);
+        server.on("/rgbtohdmi", HTTP_GET, [](AsyncWebServerRequest *request){
+            request->send_P(200, "text/html", rgbtohdmi);//, processor);
         });
 
         // Start ElegantOTA