wrong pin error warning added

This commit is contained in:
Dmitry Borisenko
2020-12-18 23:20:42 +01:00
parent 19f728e209
commit 433d28a785
7 changed files with 72 additions and 28 deletions

Binary file not shown.

View File

@@ -60,6 +60,10 @@
"type": "text",
"title": "{{warning2}}"
},
{
"type": "text",
"title": "{{warning3}}"
},
{
"type": "hr"
},

Binary file not shown.

View File

@@ -1,12 +1,12 @@
#pragma once
#include <Arduino.h>
#include "ItemsList.h"
#include "Global.h"
#include "Utils/JsonUtils.h"
class LineParsing {
protected:
protected:
String _key;
String _file;
String _page;
@@ -26,29 +26,33 @@ class LineParsing {
String _val;
String _index;
public:
int pinErrors;
public:
LineParsing() :
_key{""},
_file{""},
_page{""},
_descr{""},
_order{""},
_addr{""},
_reg{""},
_pin{""},
_map{""},
_c{""},
_inv{""},
_state{""},
_db{""},
_type{""},
_int{""},
_cnt{""},
_val{""},
_index{""}
_key{ "" },
_file{ "" },
_page{ "" },
_descr{ "" },
_order{ "" },
_addr{ "" },
_reg{ "" },
_pin{ "" },
_map{ "" },
_c{ "" },
_inv{ "" },
_state{ "" },
_db{ "" },
_type{ "" },
_int{ "" },
_cnt{ "" },
_val{ "" },
_index{ "" },
{};
pinErrors{ 0 }
{};
void update() {
//String order = sCmd.order();
@@ -106,17 +110,19 @@ class LineParsing {
}
}
if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) {
pinErrors++;
_pin = "";
}
_page.replace("#", " ");
_descr.replace("#", " ");
_descr.replace("%ver%", String(FIRMWARE_VERSION));
_descr.replace("%name%", jsonReadStr(configSetupJson, F("name")));
createWidget(_descr, _page, _order, _file, _key);
}
//jsonWriteStr(configOptionJson, _key + "_pin", _pin);
String gkey() {
return _key;
@@ -171,6 +177,15 @@ class LineParsing {
}
int getPinErrors() {
return pinErrors;
}
void clearErrors() {
pinErrors = 0;
}
void clear() {
_key = "";
_file = "";
@@ -205,7 +220,7 @@ class LineParsing {
return;
}
if(filename.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
if (filename.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
jsonWriteStr(buf, "page", page);
jsonWriteStr(buf, "order", order);

View File

@@ -12,4 +12,5 @@ extern void delChoosingItems();
extern void delAllItems();
extern uint8_t getNewElementNumber(String file);
extern uint8_t getFreePinAll();
extern bool isPinExist(unsigned int num);
extern uint8_t getFreePinAnalog();

View File

@@ -2,6 +2,7 @@
#include "BufferExecute.h"
#include "Cmd.h"
#include "Global.h"
#include "Class/LineParsing.h"
#include "items/vLogging.h"
#include "items/vImpulsOut.h"
#include "items/vButtonOut.h"
@@ -20,6 +21,7 @@ void loadConfig() {
jsonWriteStr(configSetupJson, "warning1", "");
jsonWriteStr(configSetupJson, "warning2", "");
jsonWriteStr(configSetupJson, "warning3", "");
jsonWriteStr(configSetupJson, "chipID", chipId);
jsonWriteInt(configSetupJson, "firmware_version", FIRMWARE_VERSION);
@@ -76,13 +78,13 @@ void deviceInit() {
inOutput_KeyList = "";
inOutput_EnterCounter = -1;
//======clear pwm params=======
#ifdef PwmOutEnable
#ifdef PwmOutEnable
if (myPwmOut != nullptr) {
myPwmOut->clear();
}
pwmOut_KeyList = "";
pwmOut_EnterCounter = -1;
#endif
#endif
//===================================
if (myCountDown != nullptr) {
myCountDown->clear();
@@ -97,8 +99,20 @@ void deviceInit() {
#else
removeFile(String("layout.txt"));
#endif
myLineParsing.clearErrors();
fileCmdExecute(String(DEVICE_CONFIG_FILE));
int errors = myLineParsing.getPinErrors();
if (errors != 0) {
jsonWriteStr(configSetupJson, F("warning3"), F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Обнаружен неверный номер пина</p></font></div>"));
}
else {
jsonWriteStr(configSetupJson, F("warning3"), "");
}
//outcoming_date();
}
//-------------------------------сценарии-----------------------------------------------------

View File

@@ -143,6 +143,16 @@ uint8_t getFreePinAll() {
}
}
bool isPinExist(unsigned int num) {
bool ret = false;
unsigned int pins[] = { 0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16 };
uint8_t array_sz = sizeof(pins) / sizeof(pins[0]);
for (uint8_t i = 0; i < array_sz; i++) {
if (pins[i] == num) ret = true;
}
return ret;
}
uint8_t getFreePinAnalog() {
#ifdef ESP8266
return 0;