mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Add Button to dynamically load GPIO Viewer with Berry backend (#20424)
This commit is contained in:
parent
d51340961f
commit
aa1dd392ca
@ -35,6 +35,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- HASPmota `haspmota.page_show()` to change page (#20333)
|
- HASPmota `haspmota.page_show()` to change page (#20333)
|
||||||
- Berry `introspect.set()` for class attributes (#20339)
|
- Berry `introspect.set()` for class attributes (#20339)
|
||||||
- Support negative power on BL0942 using index 5..8 (#20322)
|
- Support negative power on BL0942 using index 5..8 (#20322)
|
||||||
|
- Button to dynamically load GPIO Viewer with Berry backend
|
||||||
|
|
||||||
### Breaking Changed
|
### Breaking Changed
|
||||||
- Refactoring of Berry `animate` module for WS2812 Leds (#20236)
|
- Refactoring of Berry `animate` module for WS2812 Leds (#20236)
|
||||||
|
@ -1146,6 +1146,8 @@
|
|||||||
#define USE_BERRY_WEBCLIENT_TIMEOUT 2000 // Default timeout in milliseconds
|
#define USE_BERRY_WEBCLIENT_TIMEOUT 2000 // Default timeout in milliseconds
|
||||||
//#define USE_BERRY_PARTITION_WIZARD // Add a button to dynamically load the Partion Wizard from a bec file online (+1.3KB Flash)
|
//#define USE_BERRY_PARTITION_WIZARD // Add a button to dynamically load the Partion Wizard from a bec file online (+1.3KB Flash)
|
||||||
#define USE_BERRY_PARTITION_WIZARD_URL "http://ota.tasmota.com/tapp/partition_wizard.bec"
|
#define USE_BERRY_PARTITION_WIZARD_URL "http://ota.tasmota.com/tapp/partition_wizard.bec"
|
||||||
|
//#define USE_BERRY_GPIOVIEWER // Add a button to dynamocally load the GPIO Viewer from a bec file online
|
||||||
|
#define USE_BERRY_GPIOVIEWER_URL "http://ota.tasmota.com/tapp/gpioviewer.bec"
|
||||||
#define USE_BERRY_TCPSERVER // Enable TCP socket server (+0.6k)
|
#define USE_BERRY_TCPSERVER // Enable TCP socket server (+0.6k)
|
||||||
// #define USE_BERRY_ULP // Enable ULP (Ultra Low Power) support (+4.9k)
|
// #define USE_BERRY_ULP // Enable ULP (Ultra Low Power) support (+4.9k)
|
||||||
// Berry crypto extensions below:
|
// Berry crypto extensions below:
|
||||||
|
@ -96,6 +96,9 @@ public:
|
|||||||
#ifdef USE_BERRY_PARTITION_WIZARD
|
#ifdef USE_BERRY_PARTITION_WIZARD
|
||||||
bool partition_wizard_loaded = false; // did we already load Parition_Wizard
|
bool partition_wizard_loaded = false; // did we already load Parition_Wizard
|
||||||
#endif // USE_BERRY_PARTITION_WIZARD
|
#endif // USE_BERRY_PARTITION_WIZARD
|
||||||
|
#ifdef USE_BERRY_GPIOVIEWER
|
||||||
|
bool gpviewer_loaded = false; // did we already load GPIOViewer
|
||||||
|
#endif // USE_BERRY_GPIOVIEWER
|
||||||
bool autoexec_done = false; // do we still need to load 'autoexec.be'
|
bool autoexec_done = false; // do we still need to load 'autoexec.be'
|
||||||
bool repl_active = false; // is REPL running (activates log recording)
|
bool repl_active = false; // is REPL running (activates log recording)
|
||||||
// output log is stored as a LinkedList of buffers
|
// output log is stored as a LinkedList of buffers
|
||||||
@ -107,4 +110,41 @@ BerrySupport berry;
|
|||||||
// multi-purpose serial logging
|
// multi-purpose serial logging
|
||||||
extern "C" void serial_debug(const char * berry_buf, ...);
|
extern "C" void serial_debug(const char * berry_buf, ...);
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************************************\
|
||||||
|
* Handle dynamic code from Berry bec files
|
||||||
|
*
|
||||||
|
\*********************************************************************************************/
|
||||||
|
struct BeBECCode_t {
|
||||||
|
const char * display_name; // display name in Web UI (must be URL encoded)
|
||||||
|
const char * id; // id in requested URL, also don't load if the global name already exists in Berry
|
||||||
|
const char * url; // absolute URL to download the bec file
|
||||||
|
const char * redirect; // relative URI to redirect after loading
|
||||||
|
bool * loaded;
|
||||||
|
};
|
||||||
|
|
||||||
|
const BeBECCode_t BECCode[] = {
|
||||||
|
#ifdef USE_BERRY_PARTITION_WIZARD
|
||||||
|
{
|
||||||
|
"Partition Wizard",
|
||||||
|
"partition_wizard",
|
||||||
|
USE_BERRY_PARTITION_WIZARD_URL,
|
||||||
|
"/part_wiz",
|
||||||
|
&berry.partition_wizard_loaded
|
||||||
|
},
|
||||||
|
#endif // USE_BERRY_PARTITION_WIZARD
|
||||||
|
|
||||||
|
#ifdef USE_BERRY_GPIOVIEWER
|
||||||
|
{
|
||||||
|
"GPIO Viewer",
|
||||||
|
"gpioviewer",
|
||||||
|
USE_BERRY_GPIOVIEWER_URL,
|
||||||
|
"/mn?",
|
||||||
|
&berry.gpviewer_loaded
|
||||||
|
},
|
||||||
|
#endif // USE_BERRY_GPIOVIEWER
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // USE_BERRY
|
#endif // USE_BERRY
|
||||||
|
@ -764,33 +764,50 @@ void HandleBerryConsole(void)
|
|||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_BERRY_PARTITION_WIZARD
|
|
||||||
// Display a Button to dynamically load the Partition Wizard
|
// const BeBECCode_t BECCode[] = {
|
||||||
void HandleBerryPartiionWizardLoaderButton(void) {
|
// struct BeBECCode_t {
|
||||||
|
// const char * display_name; // display name in Web UI (must be URL encoded)
|
||||||
|
// const char * id; // id in requested URL
|
||||||
|
// const char * url; // absolute URL to download the bec file
|
||||||
|
// const char * redirect; // relative URI to redirect after loading
|
||||||
|
// };
|
||||||
|
|
||||||
|
// Display Buttons to dynamically load bec files
|
||||||
|
void HandleBerryBECLoaderButton(void) {
|
||||||
bvm * vm = berry.vm;
|
bvm * vm = berry.vm;
|
||||||
static const char PARTITION_WIZARD_NAME[] = "partition_wizard";
|
|
||||||
if (!berry.partition_wizard_loaded) {
|
for (int32_t i = 0; i < ARRAY_SIZE(BECCode); i++) {
|
||||||
if (be_global_find(vm, be_newstr(vm, PARTITION_WIZARD_NAME)) < 0) { // the global name `partition_wizard` doesn't exist
|
const BeBECCode_t &bec = BECCode[i];
|
||||||
WSContentSend_P("<form id=but_part_mgr style='display: block;' action='tapp' method='get'><input type='hidden' name='n' value='Partition_Wizard'/><button>[Load Partition Wizard]</button></form><p></p>");
|
if (!(*bec.loaded)) {
|
||||||
|
if (be_global_find(vm, be_newstr(vm, bec.id)) < 0) { // the global name doesn't exist
|
||||||
|
WSContentSend_P("<form id=but_part_mgr style='display: block;' action='tapp' method='get'><input type='hidden' name='n' value='%s'/><button>[Load %s]</button></form><p></p>", bec.id, bec.display_name);
|
||||||
} else {
|
} else {
|
||||||
berry.partition_wizard_loaded = true;
|
*bec.loaded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" bbool BerryBECLoader(const char * url);
|
extern "C" bbool BerryBECLoader(const char * url);
|
||||||
void HandleBerryPartitionWizardLoader(void) {
|
|
||||||
if (BerryBECLoader(USE_BERRY_PARTITION_WIZARD_URL)) {
|
void HandleBerryBECLoader(void) {
|
||||||
|
String n = Webserver->arg("n");
|
||||||
|
for (int32_t i = 0; i < ARRAY_SIZE(BECCode); i++) {
|
||||||
|
const BeBECCode_t &bec = BECCode[i];
|
||||||
|
if (n.equals(bec.id)) {
|
||||||
|
if (BerryBECLoader(bec.url)) {
|
||||||
// All good, redirect
|
// All good, redirect
|
||||||
Webserver->sendHeader("Location", "/part_wiz", true);
|
Webserver->sendHeader("Location", bec.redirect, true);
|
||||||
Webserver->send(302, "text/plain", "");
|
Webserver->send(302, "text/plain", "");
|
||||||
berry.partition_wizard_loaded = true;
|
*bec.loaded = true;
|
||||||
} else {
|
} else {
|
||||||
Webserver->sendHeader("Location", "/mn?", true);
|
Webserver->sendHeader("Location", "/mn?", true);
|
||||||
Webserver->send(302, "text/plain", "");
|
Webserver->send(302, "text/plain", "");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif //USE_BERRY_PARTITION_WIZARD
|
|
||||||
|
|
||||||
// return true if successful
|
// return true if successful
|
||||||
extern "C" bbool BerryBECLoader(const char * url) {
|
extern "C" bbool BerryBECLoader(const char * url) {
|
||||||
@ -925,9 +942,7 @@ bool Xdrv52(uint32_t function)
|
|||||||
XdrvMailbox.index++;
|
XdrvMailbox.index++;
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_P(HTTP_BTN_BERRY_CONSOLE);
|
WSContentSend_P(HTTP_BTN_BERRY_CONSOLE);
|
||||||
#ifdef USE_BERRY_PARTITION_WIZARD
|
HandleBerryBECLoaderButton(); // display buttons to load BEC files
|
||||||
HandleBerryPartiionWizardLoaderButton();
|
|
||||||
#endif // USE_BERRY_PARTITION_WIZARD
|
|
||||||
callBerryEventDispatcher(PSTR("web_add_button"), nullptr, 0, nullptr);
|
callBerryEventDispatcher(PSTR("web_add_button"), nullptr, 0, nullptr);
|
||||||
callBerryEventDispatcher(PSTR("web_add_console_button"), nullptr, 0, nullptr);
|
callBerryEventDispatcher(PSTR("web_add_console_button"), nullptr, 0, nullptr);
|
||||||
}
|
}
|
||||||
@ -946,10 +961,8 @@ bool Xdrv52(uint32_t function)
|
|||||||
callBerryEventDispatcher(PSTR("web_add_handler"), nullptr, 0, nullptr);
|
callBerryEventDispatcher(PSTR("web_add_handler"), nullptr, 0, nullptr);
|
||||||
berry.web_add_handler_done = true;
|
berry.web_add_handler_done = true;
|
||||||
}
|
}
|
||||||
WebServer_on(PSTR("/bc"), HandleBerryConsole);
|
WebServer_on("/bc", HandleBerryConsole);
|
||||||
#ifdef USE_BERRY_PARTITION_WIZARD
|
WebServer_on("/tapp", HandleBerryBECLoader, HTTP_GET);
|
||||||
Webserver->on("/tapp", HTTP_GET, HandleBerryPartitionWizardLoader);
|
|
||||||
#endif // USE_BERRY_PARTITION_WIZARD
|
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
case FUNC_SAVE_BEFORE_RESTART:
|
case FUNC_SAVE_BEFORE_RESTART:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user