widget support for Berry/MI32 dashboard (#22359)

This commit is contained in:
Christian Baars 2024-10-25 19:25:49 +02:00 committed by GitHub
parent 0f2b3b1898
commit b5a487a595
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 31 deletions

View File

@ -25,6 +25,9 @@ BE_FUNC_CTYPE_DECLARE(be_MI32_set_hum, "", "ii");
extern void be_MI32_set_temp(int slot, int temp_val); extern void be_MI32_set_temp(int slot, int temp_val);
BE_FUNC_CTYPE_DECLARE(be_MI32_set_temp, "", "ii"); BE_FUNC_CTYPE_DECLARE(be_MI32_set_temp, "", "ii");
extern bbool be_MI32_widget(const char *sbuf, void* function);
BE_FUNC_CTYPE_DECLARE(be_MI32_widget, "b", "s[c]");
#include "be_fixed_MI32.h" #include "be_fixed_MI32.h"
/* @const_object_info_begin /* @const_object_info_begin
@ -35,6 +38,7 @@ module MI32 (scope: global) {
set_bat, ctype_func(be_MI32_set_bat) set_bat, ctype_func(be_MI32_set_bat)
set_hum, ctype_func(be_MI32_set_hum) set_hum, ctype_func(be_MI32_set_hum)
set_temp, ctype_func(be_MI32_set_temp) set_temp, ctype_func(be_MI32_set_temp)
widget, ctype_func(be_MI32_widget)
} }
@const_object_info_end */ @const_object_info_end */

View File

@ -44,6 +44,12 @@ extern "C" {
extern void MI32setTemperatureForSlot(uint32_t slot, float value); extern void MI32setTemperatureForSlot(uint32_t slot, float value);
extern uint8_t * MI32getDeviceMAC(uint32_t slot); extern uint8_t * MI32getDeviceMAC(uint32_t slot);
struct {
const char * data = nullptr;
size_t size = 0;
void* callback = nullptr;
} be_MI32Widget;
int be_MI32_devices(void) { int be_MI32_devices(void) {
return MI32numberOfDevices(); return MI32numberOfDevices();
} }
@ -73,6 +79,18 @@ extern "C" {
MI32setTemperatureForSlot(slot,temp_val); MI32setTemperatureForSlot(slot,temp_val);
} }
bool be_MI32_widget(const char* sbuf, void* function){
if (function){
be_MI32Widget.callback = function;
}
if(be_MI32Widget.size == 0){
be_MI32Widget.data = sbuf;
be_MI32Widget.size = strlen(sbuf);
return true;
}
return false;
}
/******************************************************************** /********************************************************************
** BLE - generic BLE functions ** BLE - generic BLE functions
@ -358,5 +376,6 @@ MI32.get_MAC(slot)
MI32.set_bat(slot,int) MI32.set_bat(slot,int)
MI32.set_hum(slot,float) MI32.set_hum(slot,float)
MI32.set_temp(slot,float) MI32.set_temp(slot,float)
MI32.widget(string[,cb])
*/ */

View File

@ -919,6 +919,14 @@ extern "C" {
return _name; return _name;
} }
void MI32sendBerryWidget() {
if(be_MI32Widget.size != 0) {
WSContentSend(be_MI32Widget.data, be_MI32Widget.size);
be_MI32Widget.data = nullptr;
be_MI32Widget.size = 0;
}
}
} //extern "C" } //extern "C"
/*********************************************************************************************\ /*********************************************************************************************\
@ -1187,7 +1195,7 @@ bool MI32ConnectActiveSensor(){ // only use inside a task !!
/** /**
* @brief Retrieves all services of the connected BLE device and stores the result into the transfer buffer of Berry's BLE module * @brief Retrieves all services of the connected BLE device and stores the result into the transfer buffer of Berry's BLE module
* buffer format: * buffer format:
* first byte: number of services * first byte: number of services
* next byte: format of the UUID in bits, next N bytes: the UUID as 16-bit-uint or uint8_t buffer of 16 bytes * next byte: format of the UUID in bits, next N bytes: the UUID as 16-bit-uint or uint8_t buffer of 16 bytes
* ... next service * ... next service
@ -2361,6 +2369,9 @@ void CmndMi32Option(void){
\*********************************************************************************************/ \*********************************************************************************************/
#ifdef USE_MI_EXT_GUI #ifdef USE_MI_EXT_GUI
bool MI32HandleWebGUIResponse(void){ bool MI32HandleWebGUIResponse(void){
if(be_MI32Widget.callback != nullptr){
((void(*)())be_MI32Widget.callback)();
}
char tmp[16]; char tmp[16];
WebGetArg(PSTR("wi"), tmp, sizeof(tmp)); WebGetArg(PSTR("wi"), tmp, sizeof(tmp));
if (strlen(tmp)) { if (strlen(tmp)) {
@ -2373,6 +2384,8 @@ bool MI32HandleWebGUIResponse(void){
break; break;
} }
} }
} else {
MI32sendBerryWidget();
} }
WSContentEnd(); WSContentEnd();
return true; return true;