mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-02-19 23:46:02 +01:00
Display class
This commit is contained in:
parent
48d03cc82f
commit
086c78f58f
40
Display.cpp
Normal file
40
Display.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* © 2020, Harald Barth.
|
||||||
|
*
|
||||||
|
* This file is part of Asbelos DCC API
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* It is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Display.h"
|
||||||
|
#include "DIAG.h"
|
||||||
|
|
||||||
|
void Display::displayIP(byte ip[4]) {
|
||||||
|
if (ip != NULL)
|
||||||
|
LCD(6,F("%d.%d.%d.%d"),ip[0],ip[1],ip[2],ip[3]);
|
||||||
|
else
|
||||||
|
LCD(6,F("NO IP"));
|
||||||
|
}
|
||||||
|
void Display::displayIP(char *ip) {
|
||||||
|
if (ip != NULL)
|
||||||
|
LCD(6,F("%s"),ip);
|
||||||
|
else
|
||||||
|
LCD(6,F("NO IP"));
|
||||||
|
}
|
||||||
|
void Display::displayPort(int i) {
|
||||||
|
if (i > 0)
|
||||||
|
LCD(7,F(":%d"),i);
|
||||||
|
else
|
||||||
|
LCD(7,F("none"));
|
||||||
|
}
|
29
Display.h
Normal file
29
Display.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* © 2020, Harald Barth.
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* It is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef Display_h
|
||||||
|
#define Display_h
|
||||||
|
|
||||||
|
class Display {
|
||||||
|
public:
|
||||||
|
void displayIP(byte[4]);
|
||||||
|
void displayIP(char *);
|
||||||
|
void displayPort(int);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif
|
@ -22,8 +22,8 @@
|
|||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
#include "WifiInboundHandler.h"
|
#include "WifiInboundHandler.h"
|
||||||
|
#include "Display.h"
|
||||||
|
|
||||||
const char PROGMEM READY_SEARCH[] = "\r\nready\r\n";
|
const char PROGMEM READY_SEARCH[] = "\r\nready\r\n";
|
||||||
const char PROGMEM OK_SEARCH[] = "\r\nOK\r\n";
|
const char PROGMEM OK_SEARCH[] = "\r\nOK\r\n";
|
||||||
@ -33,6 +33,10 @@ const char PROGMEM IPD_SEARCH[] = "+IPD";
|
|||||||
const unsigned long LOOP_TIMEOUT = 2000;
|
const unsigned long LOOP_TIMEOUT = 2000;
|
||||||
bool WifiInterface::connected = false;
|
bool WifiInterface::connected = false;
|
||||||
Stream * WifiInterface::wifiStream;
|
Stream * WifiInterface::wifiStream;
|
||||||
|
wifiESPMode WifiInterface::wifiMode = WIFIMODE_UNKNOWN;
|
||||||
|
char WifiInterface::ip[16] = "\0234567890123456";
|
||||||
|
//char WifiInterface::ip[0] = 0;
|
||||||
|
int WifiInterface::wifiPort = 0;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -121,6 +125,9 @@ wifiSerialState WifiInterface::setup(Stream & setupStream, const __FlashStringH
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wifiState == WIFI_CONNECTED) {
|
if (wifiState == WIFI_CONNECTED) {
|
||||||
|
/// test here
|
||||||
|
SetIP();
|
||||||
|
DisplayIP();
|
||||||
StringFormatter::send(wifiStream, F("ATE0\r\n")); // turn off the echo
|
StringFormatter::send(wifiStream, F("ATE0\r\n")); // turn off the echo
|
||||||
checkForOK(200, OK_SEARCH, true);
|
checkForOK(200, OK_SEARCH, true);
|
||||||
}
|
}
|
||||||
@ -286,7 +293,49 @@ void WifiInterface::ATCommand(const byte * command) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WifiInterface::SetIP() {
|
||||||
|
|
||||||
|
StringFormatter::send(wifiStream, F("AT+CIFSR\r\n"));
|
||||||
|
if (!checkForOK(10000, (const char *)F("+CIFSR:"), true, false))
|
||||||
|
return;
|
||||||
|
// now we should be at APIP," or STAIP,"
|
||||||
|
char c = ':';
|
||||||
|
char oldc = ':';
|
||||||
|
while (c != '"') {
|
||||||
|
while (!wifiStream->available());
|
||||||
|
switch(c = wifiStream->read()) {
|
||||||
|
case 'T':
|
||||||
|
if (oldc == 'S') wifiMode = WIFIMODE_STA;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
if (oldc == 'A') wifiMode = WIFIMODE_AP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// ignore other chars
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
oldc = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte i=0;
|
||||||
|
for (;;) {
|
||||||
|
while(!wifiStream->available());
|
||||||
|
ip[i]=wifiStream->read();
|
||||||
|
if (ip[i] == '"' || i >= 15) {
|
||||||
|
ip[i]='\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WifiInterface::DisplayIP() {
|
||||||
|
//XXXX here I want to something like Display::displayIP(ip);
|
||||||
|
if (wifiMode == WIFIMODE_STA)
|
||||||
|
LCD(3,F("WifiCLIENT"));
|
||||||
|
else
|
||||||
|
LCD(3,F("AP"));
|
||||||
|
}
|
||||||
|
|
||||||
bool WifiInterface::checkForOK( const unsigned int timeout, const char * waitfor, bool echo, bool escapeEcho) {
|
bool WifiInterface::checkForOK( const unsigned int timeout, const char * waitfor, bool echo, bool escapeEcho) {
|
||||||
unsigned long startTime = millis();
|
unsigned long startTime = millis();
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
enum wifiSerialState { WIFI_NOAT, WIFI_DISCONNECTED, WIFI_CONNECTED };
|
enum wifiSerialState { WIFI_NOAT, WIFI_DISCONNECTED, WIFI_CONNECTED };
|
||||||
|
enum wifiESPMode { WIFIMODE_UNKNOWN = 0, WIFIMODE_STA = 1, WIFIMODE_AP = 2 };
|
||||||
|
|
||||||
class WifiInterface
|
class WifiInterface
|
||||||
{
|
{
|
||||||
@ -37,7 +38,8 @@ public:
|
|||||||
const int port = 2560);
|
const int port = 2560);
|
||||||
static void loop();
|
static void loop();
|
||||||
static void ATCommand(const byte *command);
|
static void ATCommand(const byte *command);
|
||||||
|
static void SetIP();
|
||||||
|
static void DisplayIP();
|
||||||
private:
|
private:
|
||||||
static wifiSerialState setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
static wifiSerialState setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||||
const __FlashStringHelper *hostname, int port);
|
const __FlashStringHelper *hostname, int port);
|
||||||
@ -52,5 +54,8 @@ private:
|
|||||||
static int datalength;
|
static int datalength;
|
||||||
static int connectionId;
|
static int connectionId;
|
||||||
static unsigned long loopTimeoutStart;
|
static unsigned long loopTimeoutStart;
|
||||||
|
static wifiESPMode wifiMode;
|
||||||
|
static char ip[16];
|
||||||
|
static int wifiPort;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user