mirror of https://github.com/arendst/Tasmota.git
Berry add module `webserver`
This commit is contained in:
parent
ed5b048b6e
commit
5cffd58c16
|
@ -25,6 +25,7 @@ be_extern_native_module(solidify);
|
|||
be_extern_native_module(light);
|
||||
be_extern_native_module(gpio);
|
||||
be_extern_native_module(energy);
|
||||
be_extern_native_module(webserver);
|
||||
#ifdef USE_LVGL
|
||||
be_extern_native_module(lvgl);
|
||||
#endif // USE_LVGL
|
||||
|
@ -79,6 +80,9 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = {
|
|||
#ifdef USE_ENERGY_SENSOR
|
||||
&be_native_module(energy),
|
||||
#endif // USE_ENERGY_SENSOR
|
||||
#ifdef USE_WEBSERVER
|
||||
&be_native_module(webserver),
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
|
||||
/* user-defined modules register end */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
extern int l_getFreeHeap(bvm *vm);
|
||||
extern int l_publish(bvm *vm);
|
||||
extern int l_cmd(bvm *vm);
|
||||
extern int l_get_cb(bvm *vm);
|
||||
extern int l_getoption(bvm *vm);
|
||||
extern int l_millis(bvm *vm);
|
||||
extern int l_timereached(bvm *vm);
|
||||
|
@ -1452,41 +1453,6 @@ be_define_local_closure(gc);
|
|||
|
||||
/*******************************************************************/
|
||||
|
||||
/********************************************************************
|
||||
//
|
||||
// Event from Tasmota is:
|
||||
// 1. event:string -- type of event (cmd, rule, ...)
|
||||
// 2. cmd:string -- name of the command to process
|
||||
// 3. index:int -- index number
|
||||
// 4. payload:string -- payload as text, analyzed as json
|
||||
//
|
||||
def event(type, cmd, idx, payload)
|
||||
if type=='cmd' return self.exec_cmd(cmd, idx, payload)
|
||||
elif type=='rule' return self.exec_rules(payload)
|
||||
elif type=='mqtt_data' return nil
|
||||
elif type=='gc' return self.gc()
|
||||
elif type=='every_50ms' return self.run_deferred()
|
||||
elif self._drivers
|
||||
for d:self._drivers
|
||||
try
|
||||
if type=='every_second' && d.every_second return d.every_second()
|
||||
elif type=='every_100ms' && d.every_100ms return d.every_100ms()
|
||||
elif type=='web_add_button' && d.web_add_button return d.web_add_button()
|
||||
elif type=='web_add_main_button' && d.web_add_main_button return d.web_add_main_button()
|
||||
elif type=='save_before_restart' && d.save_before_restart return d.save_before_restart()
|
||||
elif type=='web_sensor' && d.web_sensor return d.web_sensor()
|
||||
elif type=='json_append' && d.json_append return d.json_append()
|
||||
elif type=='button_pressed' && d.button_pressed return d.button_pressed()
|
||||
elif type=='display' && d.display return d.display()
|
||||
end
|
||||
except .. as e,m
|
||||
import string
|
||||
self.log(string.format('BRY: exception %s - %m',3))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
********************************************************************/
|
||||
/********************************************************************
|
||||
** Solidified function: event
|
||||
********************************************************************/
|
||||
|
@ -1511,14 +1477,15 @@ be_define_local_const_str(event_str_13, "save_before_restart", 1253239338, 19);
|
|||
be_define_local_const_str(event_str_14, "web_sensor", -1394870324, 10);
|
||||
be_define_local_const_str(event_str_15, "json_append", -1292948012, 11);
|
||||
be_define_local_const_str(event_str_16, "button_pressed", 1694209616, 14);
|
||||
be_define_local_const_str(event_str_17, "display", 1164572437, 7);
|
||||
be_define_local_const_str(event_str_18, "string", 398550328, 6);
|
||||
be_define_local_const_str(event_str_19, "log", 1062293841, 3);
|
||||
be_define_local_const_str(event_str_20, "format", -1180859054, 6);
|
||||
be_define_local_const_str(event_str_21, "BRY: exception %s - %m", -1290966132, 22);
|
||||
be_define_local_const_str(event_str_23, "stop_iteration", -121173395, 14);
|
||||
be_define_local_const_str(event_str_17, "web_add_handler", -304792334, 15);
|
||||
be_define_local_const_str(event_str_18, "display", 1164572437, 7);
|
||||
be_define_local_const_str(event_str_19, "string", 398550328, 6);
|
||||
be_define_local_const_str(event_str_20, "log", 1062293841, 3);
|
||||
be_define_local_const_str(event_str_21, "format", -1180859054, 6);
|
||||
be_define_local_const_str(event_str_22, "BRY: exception %s - %m", -1290966132, 22);
|
||||
be_define_local_const_str(event_str_24, "stop_iteration", -121173395, 14);
|
||||
|
||||
static const bvalue event_ktab[24] = {
|
||||
static const bvalue event_ktab[25] = {
|
||||
{ { .s=be_local_const_str(event_str_0) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(event_str_1) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(event_str_2) }, BE_STRING},
|
||||
|
@ -1541,11 +1508,12 @@ static const bvalue event_ktab[24] = {
|
|||
{ { .s=be_local_const_str(event_str_19) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(event_str_20) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(event_str_21) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(event_str_22) }, BE_STRING},
|
||||
{ { .i=3 }, BE_INT},
|
||||
{ { .s=be_local_const_str(event_str_23) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(event_str_24) }, BE_STRING},
|
||||
};
|
||||
|
||||
static const uint32_t event_code[140] = {
|
||||
static const uint32_t event_code[149] = {
|
||||
0x1C140300, // 0000 EQ R5 R1 R256
|
||||
0x78160006, // 0001 JMPF R5 #0009
|
||||
0x8C140101, // 0002 GETMET R5 R0 R257
|
||||
|
@ -1554,40 +1522,40 @@ static const uint32_t event_code[140] = {
|
|||
0x5C240800, // 0005 MOVE R9 R4
|
||||
0x7C140800, // 0006 CALL R5 4
|
||||
0x80040A00, // 0007 RET 1 R5
|
||||
0x70020081, // 0008 JMP #008B
|
||||
0x7002008A, // 0008 JMP #0094
|
||||
0x1C140302, // 0009 EQ R5 R1 R258
|
||||
0x78160004, // 000A JMPF R5 #0010
|
||||
0x8C140103, // 000B GETMET R5 R0 R259
|
||||
0x5C1C0800, // 000C MOVE R7 R4
|
||||
0x7C140400, // 000D CALL R5 2
|
||||
0x80040A00, // 000E RET 1 R5
|
||||
0x7002007A, // 000F JMP #008B
|
||||
0x70020083, // 000F JMP #0094
|
||||
0x1C140304, // 0010 EQ R5 R1 R260
|
||||
0x78160002, // 0011 JMPF R5 #0015
|
||||
0x4C140000, // 0012 LDNIL 5
|
||||
0x80040A00, // 0013 RET 1 R5
|
||||
0x70020075, // 0014 JMP #008B
|
||||
0x7002007E, // 0014 JMP #0094
|
||||
0x1C140305, // 0015 EQ R5 R1 R261
|
||||
0x78160003, // 0016 JMPF R5 #001B
|
||||
0x8C140105, // 0017 GETMET R5 R0 R261
|
||||
0x7C140200, // 0018 CALL R5 1
|
||||
0x80040A00, // 0019 RET 1 R5
|
||||
0x7002006F, // 001A JMP #008B
|
||||
0x70020078, // 001A JMP #0094
|
||||
0x1C140306, // 001B EQ R5 R1 R262
|
||||
0x78160003, // 001C JMPF R5 #0021
|
||||
0x8C140107, // 001D GETMET R5 R0 R263
|
||||
0x7C140200, // 001E CALL R5 1
|
||||
0x80040A00, // 001F RET 1 R5
|
||||
0x70020069, // 0020 JMP #008B
|
||||
0x70020072, // 0020 JMP #0094
|
||||
0x88140108, // 0021 GETMBR R5 R0 R264
|
||||
0x78160067, // 0022 JMPF R5 #008B
|
||||
0x78160070, // 0022 JMPF R5 #0094
|
||||
0x60140000, // 0023 GETGBL R5 G0
|
||||
0x88180108, // 0024 GETMBR R6 R0 R264
|
||||
0x7C140200, // 0025 CALL R5 1
|
||||
0xA8020060, // 0026 EXBLK 0 #0088
|
||||
0xA8020069, // 0026 EXBLK 0 #0091
|
||||
0x5C180A00, // 0027 MOVE R6 R5
|
||||
0x7C180000, // 0028 CALL R6 0
|
||||
0xA8020051, // 0029 EXBLK 0 #007C
|
||||
0xA802005A, // 0029 EXBLK 0 #0085
|
||||
0x1C1C0309, // 002A EQ R7 R1 R265
|
||||
0x781E0006, // 002B JMPF R7 #0033
|
||||
0x881C0D09, // 002C GETMBR R7 R6 R265
|
||||
|
@ -1596,7 +1564,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 002F CALL R7 1
|
||||
0xA8040002, // 0030 EXBLK 1 2
|
||||
0x80040E00, // 0031 RET 1 R7
|
||||
0x70020046, // 0032 JMP #007A
|
||||
0x7002004F, // 0032 JMP #0083
|
||||
0x1C1C030A, // 0033 EQ R7 R1 R266
|
||||
0x781E0006, // 0034 JMPF R7 #003C
|
||||
0x881C0D0A, // 0035 GETMBR R7 R6 R266
|
||||
|
@ -1605,7 +1573,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 0038 CALL R7 1
|
||||
0xA8040002, // 0039 EXBLK 1 2
|
||||
0x80040E00, // 003A RET 1 R7
|
||||
0x7002003D, // 003B JMP #007A
|
||||
0x70020046, // 003B JMP #0083
|
||||
0x1C1C030B, // 003C EQ R7 R1 R267
|
||||
0x781E0006, // 003D JMPF R7 #0045
|
||||
0x881C0D0B, // 003E GETMBR R7 R6 R267
|
||||
|
@ -1614,7 +1582,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 0041 CALL R7 1
|
||||
0xA8040002, // 0042 EXBLK 1 2
|
||||
0x80040E00, // 0043 RET 1 R7
|
||||
0x70020034, // 0044 JMP #007A
|
||||
0x7002003D, // 0044 JMP #0083
|
||||
0x1C1C030C, // 0045 EQ R7 R1 R268
|
||||
0x781E0006, // 0046 JMPF R7 #004E
|
||||
0x881C0D0C, // 0047 GETMBR R7 R6 R268
|
||||
|
@ -1623,7 +1591,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 004A CALL R7 1
|
||||
0xA8040002, // 004B EXBLK 1 2
|
||||
0x80040E00, // 004C RET 1 R7
|
||||
0x7002002B, // 004D JMP #007A
|
||||
0x70020034, // 004D JMP #0083
|
||||
0x1C1C030D, // 004E EQ R7 R1 R269
|
||||
0x781E0006, // 004F JMPF R7 #0057
|
||||
0x881C0D0D, // 0050 GETMBR R7 R6 R269
|
||||
|
@ -1632,7 +1600,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 0053 CALL R7 1
|
||||
0xA8040002, // 0054 EXBLK 1 2
|
||||
0x80040E00, // 0055 RET 1 R7
|
||||
0x70020022, // 0056 JMP #007A
|
||||
0x7002002B, // 0056 JMP #0083
|
||||
0x1C1C030E, // 0057 EQ R7 R1 R270
|
||||
0x781E0006, // 0058 JMPF R7 #0060
|
||||
0x881C0D0E, // 0059 GETMBR R7 R6 R270
|
||||
|
@ -1641,7 +1609,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 005C CALL R7 1
|
||||
0xA8040002, // 005D EXBLK 1 2
|
||||
0x80040E00, // 005E RET 1 R7
|
||||
0x70020019, // 005F JMP #007A
|
||||
0x70020022, // 005F JMP #0083
|
||||
0x1C1C030F, // 0060 EQ R7 R1 R271
|
||||
0x781E0006, // 0061 JMPF R7 #0069
|
||||
0x881C0D0F, // 0062 GETMBR R7 R6 R271
|
||||
|
@ -1650,7 +1618,7 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 0065 CALL R7 1
|
||||
0xA8040002, // 0066 EXBLK 1 2
|
||||
0x80040E00, // 0067 RET 1 R7
|
||||
0x70020010, // 0068 JMP #007A
|
||||
0x70020019, // 0068 JMP #0083
|
||||
0x1C1C0310, // 0069 EQ R7 R1 R272
|
||||
0x781E0006, // 006A JMPF R7 #0072
|
||||
0x881C0D10, // 006B GETMBR R7 R6 R272
|
||||
|
@ -1659,33 +1627,42 @@ static const uint32_t event_code[140] = {
|
|||
0x7C1C0200, // 006E CALL R7 1
|
||||
0xA8040002, // 006F EXBLK 1 2
|
||||
0x80040E00, // 0070 RET 1 R7
|
||||
0x70020007, // 0071 JMP #007A
|
||||
0x70020010, // 0071 JMP #0083
|
||||
0x1C1C0311, // 0072 EQ R7 R1 R273
|
||||
0x781E0005, // 0073 JMPF R7 #007A
|
||||
0x881C0D11, // 0074 GETMBR R7 R6 R273
|
||||
0x781E0003, // 0075 JMPF R7 #007A
|
||||
0x8C1C0D11, // 0076 GETMET R7 R6 R273
|
||||
0x781E0006, // 0073 JMPF R7 #007B
|
||||
0x881C0D12, // 0074 GETMBR R7 R6 R274
|
||||
0x781E0004, // 0075 JMPF R7 #007B
|
||||
0x8C1C0D12, // 0076 GETMET R7 R6 R274
|
||||
0x7C1C0200, // 0077 CALL R7 1
|
||||
0xA8040002, // 0078 EXBLK 1 2
|
||||
0x80040E00, // 0079 RET 1 R7
|
||||
0xA8040001, // 007A EXBLK 1 1
|
||||
0x7002000A, // 007B JMP #0087
|
||||
0xAC1C0002, // 007C CATCH R7 0 2
|
||||
0x70020007, // 007D JMP #0086
|
||||
0xA4262400, // 007E IMPORT R9 R274
|
||||
0x8C280113, // 007F GETMET R10 R0 R275
|
||||
0x8C301314, // 0080 GETMET R12 R9 R276
|
||||
0x58380015, // 0081 LDCONST R14 K21
|
||||
0x583C0016, // 0082 LDCONST R15 K22
|
||||
0x7C300600, // 0083 CALL R12 3
|
||||
0x7C280400, // 0084 CALL R10 2
|
||||
0x70020000, // 0085 JMP #0087
|
||||
0xB0080000, // 0086 RAISE 2 R0 R0
|
||||
0x7001FF9E, // 0087 JMP #0027
|
||||
0x58140017, // 0088 LDCONST R5 K23
|
||||
0xAC140200, // 0089 CATCH R5 1 0
|
||||
0xB0080000, // 008A RAISE 2 R0 R0
|
||||
0x80000000, // 008B RET 0 R0
|
||||
0x70020007, // 007A JMP #0083
|
||||
0x1C1C0312, // 007B EQ R7 R1 R274
|
||||
0x781E0005, // 007C JMPF R7 #0083
|
||||
0x881C0D12, // 007D GETMBR R7 R6 R274
|
||||
0x781E0003, // 007E JMPF R7 #0083
|
||||
0x8C1C0D12, // 007F GETMET R7 R6 R274
|
||||
0x7C1C0200, // 0080 CALL R7 1
|
||||
0xA8040002, // 0081 EXBLK 1 2
|
||||
0x80040E00, // 0082 RET 1 R7
|
||||
0xA8040001, // 0083 EXBLK 1 1
|
||||
0x7002000A, // 0084 JMP #0090
|
||||
0xAC1C0002, // 0085 CATCH R7 0 2
|
||||
0x70020007, // 0086 JMP #008F
|
||||
0xA4262600, // 0087 IMPORT R9 R275
|
||||
0x8C280114, // 0088 GETMET R10 R0 R276
|
||||
0x8C301315, // 0089 GETMET R12 R9 R277
|
||||
0x58380016, // 008A LDCONST R14 K22
|
||||
0x583C0017, // 008B LDCONST R15 K23
|
||||
0x7C300600, // 008C CALL R12 3
|
||||
0x7C280400, // 008D CALL R10 2
|
||||
0x70020000, // 008E JMP #0090
|
||||
0xB0080000, // 008F RAISE 2 R0 R0
|
||||
0x7001FF95, // 0090 JMP #0027
|
||||
0x58140018, // 0091 LDCONST R5 K24
|
||||
0xAC140200, // 0092 CATCH R5 1 0
|
||||
0xB0080000, // 0093 RAISE 2 R0 R0
|
||||
0x80000000, // 0094 RET 0 R0
|
||||
};
|
||||
|
||||
be_define_local_proto(event, 16, 5, 1, 0, 0);
|
||||
|
@ -1693,18 +1670,6 @@ be_define_local_closure(event);
|
|||
|
||||
/*******************************************************************/
|
||||
|
||||
/********************************************************************
|
||||
//
|
||||
// add driver to the queue of event dispatching
|
||||
//
|
||||
"def add_driver(d) "
|
||||
"if self._drivers "
|
||||
"self._drivers.push(d) "
|
||||
"else "
|
||||
"self._drivers = [d]"
|
||||
"end "
|
||||
"end "
|
||||
********************************************************************/
|
||||
/********************************************************************
|
||||
** Solidified function: add_driver
|
||||
********************************************************************/
|
||||
|
@ -2398,6 +2363,118 @@ static const bclosure set_light_closure = {
|
|||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/********************************************************************
|
||||
** Solidified function: cb_dispatch
|
||||
********************************************************************/
|
||||
|
||||
/********** Solidified proto: cb_dispatch */
|
||||
be_define_local_const_str(cb_dispatch_str_name, "cb_dispatch", 1741510499, 11);
|
||||
be_define_local_const_str(cb_dispatch_str_source, "input", -103256197, 5);
|
||||
be_define_local_const_str(cb_dispatch_str_0, "_cb", -251666929, 3);
|
||||
be_define_local_const_str(cb_dispatch_str_2, "find", -1108310694, 4);
|
||||
|
||||
static const bvalue cb_dispatch_ktab[3] = {
|
||||
{ { .s=be_local_const_str(cb_dispatch_str_0) }, BE_STRING},
|
||||
{ { .i=0 }, BE_INT},
|
||||
{ { .s=be_local_const_str(cb_dispatch_str_2) }, BE_STRING},
|
||||
};
|
||||
|
||||
static const uint32_t cb_dispatch_code[20] = {
|
||||
0x88180100, // 0000 GETMBR R6 R0 R256
|
||||
0x4C1C0000, // 0001 LDNIL 7
|
||||
0x1C180C07, // 0002 EQ R6 R6 R7
|
||||
0x781A0000, // 0003 JMPF R6 #0005
|
||||
0x80060200, // 0004 RET 1 R257
|
||||
0x88180100, // 0005 GETMBR R6 R0 R256
|
||||
0x8C180D02, // 0006 GETMET R6 R6 R258
|
||||
0x5C200200, // 0007 MOVE R8 R1
|
||||
0x7C180400, // 0008 CALL R6 2
|
||||
0x4C1C0000, // 0009 LDNIL 7
|
||||
0x201C0C07, // 000A NE R7 R6 R7
|
||||
0x781E0006, // 000B JMPF R7 #0013
|
||||
0x5C1C0C00, // 000C MOVE R7 R6
|
||||
0x5C200400, // 000D MOVE R8 R2
|
||||
0x5C240600, // 000E MOVE R9 R3
|
||||
0x5C280800, // 000F MOVE R10 R4
|
||||
0x5C2C0A00, // 0010 MOVE R11 R5
|
||||
0x7C1C0800, // 0011 CALL R7 4
|
||||
0x80040E00, // 0012 RET 1 R7
|
||||
0x80060200, // 0013 RET 1 R257
|
||||
};
|
||||
|
||||
be_define_local_proto(cb_dispatch, 12, 6, 1, 0, 0);
|
||||
be_define_local_closure(cb_dispatch);
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
/********************************************************************
|
||||
** Solidified function: gen_cb
|
||||
********************************************************************/
|
||||
|
||||
/********** Solidified proto: gen_cb */
|
||||
be_define_local_const_str(gen_cb_str_name, "gen_cb", -1049739745, 6);
|
||||
be_define_local_const_str(gen_cb_str_source, "input", -103256197, 5);
|
||||
be_define_local_const_str(gen_cb_str_0, "_cb", -251666929, 3);
|
||||
be_define_local_const_str(gen_cb_str_2, "find", -1108310694, 4);
|
||||
be_define_local_const_str(gen_cb_str_3, "_get_cb", 1448849122, 7);
|
||||
be_define_local_const_str(gen_cb_str_4, "stop_iteration", -121173395, 14);
|
||||
be_define_local_const_str(gen_cb_str_5, "internal_error", -1775809127, 14);
|
||||
be_define_local_const_str(gen_cb_str_6, "No callback available", 633786138, 21);
|
||||
|
||||
static const bvalue gen_cb_ktab[7] = {
|
||||
{ { .s=be_local_const_str(gen_cb_str_0) }, BE_STRING},
|
||||
{ { .i=0 }, BE_INT},
|
||||
{ { .s=be_local_const_str(gen_cb_str_2) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(gen_cb_str_3) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(gen_cb_str_4) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(gen_cb_str_5) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(gen_cb_str_6) }, BE_STRING},
|
||||
};
|
||||
|
||||
static const uint32_t gen_cb_code[34] = {
|
||||
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||
0x4C0C0000, // 0001 LDNIL 3
|
||||
0x1C080403, // 0002 EQ R2 R2 R3
|
||||
0x780A0002, // 0003 JMPF R2 #0007
|
||||
0x6008000B, // 0004 GETGBL R2 G11
|
||||
0x7C080000, // 0005 CALL R2 0
|
||||
0x90020002, // 0006 SETMBR R0 R256 R2
|
||||
0x60080000, // 0007 GETGBL R2 G0
|
||||
0x540E0012, // 0008 LDINT R3 19
|
||||
0x400E0203, // 0009 CONNECT R3 R257 R3
|
||||
0x7C080200, // 000A CALL R2 1
|
||||
0xA8020010, // 000B EXBLK 0 #001D
|
||||
0x5C0C0400, // 000C MOVE R3 R2
|
||||
0x7C0C0000, // 000D CALL R3 0
|
||||
0x88100100, // 000E GETMBR R4 R0 R256
|
||||
0x8C100902, // 000F GETMET R4 R4 R258
|
||||
0x5C180600, // 0010 MOVE R6 R3
|
||||
0x7C100400, // 0011 CALL R4 2
|
||||
0x4C140000, // 0012 LDNIL 5
|
||||
0x1C100805, // 0013 EQ R4 R4 R5
|
||||
0x78120006, // 0014 JMPF R4 #001C
|
||||
0x88100100, // 0015 GETMBR R4 R0 R256
|
||||
0x98100601, // 0016 SETIDX R4 R3 R1
|
||||
0x8C100103, // 0017 GETMET R4 R0 R259
|
||||
0x5C180600, // 0018 MOVE R6 R3
|
||||
0x7C100400, // 0019 CALL R4 2
|
||||
0xA8040001, // 001A EXBLK 1 1
|
||||
0x80040800, // 001B RET 1 R4
|
||||
0x7001FFEE, // 001C JMP #000C
|
||||
0x58080004, // 001D LDCONST R2 K4
|
||||
0xAC080200, // 001E CATCH R2 1 0
|
||||
0xB0080000, // 001F RAISE 2 R0 R0
|
||||
0xB0060B06, // 0020 RAISE 1 R261 R262
|
||||
0x80000000, // 0021 RET 0 R0
|
||||
};
|
||||
|
||||
be_define_local_proto(gen_cb, 7, 2, 1, 0, 0);
|
||||
be_define_local_closure(gen_cb);
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
#if BE_USE_PRECOMPILED_OBJECT
|
||||
#include "../generate/be_fixed_be_class_tasmota.h"
|
||||
#endif
|
||||
|
@ -2412,11 +2489,13 @@ void be_load_tasmota_ntvlib(bvm *vm)
|
|||
{ "_timers", NULL },
|
||||
{ "_ccmd", NULL },
|
||||
{ "_drivers", NULL },
|
||||
{ "_cb", NULL},
|
||||
{ "wire1", NULL },
|
||||
{ "wire2", NULL },
|
||||
{ "get_free_heap", l_getFreeHeap },
|
||||
{ "publish", l_publish },
|
||||
{ "_cmd", l_cmd },
|
||||
{ "_get_cb", l_get_cb },
|
||||
{ "get_option", l_getoption },
|
||||
{ "millis", l_millis },
|
||||
{ "time_reached", l_timereached },
|
||||
|
@ -2465,6 +2544,10 @@ void be_load_tasmota_ntvlib(bvm *vm)
|
|||
{ "wire_scan", (bntvfunc) &wire_scan_closure },
|
||||
{ "time_str", (bntvfunc) &time_str_closure },
|
||||
|
||||
// callbacks
|
||||
{ "cb_dispatch", (bntvfunc) &cb_dispatch_closure },
|
||||
{ "gen_cb", (bntvfunc) &gen_cb_closure },
|
||||
|
||||
// deprecated
|
||||
{ "get_light", (bntvfunc) &get_light_closure },
|
||||
{ "set_light", (bntvfunc) &set_light_closure },
|
||||
|
@ -2485,12 +2568,14 @@ class be_class_tasmota (scope: global, name: Tasmota) {
|
|||
_timers, var
|
||||
_ccmd, var
|
||||
_drivers, var
|
||||
_cb, var
|
||||
wire1, var
|
||||
wire2, var
|
||||
|
||||
get_free_heap, func(l_getFreeHeap)
|
||||
publish, func(l_publish)
|
||||
_cmd, func(l_cmd)
|
||||
_get_cb, func(l_get_cb)
|
||||
get_option, func(l_getoption)
|
||||
millis, func(l_millis)
|
||||
time_reached, func(l_timereached)
|
||||
|
@ -2538,6 +2623,9 @@ class be_class_tasmota (scope: global, name: Tasmota) {
|
|||
wire_scan, closure(wire_scan_closure)
|
||||
time_str, closure(time_str_closure)
|
||||
|
||||
cb_dispatch, closure(cb_dispatch_closure)
|
||||
gen_cb, closure(gen_cb_closure)
|
||||
|
||||
get_light, closure(get_light_closure)
|
||||
set_light, closure(set_light_closure)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/********************************************************************
|
||||
* Berry module `webserver`
|
||||
*
|
||||
* To use: `import webserver`
|
||||
*
|
||||
* Allows to respond to HTTP request
|
||||
*******************************************************************/
|
||||
#include "be_constobj.h"
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
|
||||
extern int w_webserver_on(bvm *vm);
|
||||
extern int w_webserver_state(bvm *vm);
|
||||
|
||||
extern int w_webserver_check_privileged_access(bvm *vm);
|
||||
extern int w_webserver_content_start(bvm *vm);
|
||||
extern int w_webserver_content_send(bvm *vm);
|
||||
extern int w_webserver_content_send_style(bvm *vm);
|
||||
extern int w_webserver_content_flush(bvm *vm);
|
||||
extern int w_webserver_content_stop(bvm *vm);
|
||||
extern int w_webserver_content_button(bvm *vm);
|
||||
|
||||
extern int w_webserver_args(bvm *vm);
|
||||
extern int w_webserver_arg(bvm *vm);
|
||||
extern int w_webserver_has_arg(bvm *vm);
|
||||
|
||||
#if !BE_USE_PRECOMPILED_OBJECT
|
||||
be_native_module_attr_table(webserver) {
|
||||
be_native_module_int("HTTP_OFF", 0),
|
||||
be_native_module_int("HTTP_USER", 1),
|
||||
be_native_module_int("HTTP_ADMIN", 2),
|
||||
be_native_module_int("HTTP_MANAGER", 3),
|
||||
be_native_module_int("HTTP_MANAGER_RESET_ONLY", 4),
|
||||
|
||||
be_native_module_function("on", w_webserver_on),
|
||||
be_native_module_function("state", w_webserver_state),
|
||||
|
||||
be_native_module_function("check_privileged_access", w_webserver_check_privileged_access),
|
||||
be_native_module_function("content_start", w_webserver_content_start),
|
||||
be_native_module_function("content_send", w_webserver_content_send),
|
||||
be_native_module_function("content_send_style", w_webserver_content_send_style),
|
||||
be_native_module_function("content_flush", w_webserver_content_flush),
|
||||
be_native_module_function("content_start", w_webserver_content_start),
|
||||
be_native_module_function("content_stop", w_webserver_content_stop),
|
||||
be_native_module_function("content_button", w_webserver_content_button),
|
||||
|
||||
be_native_module_function("args", w_webserver_args),
|
||||
be_native_module_function("arg", w_webserver_arg),
|
||||
be_native_module_function("has_arg", w_webserver_has_arg),
|
||||
|
||||
};
|
||||
|
||||
be_define_native_module(webserver, NULL);
|
||||
#else
|
||||
/* @const_object_info_begin
|
||||
module webserver (scope: global) {
|
||||
HTTP_OFF, int(0)
|
||||
HTTP_USER, int(1)
|
||||
HTTP_ADMIN, int(2)
|
||||
HTTP_MANAGER, int(3)
|
||||
HTTP_MANAGER_RESET_ONLY, int(4)
|
||||
|
||||
on, func(w_webserver_on)
|
||||
state, func(w_webserver_state)
|
||||
|
||||
check_privileged_access, func(w_webserver_check_privileged_access)
|
||||
content_start, func(w_webserver_content_start)
|
||||
content_send, func(w_webserver_content_send)
|
||||
content_send_style, func(w_webserver_content_send_style)
|
||||
content_flush, func(w_webserver_content_flush)
|
||||
content_start, func(w_webserver_content_start)
|
||||
content_stop, func(w_webserver_content_stop)
|
||||
content_button, func(w_webserver_content_button)
|
||||
|
||||
args, func(w_webserver_args)
|
||||
arg, func(w_webserver_arg)
|
||||
has_arg, func(w_webserver_has_arg)
|
||||
}
|
||||
@const_object_info_end */
|
||||
#include "../generate/be_fixed_webserver.h"
|
||||
#endif
|
||||
|
||||
#endif // USE_WEBSERVER
|
|
@ -19,6 +19,7 @@ class Tasmota
|
|||
elif type=='web_sensor' && d.web_sensor return d.web_sensor()
|
||||
elif type=='json_append' && d.json_append return d.json_append()
|
||||
elif type=='button_pressed' && d.button_pressed return d.button_pressed()
|
||||
elif type=='web_add_handler' && d.display return d.display()
|
||||
elif type=='display' && d.display return d.display()
|
||||
end
|
||||
except .. as e,m
|
||||
|
@ -28,4 +29,28 @@ class Tasmota
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
#- dispatch callback number n, with parameters v0,v1,v2,v3 -#
|
||||
def cb_dispatch(n,v0,v1,v2,v3)
|
||||
if self._cb == nil return 0 end
|
||||
var f = self._cb.find(n)
|
||||
if f != nil
|
||||
return f(v0,v1,v2,v3)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
#- generate a new C callback and record the associated Berry closure -#
|
||||
def gen_cb(f)
|
||||
if self._cb == nil self._cb = {} end # create map if not already initialized
|
||||
for i:0..19
|
||||
if self._cb.find(i) == nil
|
||||
#- free slot -#
|
||||
self._cb[i] = f
|
||||
return self._get_cb(i)
|
||||
end
|
||||
end
|
||||
raise "internal_error", "No callback available"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,68 +1,72 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_tasmota_map) {
|
||||
{ be_const_key(web_send, 41), be_const_func(l_webSend) },
|
||||
{ be_const_key(wire2, -1), be_const_int(0) },
|
||||
{ be_const_key(remove_cmd, 6), be_const_closure(remove_cmd_closure) },
|
||||
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(save, -1), be_const_func(l_save) },
|
||||
{ be_const_key(set_timer, 8), be_const_closure(set_timer_closure) },
|
||||
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(add_driver, 26), be_const_closure(add_driver_closure) },
|
||||
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
|
||||
{ be_const_key(i2c_enabled, 29), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
|
||||
{ be_const_key(wire1, 20), be_const_int(1) },
|
||||
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
|
||||
{ be_const_key(get_power, 3), be_const_func(l_getpower) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
|
||||
{ be_const_key(_drivers, -1), be_const_int(2) },
|
||||
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
|
||||
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
|
||||
{ be_const_key(event, -1), be_const_closure(event_closure) },
|
||||
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
|
||||
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
|
||||
{ be_const_key(_timers, 45), be_const_int(3) },
|
||||
{ be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) },
|
||||
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(response_append, 47), be_const_func(l_respAppend) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(rtc, 34), be_const_func(l_rtc) },
|
||||
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
|
||||
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) },
|
||||
{ be_const_key(_rules, -1), be_const_int(4) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(web_send_decimal, 23), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(log, 40), be_const_func(l_logInfo) },
|
||||
{ be_const_key(resp_cmnd_failed, 1), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(millis, 42), be_const_func(l_millis) },
|
||||
{ be_const_key(load, 31), be_const_closure(load_closure) },
|
||||
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
|
||||
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
|
||||
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
|
||||
{ be_const_key(get_light, 18), be_const_closure(get_light_closure) },
|
||||
{ be_const_key(gc, 41), be_const_closure(gc_closure) },
|
||||
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
|
||||
{ be_const_key(rtc, 23), be_const_func(l_rtc) },
|
||||
{ be_const_key(time_str, 9), be_const_closure(time_str_closure) },
|
||||
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
|
||||
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
|
||||
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
|
||||
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
|
||||
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
|
||||
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
|
||||
{ be_const_key(set_light, 3), be_const_closure(set_light_closure) },
|
||||
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
|
||||
{ be_const_key(scale_uint, 2), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(publish, 30), be_const_func(l_publish) },
|
||||
{ be_const_key(_ccmd, -1), be_const_int(5) },
|
||||
{ be_const_key(set_power, 44), be_const_func(l_setpower) },
|
||||
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
|
||||
{ be_const_key(add_rule, 18), be_const_closure(add_rule_closure) },
|
||||
{ be_const_key(save, -1), be_const_func(l_save) },
|
||||
{ be_const_key(_rules, -1), be_const_int(0) },
|
||||
{ be_const_key(resp_cmnd_error, 50), be_const_func(l_respCmndError) },
|
||||
{ be_const_key(wire1, 8), be_const_int(1) },
|
||||
{ be_const_key(_timers, -1), be_const_int(2) },
|
||||
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
|
||||
{ be_const_key(response_append, 46), be_const_func(l_respAppend) },
|
||||
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
|
||||
{ be_const_key(remove_rule, 35), be_const_closure(remove_rule_closure) },
|
||||
{ be_const_key(_drivers, 7), be_const_int(3) },
|
||||
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
|
||||
{ be_const_key(add_driver, 22), be_const_closure(add_driver_closure) },
|
||||
{ be_const_key(exec_rules, 20), be_const_closure(exec_rules_closure) },
|
||||
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
|
||||
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
|
||||
{ be_const_key(millis, 1), be_const_func(l_millis) },
|
||||
{ be_const_key(web_send, 11), be_const_func(l_webSend) },
|
||||
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
|
||||
{ be_const_key(yield, -1), be_const_func(l_yield) },
|
||||
{ be_const_key(delay, -1), be_const_func(l_delay) },
|
||||
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
|
||||
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
|
||||
{ be_const_key(wire2, 34), be_const_int(4) },
|
||||
{ be_const_key(event, -1), be_const_closure(event_closure) },
|
||||
{ be_const_key(load, -1), be_const_closure(load_closure) },
|
||||
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
|
||||
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
|
||||
{ be_const_key(cb_dispatch, 37), be_const_closure(cb_dispatch_closure) },
|
||||
{ be_const_key(_ccmd, -1), be_const_int(5) },
|
||||
{ be_const_key(time_reached, 51), be_const_func(l_timereached) },
|
||||
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
|
||||
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
|
||||
{ be_const_key(publish, 12), be_const_func(l_publish) },
|
||||
{ be_const_key(log, 40), be_const_func(l_logInfo) },
|
||||
{ be_const_key(_cb, -1), be_const_int(6) },
|
||||
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
|
||||
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
|
||||
{ be_const_key(resolvecmnd, 5), be_const_func(l_resolveCmnd) },
|
||||
{ be_const_key(find_key_i, 10), be_const_closure(find_key_i_closure) },
|
||||
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_tasmota_map,
|
||||
52
|
||||
56
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_tasmota,
|
||||
6,
|
||||
7,
|
||||
NULL,
|
||||
Tasmota
|
||||
);
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(m_libwebserver_map) {
|
||||
{ be_const_key(has_arg, -1), be_const_func(w_webserver_has_arg) },
|
||||
{ be_const_key(HTTP_MANAGER, -1), be_const_int(3) },
|
||||
{ be_const_key(content_start, 12), be_const_func(w_webserver_content_start) },
|
||||
{ be_const_key(args, -1), be_const_func(w_webserver_args) },
|
||||
{ be_const_key(HTTP_USER, -1), be_const_int(1) },
|
||||
{ be_const_key(content_stop, -1), be_const_func(w_webserver_content_stop) },
|
||||
{ be_const_key(arg, 10), be_const_func(w_webserver_arg) },
|
||||
{ be_const_key(HTTP_ADMIN, -1), be_const_int(2) },
|
||||
{ be_const_key(content_send_style, -1), be_const_func(w_webserver_content_send_style) },
|
||||
{ be_const_key(content_flush, 14), be_const_func(w_webserver_content_flush) },
|
||||
{ be_const_key(state, -1), be_const_func(w_webserver_state) },
|
||||
{ be_const_key(content_button, -1), be_const_func(w_webserver_content_button) },
|
||||
{ be_const_key(HTTP_OFF, -1), be_const_int(0) },
|
||||
{ be_const_key(on, 5), be_const_func(w_webserver_on) },
|
||||
{ be_const_key(content_send, -1), be_const_func(w_webserver_content_send) },
|
||||
{ be_const_key(HTTP_MANAGER_RESET_ONLY, 16), be_const_int(4) },
|
||||
{ be_const_key(check_privileged_access, -1), be_const_func(w_webserver_check_privileged_access) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
m_libwebserver_map,
|
||||
17
|
||||
);
|
||||
|
||||
static be_define_const_module(
|
||||
m_libwebserver,
|
||||
"webserver"
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_native_module(webserver, NULL);
|
|
@ -24,6 +24,7 @@
|
|||
#include <Wire.h>
|
||||
|
||||
const char kTypeError[] PROGMEM = "type_error";
|
||||
const char kInternalError[] PROGMEM = "intenal_error";
|
||||
|
||||
extern "C" {
|
||||
#include "be_exec.h"
|
||||
|
@ -148,6 +149,132 @@ extern "C" {
|
|||
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Binary search for dynamic attributes
|
||||
*
|
||||
* Names need to be sorted
|
||||
\*********************************************************************************************/
|
||||
// binary search within an array of sorted strings
|
||||
// the first 4 bytes are a pointer to a string
|
||||
// returns 0..total_elements-1 or -1 if not found
|
||||
extern "C" {
|
||||
int32_t bin_search(const char * needle, const void * table, size_t elt_size, size_t total_elements) {
|
||||
int32_t low = 0;
|
||||
int32_t high = total_elements - 1;
|
||||
int32_t mid = (low + high) / 2;
|
||||
// start a dissect
|
||||
while (low <= high) {
|
||||
const char * elt = *(const char **) ( ((uint8_t*)table) + mid * elt_size );
|
||||
int32_t comp = strcmp(needle, elt);
|
||||
if (comp < 0) {
|
||||
high = mid - 1;
|
||||
} else if (comp > 0) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
mid = (low + high) / 2;
|
||||
}
|
||||
if (low <= high) {
|
||||
return mid;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Generalized callbacks
|
||||
*
|
||||
\*********************************************************************************************/
|
||||
extern "C" {
|
||||
|
||||
typedef int32_t (*berry_callback_t)(int32_t v0, int32_t v1, int32_t v2, int32_t v3);
|
||||
|
||||
int32_t call_berry_cb(int32_t num, int32_t v0, int32_t v1, int32_t v2, int32_t v3) {
|
||||
// call berry cb dispatcher
|
||||
int32_t ret = 0;
|
||||
// get the 'tasmota' object (global) and call 'cb_dispatch'
|
||||
be_getglobal(berry.vm, PSTR("tasmota"));
|
||||
if (!be_isnil(berry.vm, -1)) {
|
||||
be_getmethod(berry.vm, -1, PSTR("cb_dispatch"));
|
||||
|
||||
if (!be_isnil(berry.vm, -1)) {
|
||||
be_pushvalue(berry.vm, -2); // add instance as first arg
|
||||
// push all args as ints (may be revised)
|
||||
be_pushint(berry.vm, num);
|
||||
be_pushint(berry.vm, v0);
|
||||
be_pushint(berry.vm, v1);
|
||||
be_pushint(berry.vm, v2);
|
||||
be_pushint(berry.vm, v3);
|
||||
|
||||
be_pcall(berry.vm, 6); // 5 arguments
|
||||
be_pop(berry.vm, 6);
|
||||
|
||||
if (be_isint(berry.vm, -1) || be_isnil(berry.vm, -1)) { // sanity check
|
||||
if (be_isint(berry.vm, -1)) {
|
||||
ret = be_toint(berry.vm, -1);
|
||||
}
|
||||
// All good, we can proceed
|
||||
be_pop(berry.vm, 2); // remove tasmota instance and result
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
be_pop(berry.vm, 1);
|
||||
}
|
||||
be_pop(berry.vm, 1);
|
||||
AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_BERRY "can't call 'tasmota.cb_dispatch'"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BERRY_CB(n) int32_t berry_cb_##n(int32_t v0, int32_t v1, int32_t v2, int32_t v3) { return call_berry_cb(n, v0, v1, v2, v3); }
|
||||
// list the callbacks
|
||||
BERRY_CB(0);
|
||||
BERRY_CB(1);
|
||||
BERRY_CB(2);
|
||||
BERRY_CB(3);
|
||||
BERRY_CB(4);
|
||||
BERRY_CB(5);
|
||||
BERRY_CB(6);
|
||||
BERRY_CB(7);
|
||||
BERRY_CB(8);
|
||||
BERRY_CB(9);
|
||||
BERRY_CB(10);
|
||||
BERRY_CB(11);
|
||||
BERRY_CB(12);
|
||||
BERRY_CB(13);
|
||||
BERRY_CB(14);
|
||||
BERRY_CB(15);
|
||||
BERRY_CB(16);
|
||||
BERRY_CB(17);
|
||||
BERRY_CB(18);
|
||||
BERRY_CB(19);
|
||||
|
||||
// array of callbacks
|
||||
berry_callback_t berry_callback_array[] {
|
||||
berry_cb_0,
|
||||
berry_cb_1,
|
||||
berry_cb_2,
|
||||
berry_cb_3,
|
||||
berry_cb_4,
|
||||
berry_cb_5,
|
||||
berry_cb_6,
|
||||
berry_cb_7,
|
||||
berry_cb_8,
|
||||
berry_cb_9,
|
||||
berry_cb_10,
|
||||
berry_cb_11,
|
||||
berry_cb_12,
|
||||
berry_cb_13,
|
||||
berry_cb_14,
|
||||
berry_cb_15,
|
||||
berry_cb_16,
|
||||
berry_cb_17,
|
||||
berry_cb_18,
|
||||
berry_cb_19,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#define LV_OBJ_CLASS "lv_obj"
|
||||
|
||||
|
|
|
@ -56,8 +56,6 @@ extern "C" {
|
|||
}
|
||||
}
|
||||
|
||||
#endif // USE_ENERGY_SENSOR
|
||||
|
||||
extern "C" {
|
||||
//
|
||||
int32_t b_wire_energymissing(struct bvm *vm);
|
||||
|
@ -67,4 +65,5 @@ extern "C" {
|
|||
|
||||
}
|
||||
|
||||
#endif // USE_ENERGY_SENSOR
|
||||
#endif // USE_BERRY
|
||||
|
|
|
@ -309,33 +309,6 @@ extern "C" {
|
|||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
// binary search within an array of sorted strings
|
||||
// the first 4 bytes are a pointer to a string
|
||||
// returns 0..total_elements-1 or -1 if not found
|
||||
int32_t bin_search(const char * needle, const void * table, size_t elt_size, size_t total_elements) {
|
||||
int32_t low = 0;
|
||||
int32_t high = total_elements - 1;
|
||||
int32_t mid = (low + high) / 2;
|
||||
// start a dissect
|
||||
while (low <= high) {
|
||||
const char * elt = *(const char **) ( ((uint8_t*)table) + mid * elt_size );
|
||||
int32_t comp = strcmp(needle, elt);
|
||||
if (comp < 0) {
|
||||
high = mid - 1;
|
||||
} else if (comp > 0) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
mid = (low + high) / 2;
|
||||
}
|
||||
if (low <= high) {
|
||||
return mid;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int be_call_c_func(bvm *vm, void * func, const char * return_type, const char * arg_type);
|
||||
|
||||
// native closure to call `be_call_c_func`
|
||||
|
|
|
@ -25,6 +25,26 @@
|
|||
|
||||
const uint32_t BERRY_MAX_LOGS = 16; // max number of print output recorded when outside of REPL, used to avoid infinite grow of logs
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Return C callback from index
|
||||
*
|
||||
\*********************************************************************************************/
|
||||
extern "C" {
|
||||
int32_t l_get_cb(struct bvm *vm);
|
||||
int32_t l_get_cb(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc >= 2 && be_isint(vm, 2)) {
|
||||
int32_t idx = be_toint(vm, 2);
|
||||
if (idx >= 0 && idx < ARRAY_SIZE(berry_callback_array)) {
|
||||
const berry_callback_t c_ptr = berry_callback_array[idx];
|
||||
be_pushcomptr(vm, (void*) c_ptr);
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Native functions mapped to Berry functions
|
||||
*
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
xdrv_52_3_berry_webserver.ino - Berry scripting language, webserver module
|
||||
|
||||
Copyright (C) 2021 Stephan Hadinger, Berry language by Guan Wenliang https://github.com/Skiars/berry
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef USE_BERRY
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
|
||||
#include <berry.h>
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Native functions mapped to Berry functions
|
||||
*
|
||||
* import webserver
|
||||
*
|
||||
\*********************************************************************************************/
|
||||
extern "C" {
|
||||
// Berry: `webserver.on(prefix:string, callback:closure) -> nil`
|
||||
//
|
||||
// WARNING - this should be called only when receiving `web_add_handler` event.
|
||||
// If called before the WebServer is set up and Wifi on, it will crash.
|
||||
// For debug purpose, it can be called later when you are sure that Wifi/Eth is up
|
||||
//
|
||||
int32_t w_webserver_on(struct bvm *vm);
|
||||
int32_t w_webserver_on(struct bvm *vm) {
|
||||
if (!Web.state) {
|
||||
be_raise(vm, kInternalError, "Web.state is 'HTTP_OFF'");
|
||||
}
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc >= 2 && be_isstring(vm, 1) && be_isclosure(vm, 2) &&
|
||||
(argc < 3 || be_isint(vm, 3)) ) { // optional third argument must be int
|
||||
uint8_t method = HTTP_ANY; // default method if not specified
|
||||
const char * prefix = be_tostring(vm, 1);
|
||||
if (argc >= 3) {
|
||||
method = be_toint(vm, 3);
|
||||
}
|
||||
|
||||
be_getglobal(vm, PSTR("tasmota"));
|
||||
if (!be_isnil(vm, -1)) {
|
||||
be_getmethod(vm, -1, PSTR("gen_cb"));
|
||||
if (!be_isnil(vm, -1)) {
|
||||
be_pushvalue(vm, -2); // add instance as first arg
|
||||
be_pushvalue(vm, 2); // push closure as second arg
|
||||
be_pcall(vm, 2); // 2 arguments
|
||||
be_pop(vm, 2);
|
||||
|
||||
if (be_iscomptr(vm, -1)) { // sanity check
|
||||
const void * cb = be_tocomptr(vm, -1);
|
||||
// All good, we can proceed
|
||||
|
||||
WebServer_on(prefix, (void (*)()) cb, method);
|
||||
be_return_nil(vm); // return, all good
|
||||
}
|
||||
}
|
||||
be_pop(vm, 1);
|
||||
}
|
||||
// be_pop(vm, 1); // not really useful since we raise an exception anyways
|
||||
be_raise(vm, kInternalError, nullptr);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
// Berry: `webserver.state() -> int`
|
||||
//
|
||||
int32_t w_webserver_state(struct bvm *vm);
|
||||
int32_t w_webserver_state(struct bvm *vm) {
|
||||
be_pushint(vm, Web.state);
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
// Berry: `webserver.check_privileged_access() -> bool`
|
||||
//
|
||||
int32_t w_webserver_check_privileged_access(struct bvm *vm);
|
||||
int32_t w_webserver_check_privileged_access(struct bvm *vm) {
|
||||
be_pushbool(vm, HttpCheckPriviledgedAccess());
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
// Berry: `webserver.content_start() -> nil`
|
||||
//
|
||||
int32_t w_webserver_content_start(struct bvm *vm);
|
||||
int32_t w_webserver_content_start(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc >= 1 && be_isstring(vm, 1)) {
|
||||
const char * html = be_tostring(vm, 1);
|
||||
WSContentStart_P(html);
|
||||
be_return_nil(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
// Berry: `webserver.content_send() -> nil`
|
||||
//
|
||||
int32_t w_webserver_content_send(struct bvm *vm);
|
||||
int32_t w_webserver_content_send(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc >= 1 && be_isstring(vm, 1)) {
|
||||
const char * html = be_tostring(vm, 1);
|
||||
WSContentSend_P(PSTR("%s"), html);
|
||||
be_return_nil(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
// Berry: `webserver.content_send_style() -> nil`
|
||||
//
|
||||
int32_t w_webserver_content_send_style(struct bvm *vm);
|
||||
int32_t w_webserver_content_send_style(struct bvm *vm) {
|
||||
WSContentSendStyle();
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
// Berry: `webserver.content_flush() -> nil`
|
||||
//
|
||||
int32_t w_webserver_content_flush(struct bvm *vm);
|
||||
int32_t w_webserver_content_flush(struct bvm *vm) {
|
||||
WSContentFlush();
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
// Berry: `webserver.content_stop() -> nil`
|
||||
//
|
||||
int32_t w_webserver_content_stop(struct bvm *vm);
|
||||
int32_t w_webserver_content_stop(struct bvm *vm) {
|
||||
WSContentStop();
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
// Berry: `webserver.content_button([button:int]) -> nil`
|
||||
// Default button is BUTTON_MAIN
|
||||
//
|
||||
int32_t w_webserver_content_button(struct bvm *vm);
|
||||
int32_t w_webserver_content_button(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc < 1 || be_isint(vm, 1)) {
|
||||
int32_t button = BUTTON_MAIN;
|
||||
if (argc > 0) {
|
||||
button = be_toint(vm, 1);
|
||||
}
|
||||
WSContentSpaceButton(button);
|
||||
be_return_nil(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
// Berry: `webserver.args() -> int`
|
||||
//
|
||||
// Returns the number of arguments
|
||||
int32_t w_webserver_args(struct bvm *vm);
|
||||
int32_t w_webserver_args(struct bvm *vm) {
|
||||
be_pushint(vm, Webserver->args());
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
// Berry: `webserver.arg(int or string) -> string`
|
||||
//
|
||||
// takes either an int (index 0..args-1) or a string (name of arg)
|
||||
int32_t w_webserver_arg(struct bvm *vm);
|
||||
int32_t w_webserver_arg(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc >= 1 && (be_isint(vm, 1) || be_isstring(vm, 1))) {
|
||||
if (be_isint(vm, 1)) {
|
||||
int32_t idx = be_toint(vm, 1);
|
||||
be_pushstring(vm, Webserver->arg(idx).c_str());
|
||||
} else {
|
||||
const char * arg_name = be_tostring(vm, 1);
|
||||
be_pushstring(vm, Webserver->arg(arg_name).c_str());
|
||||
}
|
||||
be_return(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
// Berry: `webserver.has_arg(name:string) -> bool`
|
||||
//
|
||||
int32_t w_webserver_has_arg(struct bvm *vm);
|
||||
int32_t w_webserver_has_arg(struct bvm *vm) {
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc >= 1 && be_isstring(vm, 1)) {
|
||||
const char * arg_name = be_tostring(vm, 1);
|
||||
be_pushbool(vm, Webserver->hasArg(arg_name));
|
||||
be_return(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // USE_WEBSERVER
|
||||
#endif // USE_BERRY
|
|
@ -743,7 +743,7 @@ bool Xdrv52(uint8_t function)
|
|||
callBerryEventDispatcher(PSTR("web_add_main_button"), nullptr, 0, nullptr);
|
||||
break;
|
||||
case FUNC_WEB_ADD_HANDLER:
|
||||
// callBerryEventDispatcher(PSTR("web_add_handler"), nullptr, 0, nullptr);
|
||||
callBerryEventDispatcher(PSTR("web_add_handler"), nullptr, 0, nullptr);
|
||||
WebServer_on(PSTR("/bs"), HandleBerryConsole);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
|
|
Loading…
Reference in New Issue