Skip to content

Commit

Permalink
FIX: Set API's aftercare check
Browse files Browse the repository at this point in the history
  • Loading branch information
yakumo-saki committed Mar 23, 2021
1 parent 3778faf commit 38e1a1f
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 51 deletions.
31 changes: 16 additions & 15 deletions docs/history.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Version History

* BUGFIX: Bug fix
* FIX: Fix not bug, but not friendly behavior
* FIX: Fix bug, or not friendly behavior
* CHANGE: Change some behavior
* ADD: Add new function
* DROP: Delete some functions
* NOTE: other things

## v44.0: Untitled update
## v44.0: Internal refactoring Update

NOTE: Alerts settings are back to default on version up.
IMPORTANT NOTE:
Alerts settings are back to default on version up.
Please write down current config or use backup API.

* ADD: MHZ-19B Auto Baseline Correction ON/OFF at boot time
* ADD: Skip wait for reconfigure
Expand Down Expand Up @@ -72,23 +73,23 @@ NOTE: Alerts settings are back to default on version up.
* CHANGE: SSD1306: Lux unit "lx" to "Lx" (1 and l is very similer griph)
* CHANGE: SSD1306: Draw wait for reconfigure bar using graphics
* CHANGE: ST7789: Draw wait for reconfigure bar using graphics
* BUGFIX: CONFIG: coution 2 High value is not saved. (due to insufficient buffer)
* FIX: CONFIG: coution 2 High value is not saved. (due to insufficient buffer)

## v37: Alert update.

* VERSION: 37. next version is v38.
* BUGFIX: Alert settings are not saved on ESP32.
* BUGFIX: Alert settings are not propery saved.
* FIX: Alert settings are not saved on ESP32.
* FIX: Alert settings are not propery saved.
* CHANGE: Switch to squix78 -> thingpulse (same library)
* CONFIG: Shorten JSON keys about alerts(reconfig required)

## v3.6: Bugfix release.

* NOTE: LICENSE: EnvBoyX is now under APL 2.0 , Affected to all versions. (license terms are not shown before)
* BUGFIX: TSL2561 can't enabled
* FIX: TSL2561 can't enabled
* CHANGE: Serial speed changed to 74880. (was 115200)
* BUGFIX: ping API returns invalid JSON
* BUGFIX: Display glitch when bigmode and show lux
* FIX: ping API returns invalid JSON
* FIX: Display glitch when bigmode and show lux

## v3.5

Expand All @@ -98,14 +99,14 @@ NOTE: Alerts settings are back to default on version up.
## v3.4

* CHANGE: Config: version 8 (was 6)
* BUGFIX: SSD1306 not shown in Setup Mode
* FIX: SSD1306 not shown in Setup Mode
* ADD: Default Brightness setting
* ADD: Screen Flip setting

## v3.3

* BUGFIX: MH-Z19B wrong message
* BUGFIX: Wrong uptime on JSON
* FIX: MH-Z19B wrong message
* FIX: Wrong uptime on JSON
* ADD: ST7789 Brightness change (via Web API)
* ADD: Watchdog timer (ESP32 only)
* CHANGE: Use TimerCall
Expand All @@ -114,7 +115,7 @@ NOTE: Alerts settings are back to default on version up.

* FIX: Avoid using delay
* ADD: I2C scan on startup.
* BUGFIX: ESP8266: I2C not working
* FIX: ESP8266: I2C not working
* DROP: ESP8266: ST7789 is not supported (because of Pin config)

## v3.1
Expand All @@ -137,7 +138,7 @@ NOTE: Alerts settings are back to default on version up.

## v2.6

* BUGFIX: Fix mDNS not working
* FIX: Fix mDNS not working

## v2.5

Expand Down
5 changes: 4 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <ArduinoJson.h>
#include "FS.h"

#include "config_names.h"
#include "config_values.h"

// --------------------------------------------------------------------
// ボード依存あり
// --------------------------------------------------------------------
Expand Down Expand Up @@ -45,7 +48,7 @@ bool read_config_file(File f, bool dump_config);
bool read_config_file(File f);

// APIコール用 Config->JSON
DynamicJsonDocument create_config_json(std::vector<String> keys);
DynamicJsonDocument create_config_json(std::vector<String>& keys);

// 設定保存用 Config->JSON
DynamicJsonDocument create_config_json_all();
2 changes: 1 addition & 1 deletion include/config_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class ConfigNames {
static const String ALERT_CAUTION1_HI;
static const String ALERT_CAUTION2_LO;
static const String ALERT_CAUTION2_HI;
};
};
3 changes: 2 additions & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <Arduino.h>

bool parseBooleanString(const String val);
bool parseBooleanString(const String val);
bool vectorStringContains(const std::vector<String> &keyArray, const String& key);
4 changes: 2 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ DynamicJsonDocument alerts_to_json(const config_alert_t& alerts, String logname)
return json;
}

DynamicJsonDocument _create_config_json(bool save, std::vector<String> keyArray) {
DynamicJsonDocument _create_config_json(bool save, const std::vector<String> &keyArray) {

DynamicJsonDocument json(CONF_JSON_SIZE);

Expand Down Expand Up @@ -154,7 +154,7 @@ DynamicJsonDocument _create_config_json(bool save, std::vector<String> keyArray)
return json;
}

DynamicJsonDocument create_config_json(std::vector<String> keys) {
DynamicJsonDocument create_config_json(std::vector<String> &keys) {
return _create_config_json(false, keys);
}

Expand Down
62 changes: 31 additions & 31 deletions src/network/api/http_api_config_getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "log.h"
#include "global.h"
#include "config.h"
#include "utils.h"

#include "mdns_client.h"

Expand All @@ -18,21 +19,6 @@ extern HTTPWEBSERVER server;

const String CONFIG_NONE = "#**#_##NONE##_#*#";

const std::vector<String> BLOCKED_CONFIG{ConfigNames::SSID, ConfigNames::PASSWORD, ConfigNames::OPMODE};
const std::vector<String> NEED_REBOOT_CONFIG{ConfigNames::OLED_TYPE, ConfigNames::ST7789, ConfigNames::MHZ19B,
ConfigNames::MHZ19B_PWM, ConfigNames::MHZ19B_RX, ConfigNames::MHZ19B_TX};

// 再描画が必要になる設定(Brightnessは再描画しなくても良いのだが面倒なのでこうする)
const std::vector<String> NEED_REDRAW_CONFIG{ConfigNames::ST7789_MODE, ConfigNames::DISPLAY_FLIP, ConfigNames::DISPLAY_BRIGHTNESS};

bool vectorStringContains(std::vector<String> keyArray, String key) {

for (const auto& k : keyArray) {
if (k == key) return true;
}
return false;
}

struct ConfigHookFlags {
bool needDisplayRedraw = false;
bool needMDnsRestart = false;
Expand All @@ -45,17 +31,31 @@ enum class UpdateConfigParamResult {
};

struct UpdateConfigParamResult_t {
UpdateConfigParamResult result;
String value;
UpdateConfigParamResult result = UpdateConfigParamResult::ERROR;
String value = "";
};

// 指定された項目の値を server から取り出し、追加で必要な反映処理を判定して返す
/**
* 指定された項目の値を server から取り出し、追加で必要な反映処理を判定して返す
*/
UpdateConfigParamResult_t _updateConfigParam(String key, String& config) {

// これを一番上に持っていくと、ConfigNamesの値がセットされる前に処理されてしまい、空文字列になってしまう。

std::vector<String> BLOCKED_CONFIG = {ConfigNames::SSID, ConfigNames::PASSWORD, ConfigNames::OPMODE};
std::vector<String> NEED_REBOOT_CONFIG = {ConfigNames::OLED_TYPE, ConfigNames::ST7789,
ConfigNames::MHZ19B, ConfigNames::MHZ19B_PWM,
ConfigNames::MHZ19B_RX, ConfigNames::MHZ19B_TX};

// 再描画が必要になる設定(Brightnessは再描画しなくても良いのだが面倒なのでこうする)
std::vector<String> NEED_REDRAW_CONFIG = {ConfigNames::ST7789_MODE, ConfigNames::DISPLAY_FLIP,
ConfigNames::DISPLAY_BRIGHTNESS};

//

UpdateConfigParamResult_t ret;

if (!server.hasArg(key)) {
// 指定されたキーは指定されていない(アリエナイはず)
ret.result = UpdateConfigParamResult::NOT_SPECIFIED;
ret.value = "";
return ret;
Expand All @@ -71,32 +71,33 @@ UpdateConfigParamResult_t _updateConfigParam(String key, String& config) {
config = value;
ret.value = value;

// ここから先はOK
if (vectorStringContains(NEED_REBOOT_CONFIG, key)) {
ret.result = UpdateConfigParamResult::REBOOT_REQ;
} else {

if (vectorStringContains(NEED_REDRAW_CONFIG, key)) {
ret.result = UpdateConfigParamResult::DISPLAY_REDRAW_REQ;
} else {
ret.result = UpdateConfigParamResult::OK;
}
}

if (key == ConfigNames::MDNS) {
} else if (vectorStringContains(NEED_REDRAW_CONFIG, key)) {
ret.result = UpdateConfigParamResult::DISPLAY_REDRAW_REQ;
} else if (key == ConfigNames::MDNS) {
ret.result = UpdateConfigParamResult::MDNS_RESTART_REQ;
} else {
ret.result = UpdateConfigParamResult::OK;
}

return ret;
}

// Config set API の処理
// updateConfigParam の API用ラッパー
void updateConfigParamForApi(DynamicJsonDocument& msgArray, ConfigHookFlags& flags, std::vector<String>& validKeys, String key, String& config) {
void updateConfigParamForApi(DynamicJsonDocument& msgArray, ConfigHookFlags &flags, std::vector<String>& validKeys, String key, String& config) {

UpdateConfigParamResult_t ret = _updateConfigParam(key, config);

// int retnum = static_cast<int>(ret.result);
// debuglog("RET RESULT = " + String(retnum));

if (ret.result == UpdateConfigParamResult::NOT_SPECIFIED) {
return;
} else if (ret.result == UpdateConfigParamResult::ERROR) {
debuglog("ERROR " + key);
}

// 有効な設定名だったので記録しておく
Expand Down Expand Up @@ -134,7 +135,6 @@ void updateConfigAlerts(DynamicJsonDocument& msgs, ConfigHookFlags& flags, std::
}

void _reflectConfig(ConfigHookFlags& flags, bool all = false) {
// debuglog(String(flags.needDisplayRedraw) + String(flags.needMDnsRestart));

if (all || flags.needDisplayRedraw) {
apilog("Exec display redraw.");
Expand Down
16 changes: 16 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <Arduino.h>

#include "log.h"

bool parseBooleanString(const String val) {

// String is null or invalid
Expand All @@ -20,3 +22,17 @@ bool parseBooleanString(const String val) {

return false;
}

//
bool vectorStringContains(const std::vector<String> &keyArray, const String& key) {

for (const String k : keyArray) {
debuglog(k);
if (k == key) {
debuglog("return true " + key);
return true;
}
}
debuglog("return false " + key);
return false;
}

0 comments on commit 38e1a1f

Please sign in to comment.