Skip to content

Commit

Permalink
Berry move mapping from C++ to C
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger committed Sep 3, 2023
1 parent fe0423c commit cb89b60
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

extern int be_ntv_display_start(bvm *vm);
extern int be_ntv_display_dimmer(bvm *vm);
extern bool be_ntv_display_started(void);
extern bbool be_ntv_display_started(void);
BE_FUNC_CTYPE_DECLARE(be_ntv_display_started, "b", "")
extern void be_ntv_display_touch_update(int32_t touches, int32_t raw_x, int32_t raw_y, int32_t gesture);
BE_FUNC_CTYPE_DECLARE(be_ntv_display_touch_update, "", "iiii")
Expand Down
115 changes: 115 additions & 0 deletions lib/libesp32/berry_tasmota/src/be_light_state_class.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/********************************************************************
* Light_state class - abstract light state
*
* Handles all states and events for a virtual light.
* Can be eventually subclassed to handle a physical light.
*
*******************************************************************/
#ifdef USE_LIGHT

#include "be_constobj.h"
#include "be_mapping.h"

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

extern void * ls_init(int32_t type); BE_FUNC_CTYPE_DECLARE(ls_init, "+_p", "i")
extern void ls_set_rgb(void* l, int32_t r, int32_t g, int32_t b); BE_FUNC_CTYPE_DECLARE(ls_set_rgb, "", ".iii")
extern void ls_set_huesat(void* l, int32_t hue, int32_t sat); BE_FUNC_CTYPE_DECLARE(ls_set_huesat, "", ".ii")
extern void ls_set_hue16sat(void* l, int32_t hue16, int32_t sat); BE_FUNC_CTYPE_DECLARE(ls_set_hue16sat, "", ".ii")
extern void ls_set_ct(void* l, int32_t ct); BE_FUNC_CTYPE_DECLARE(ls_set_ct, "", ".i")
extern void ls_set_bri(void* l, int32_t bri); BE_FUNC_CTYPE_DECLARE(ls_set_bri, "", ".i")
extern void ls_set_xy(void* l, float x, float y); BE_FUNC_CTYPE_DECLARE(ls_set_xy, "", ".ff")
extern int32_t ls_r(void* l); BE_VAR_CTYPE_DECLARE(ls_r, "i");
extern int32_t ls_g(void* l); BE_VAR_CTYPE_DECLARE(ls_g, "i");
extern int32_t ls_b(void* l); BE_VAR_CTYPE_DECLARE(ls_b, "i");
extern float ls_x(void* l); BE_VAR_CTYPE_DECLARE(ls_x, "f");
extern float ls_y(void* l); BE_VAR_CTYPE_DECLARE(ls_y, "f");
extern int32_t ls_hue(void* l); BE_VAR_CTYPE_DECLARE(ls_hue, "i");
extern int32_t ls_hue16(void* l); BE_VAR_CTYPE_DECLARE(ls_hue16, "i");
extern int32_t ls_sat(void* l); BE_VAR_CTYPE_DECLARE(ls_sat, "i");
extern int32_t ls_bri(void* l); BE_VAR_CTYPE_DECLARE(ls_bri, "i");
extern int32_t ls_ct(void* l); BE_VAR_CTYPE_DECLARE(ls_ct, "i");
extern int32_t ls_type(void* l); BE_VAR_CTYPE_DECLARE(ls_type, "i");

extern int32_t ls_mode_rgb(void* l); BE_VAR_CTYPE_DECLARE(ls_mode_rgb, "b");
extern int32_t ls_mode_ct(void* l); BE_VAR_CTYPE_DECLARE(ls_mode_ct, "b");
extern void ls_set_mode_rgb(void* l); BE_FUNC_CTYPE_DECLARE(ls_set_mode_rgb, "", ".");
extern void ls_set_mode_ct(void* l); BE_FUNC_CTYPE_DECLARE(ls_set_mode_ct, "", ".");
extern int32_t ls_get_power(void* l); BE_VAR_CTYPE_DECLARE(ls_get_power, "b");
extern void ls_set_power(void* l, int32_t pow); BE_FUNC_CTYPE_DECLARE(ls_set_power, "", ".b");
extern int32_t ls_reachable(void* p); BE_VAR_CTYPE_DECLARE(ls_reachable, "b");
extern void ls_set_reachable(void* l, int32_t pow); BE_FUNC_CTYPE_DECLARE(ls_set_reachable, "", ".b");

extern void ls_signal_change(void) {} BE_FUNC_CTYPE_DECLARE(ls_signal_change, "", ".");

extern int32_t ls_gamma8(int32_t val); BE_FUNC_CTYPE_DECLARE(ls_gamma8, "i", "i")
extern int32_t ls_gamma10(int32_t val); BE_FUNC_CTYPE_DECLARE(ls_gamma10, "i", "i")
extern int32_t ls_rev_gamma10(int32_t val); BE_FUNC_CTYPE_DECLARE(ls_rev_gamma10, "i", "i")

// moved to constants array
const be_const_member_t light_state_members[] = {
{ ">b", be_ctype(ls_b) },
{ ">bri", be_ctype(ls_bri) },
{ ">ct", be_ctype(ls_ct) },
{ ">g", be_ctype(ls_g) },
{ ">hue", be_ctype(ls_hue) },
{ ">hue16", be_ctype(ls_hue16) },
{ ">mode_ct", be_ctype(ls_mode_ct) },
{ ">mode_rgb", be_ctype(ls_mode_rgb) },
{ ">power", be_ctype(ls_get_power) },
{ ">r", be_ctype(ls_r) },
{ ">reachable", be_ctype(ls_reachable) },
{ ">sat", be_ctype(ls_sat) },
{ ">type", be_ctype(ls_type) },
{ ">x", be_ctype(ls_x) },
{ ">y", be_ctype(ls_y) },
};

extern int light_state_get(bvm *vm);

static int light_state_member(bvm *vm) {
be_const_class_member_raise(vm, light_state_members, ARRAY_SIZE(light_state_members));
be_return(vm);
}

#include "be_fixed_be_class_light_state.h"

/* @const_object_info_begin
class be_class_light_state (scope: global, name: light_state) {
RELAY, int(0)
DIMMER, int(1)
CT, int(2)
RGB, int(3)
RGBW, int(4)
RGBCT, int(5)
_p, var
init, ctype_func(ls_init)
member, func(light_state_member)
set_rgb, ctype_func(ls_set_rgb)
set_huesat, ctype_func(ls_set_huesat)
set_hue16sat, ctype_func(ls_set_hue16sat)
set_xy, ctype_func(ls_set_xy)
set_ct, ctype_func(ls_set_ct)
set_bri, ctype_func(ls_set_bri)
set_mode_rgb, ctype_func(ls_set_mode_rgb)
set_mode_ct, ctype_func(ls_set_mode_ct)
set_power, ctype_func(ls_set_power)
set_reachable, ctype_func(ls_set_reachable)
get, func(light_state_get)
signal_change, ctype_func(ls_signal_change)
gamma8, static_ctype_func(ls_gamma8)
gamma10, static_ctype_func(ls_gamma10)
reverse_gamma10, static_ctype_func(ls_rev_gamma10)
}
@const_object_info_end */

#endif // USE_LIGHT
121 changes: 0 additions & 121 deletions lib/libesp32/berry_tasmota/src/be_light_state_class.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ extern char* tlr_get_log(uint32_t* idx, int32_t log_level); BE_FUNC_CTYPE_DECLAR

#include "be_fixed_be_class_tasmota_log_reader.h"

extern "C" void be_load_tasmota_log_reader_class(bvm *vm) {
be_pushntvclass(vm, &be_class_tasmota_log_reader);
be_setglobal(vm, "tasmota_log_reader");
be_pop(vm, 1);
}
/* @const_object_info_begin
class be_class_tasmota_log_reader (scope: global, name: tasmota_log_reader) {
Expand Down
24 changes: 24 additions & 0 deletions lib/libesp32/berry_tasmota/src/be_unishox_lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************
* Berry module `unishox`
*
* To use: `import unishox`
*
* Allows to respond to HTTP request
*******************************************************************/

#ifdef USE_UNISHOX_COMPRESSION

#include "be_constobj.h"

extern int be_ntv_unishox_compress(bvm *vm);
extern int be_ntv_unishox_decompress(bvm *vm);

/* @const_object_info_begin
module unishox (scope: global) {
decompress, func(be_ntv_unishox_decompress)
compress, func(be_ntv_unishox_compress)
}
@const_object_info_end */
#include "be_fixed_unishox.h"

#endif // USE_UNISHOX_COMPRESSION
83 changes: 0 additions & 83 deletions lib/libesp32/berry_tasmota/src/be_unishox_lib.cpp

This file was deleted.

Loading

0 comments on commit cb89b60

Please sign in to comment.