From 816c9d566373f2fee187fcfbd4438d375e112163 Mon Sep 17 00:00:00 2001 From: jc4419 <60656643+jc4419@users.noreply.github.com> Date: Mon, 31 May 2021 21:49:50 +0400 Subject: [PATCH] Fixed some syntax errors in the js code for the webpage. Also added mouse click support for the arrow keys. Added some commented code that can be uncommented for connecting the esp32 to a wifi router instead of AP mode. --- Command/index.html | 84 +++++++++++++++++++++---------- Command/main/main.ino | 112 +++++++++++++++++++++++++++++++----------- 2 files changed, 143 insertions(+), 53 deletions(-) diff --git a/Command/index.html b/Command/index.html index a5421ed..b242ae1 100644 --- a/Command/index.html +++ b/Command/index.html @@ -9,7 +9,7 @@ box-sizing: border-box; } -.section-container { +.section_container { float: left; width: 50%; padding: 10px; @@ -32,11 +32,11 @@ li { :is(h1, h2, h3, h4, h5, h6, label, strong, meter) { font-family: Arial, Helvetica, sans-serif; } -.movement-control { +.movement_control { text-align: center; } -.sensor-data { +.sensor_data { text-align: center; } @@ -157,22 +157,57 @@ function down_unpressed(){ send_data(); } +var timer = null; + +function up_mouseDown() { + timer = setInterval(up_pressed, 100); +} +function up_mouseUp() { + clearInterval(timer); + up_unpressed(); +} + +function down_mouseDown() { + timer = setInterval(down_pressed, 100); +} +function down_mouseUp() { + clearInterval(timer); + down_unpressed(); +} + +function right_mouseDown() { + timer = setInterval(right_pressed, 100); +} +function right_mouseUp() { + clearInterval(timer); + right_unpressed(); +} + +function left_mouseDown() { + timer = setInterval(left_pressed, 100); +} +function left_mouseUp() { + clearInterval(timer); + left_unpressed(); +} + + document.onkeydown = function(e) { switch (e.keyCode) { case 37: - document.getElementById("left-arrow").className = "button pressed"; + document.getElementById("left_arrow").className = "button pressed"; left_pressed(); break; case 38: - document.getElementById("up-arrow").className = "button pressed"; + document.getElementById("up_arrow").className = "button pressed"; up_pressed(); break; case 39: - document.getElementById("right-arrow").className = "button pressed"; + document.getElementById("right_arrow").className = "button pressed"; right_pressed(); break; case 40: - document.getElementById("down-arrow").className = "button pressed"; + document.getElementById("down_arrow").className = "button pressed"; down_pressed(); break; } @@ -180,19 +215,19 @@ document.onkeydown = function(e) { document.onkeyup = function(e) { switch (e.keyCode) { case 37: - document.getElementById("left-arrow").className = "button"; + document.getElementById("left_arrow").className = "button"; left_unpressed(); break; case 38: - document.getElementById("up-arrow").className = "button"; + document.getElementById("up_arrow").className = "button"; up_unpressed(); break; case 39: - document.getElementById("right-arrow").className = "button"; + document.getElementById("right_arrow").className = "button"; right_unpressed(); break; case 40: - document.getElementById("down-arrow").className = "button"; + document.getElementById("down_arrow").className = "button"; down_unpressed(); break; } @@ -206,39 +241,39 @@ document.onkeyup = function(e) {
-
-
+
+

Movement Control

- +
- - - + + +
-
-
+
+

Sensor Data

    -
  • +
  • -
    +
  • -
  • +
  • -
    +
    28mm
  • @@ -250,6 +285,5 @@ document.onkeyup = function(e) {
- - + \ No newline at end of file diff --git a/Command/main/main.ino b/Command/main/main.ino index c330a25..eeb90bb 100644 --- a/Command/main/main.ino +++ b/Command/main/main.ino @@ -12,6 +12,9 @@ const int L_Led = 12; //LED subsitute for the 'movement left command'. const int R_Led = 15; //LED subsitute for the 'movement right command'. const int D_Led = 13; //LED subsitute for the 'movement back command'. +/* const char* ssid = "ssid"; +const char* password = "xxxxxxxx"; */ + int potVal = 0; bool butState = 1; //Variables only for testing - will be removed in final @@ -33,7 +36,7 @@ char index_html[] PROGMEM = R"=====( box-sizing: border-box; } -.section-container { +.section_container { float: left; width: 50%; padding: 10px; @@ -56,11 +59,11 @@ li { :is(h1, h2, h3, h4, h5, h6, label, strong, meter) { font-family: Arial, Helvetica, sans-serif; } -.movement-control { +.movement_control { text-align: center; } -.sensor-data { +.sensor_data { text-align: center; } @@ -181,22 +184,57 @@ function down_unpressed(){ send_data(); } +var timer = null; + +function up_mouseDown() { + timer = setInterval(up_pressed, 100); +} +function up_mouseUp() { + clearInterval(timer); + up_unpressed(); +} + +function down_mouseDown() { + timer = setInterval(down_pressed, 100); +} +function down_mouseUp() { + clearInterval(timer); + down_unpressed(); +} + +function right_mouseDown() { + timer = setInterval(right_pressed, 100); +} +function right_mouseUp() { + clearInterval(timer); + right_unpressed(); +} + +function left_mouseDown() { + timer = setInterval(left_pressed, 100); +} +function left_mouseUp() { + clearInterval(timer); + left_unpressed(); +} + + document.onkeydown = function(e) { switch (e.keyCode) { case 37: - document.getElementById("left-arrow").className = "button pressed"; + document.getElementById("left_arrow").className = "button pressed"; left_pressed(); break; case 38: - document.getElementById("up-arrow").className = "button pressed"; + document.getElementById("up_arrow").className = "button pressed"; up_pressed(); break; case 39: - document.getElementById("right-arrow").className = "button pressed"; + document.getElementById("right_arrow").className = "button pressed"; right_pressed(); break; case 40: - document.getElementById("down-arrow").className = "button pressed"; + document.getElementById("down_arrow").className = "button pressed"; down_pressed(); break; } @@ -204,19 +242,19 @@ document.onkeydown = function(e) { document.onkeyup = function(e) { switch (e.keyCode) { case 37: - document.getElementById("left-arrow").className = "button"; + document.getElementById("left_arrow").className = "button"; left_unpressed(); break; case 38: - document.getElementById("up-arrow").className = "button"; + document.getElementById("up_arrow").className = "button"; up_unpressed(); break; case 39: - document.getElementById("right-arrow").className = "button"; + document.getElementById("right_arrow").className = "button"; right_unpressed(); break; case 40: - document.getElementById("down-arrow").className = "button"; + document.getElementById("down_arrow").className = "button"; down_unpressed(); break; } @@ -230,39 +268,39 @@ document.onkeyup = function(e) {
-
-
+
+

Movement Control

- +
- - - + + +
-
-
+
+

Sensor Data

    -
  • +
  • -
    +
  • -
  • +
  • -
    +
    28mm
  • @@ -274,7 +312,6 @@ document.onkeyup = function(e) {
- @@ -336,6 +373,26 @@ void setup() pinMode(D_Led,OUTPUT); pinMode(butPin, INPUT_PULLUP); + +/* Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("Rover connected to "); + Serial.println(ssid); + Serial.println(); + Serial.println("Rover IP address: "); + Serial.println(WiFi.localIP()); */ + WiFi.softAP("RoverAP", "SplendidCheeks"); Serial.println(); Serial.println("RoverAP running"); @@ -360,7 +417,7 @@ void setup() server.onNotFound(notFound); - server.begin(); // it will start webserver + server.begin(); websockets.begin(); websockets.onEvent(webSocketEvent); timer.attach(0.5,send_sensor_data); @@ -385,7 +442,6 @@ void send_sensor_data() JSON_Data += potVal; JSON_Data += ",\"ODO_DIST\":"; JSON_Data += d; - JSON_Data += "}"; - //Serial.println(JSON_Data); + JSON_Data += "}"; websockets.broadcastTXT(JSON_Data); -} \ No newline at end of file +}