added primitive read of laser return (poc for future preset feature)

This commit is contained in:
fryakatkop
2017-10-21 20:11:05 +02:00
parent 0afd34f134
commit bbc3b195da

View File

@@ -16,13 +16,13 @@ SoftwareSerial laserSerial(14, 12, false, 256);
String ssid = ""; String ssid = "";
String password = ""; String password = "";
int apMode = 1; // 0: client, 1: AP (default) // will be overwriten int apMode = 1; // 0: client, 1: AP (default) // will be overwriten
int apModeRuntime = 0; int apModeRuntime = 0;
int wifiTimeout = 10000; //ms int wifiTimeout = 10000; //ms
// [0] laser[1] m1 [2] m2 [3] m3 // [0] laser[1] m1 [2] m2 [3] m3
byte lmValues[4] = {0,0,0,0}; byte lmValues[4] = {0, 0, 0, 0};
/* Soft AP network parameters */ /* Soft AP network parameters */
@@ -119,7 +119,7 @@ void handleFileList() {
void handleLaser(String uri) void handleLaser(String uri)
{ {
String laserValue = uri.substring(7); String laserValue = uri.substring(7);
if(laserValue.toInt() > 128) { if (laserValue.toInt() > 128) {
lmValues[0] = 128; lmValues[0] = 128;
laserValue = "128"; laserValue = "128";
} }
@@ -127,7 +127,7 @@ void handleLaser(String uri)
{ {
lmValues[0] = laserValue.toInt(); lmValues[0] = laserValue.toInt();
} }
String msg = "AT SLV "; String msg = "AT SLV ";
msg += laserValue; msg += laserValue;
@@ -145,8 +145,8 @@ void handleLaser(String uri)
void handleMotor(String uri) void handleMotor(String uri)
{ {
String motorNr = uri.substring(7, 8); String motorNr = uri.substring(7, 8);
String motorValue = uri.substring(9); String motorValue = uri.substring(9);
if(motorValue.toInt() > 128) { if (motorValue.toInt() > 128) {
lmValues[motorNr.toInt()] = 128; lmValues[motorNr.toInt()] = 128;
motorValue = "128"; motorValue = "128";
} }
@@ -172,18 +172,18 @@ void handleMotor(String uri)
} }
void handleReadValues() void handleReadValues()
{ {
String json = "{ \"handledReadValues\":"; String json = "{ \"handledReadValues\":";
json += "{\"laser\":\"" + (String)lmValues[0] + "\","; json += "{\"laser\":\"" + (String)lmValues[0] + "\",";
json += "\"motors\": {\"1\":\"" + (String)lmValues[1] + "\","; json += "\"motors\": {\"1\":\"" + (String)lmValues[1] + "\",";
json += "\"2\":\"" + (String)lmValues[2] + "\","; json += "\"2\":\"" + (String)lmValues[2] + "\",";
json += "\"3\":\"" + (String)lmValues[3] + "\"}}}"; json += "\"3\":\"" + (String)lmValues[3] + "\"}}}";
server.send(200, "text/json", json); server.send(200, "text/json", json);
json = String(); json = String();
} }
void handleReadWifi() void handleReadWifi()
{ {
String json = "{ \"handledReadWifi\":"; String json = "{ \"handledReadWifi\":";
json += "{\"apMode\":\"" + (String)apMode + "\","; json += "{\"apMode\":\"" + (String)apMode + "\",";
json += "\"ssid\":\"" + (String)ssid + "\","; json += "\"ssid\":\"" + (String)ssid + "\",";
@@ -325,18 +325,19 @@ boolean setupWifi() {
void setup(void) { void setup(void) {
laserSerial.begin(9600); laserSerial.begin(9600);
laserSerial.flush();
Serial.begin(115200); Serial.begin(115200);
Serial.print("\n"); Serial.print("\n");
SPIFFS.begin(); SPIFFS.begin();
// { // {
// Dir dir = SPIFFS.openDir("/"); // Dir dir = SPIFFS.openDir("/");
// while (dir.next()) { // while (dir.next()) {
// String fileName = dir.fileName(); // String fileName = dir.fileName();
// size_t fileSize = dir.fileSize(); // size_t fileSize = dir.fileSize();
// Serial.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str()); // Serial.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
// } // }
// Serial.printf("\n"); // Serial.printf("\n");
// } // }
//WIFI INIT //WIFI INIT
WiFi.disconnect(); WiFi.disconnect();
@@ -413,8 +414,8 @@ void handleNotFound() {
handleApmode(uri); handleApmode(uri);
return; return;
} }
if (uri.substring(0,12) == "/config.json") if (uri.substring(0, 12) == "/config.json")
{ {
server.send(403, "text/plain", "Forbidden"); server.send(403, "text/plain", "Forbidden");
return; return;
} }
@@ -427,6 +428,29 @@ void handleNotFound() {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
int i = 0;
char commandbuffer[100];
String sBuffer;
if (laserSerial.available()) {
delay(100);
while ( laserSerial.available() && i < 99) {
commandbuffer[i] = laserSerial.read();
i++;
}
commandbuffer[i++] = '\0';
}
if (i > 0)
{
delay(200);
Serial.print("received from laser: ");
Serial.println((char*)commandbuffer);
// Serial.println(()sBuffer);
}
} }