Berry add `display.dimmer()`

This commit is contained in:
Stephan Hadinger 2022-01-29 11:11:21 +01:00
parent 6dafe7cb60
commit 98ddcc6658
5 changed files with 1015 additions and 986 deletions

View File

@ -333,6 +333,7 @@ extern const bcstring be_const_str_detect;
extern const bcstring be_const_str_detected_X20on_X20bus;
extern const bcstring be_const_str_digital_read;
extern const bcstring be_const_str_digital_write;
extern const bcstring be_const_str_dimmer;
extern const bcstring be_const_str_dirty;
extern const bcstring be_const_str_display;
extern const bcstring be_const_str_display_X2Eini;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
#include "be_constobj.h"
static be_define_const_map_slots(m_libdisplay_map) {
{ be_const_key(dimmer, -1), be_const_func(be_ntv_display_dimmer) },
{ be_const_key(start, 0), be_const_func(be_ntv_display_start) },
};
static be_define_const_map(
m_libdisplay_map,
2
);
static be_define_const_module(
m_libdisplay,
"display"
);
BE_EXPORT_VARIABLE be_define_const_native_module(display);

View File

@ -9,21 +9,15 @@
#ifdef USE_DISPLAY
// Tasmota specific
extern int be_ntv_display_start(bvm *vm);
extern int be_ntv_display_dimmer(bvm *vm);
/********************************************************************
** Solidified module: display
********************************************************************/
be_local_module(display,
"display",
be_nested_map(1,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_const_key(start, -1), be_const_func(be_ntv_display_start) },
}))
);
BE_EXPORT_VARIABLE be_define_const_native_module(display);
/********************************************************************/
/* @const_object_info_begin
module display (scope: global) {
start, func(be_ntv_display_start)
dimmer, func(be_ntv_display_dimmer)
}
@const_object_info_end */
#include "be_fixed_display.h"
#endif // USE_DISPLAY
#endif // USE_DISPLAY

View File

@ -35,10 +35,8 @@ Renderer *Init_uDisplay(const char *desc);
*
\*********************************************************************************************/
extern "C" {
int be_ntv_display_start(bvm *vm);
int be_ntv_display_start(bvm *vm) {
#ifdef USE_UNIVERSAL_DISPLAY
#ifdef USE_UNIVERSAL_DISPLAY
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 1 && be_isstring(vm, 1)) {
const char * desc = be_tostring(vm, 1);
@ -53,9 +51,25 @@ extern "C" {
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
#else // USE_UNIVERSAL_DISPLAY
#else // USE_UNIVERSAL_DISPLAY
be_raise(vm, "internal_error", "universal display driver not present");
#endif // USE_UNIVERSAL_DISPLAY
#endif // USE_UNIVERSAL_DISPLAY
}
// `display.dimmer([dim:int]) -> int` sets the dimmer of display, value 0..100. If `0` then turn off display. If no arg, read the current value.
int be_ntv_display_dimmer(bvm *vm) {
int32_t argc = be_top(vm); // Get the number of arguments
int32_t dimmer;
if (argc >= 1) {
if (!be_isint(vm, 1)) { be_raise(vm, "type_error", "arg must be int"); }
dimmer = be_toint(vm, 1);
if ((dimmer < 0) || (dimmer > 100)) { be_raise(vm, "value_error", "value must be in range 0..100"); }
be_pop(vm, argc); // clear stack to avoid ripple errors in code called later
SetDisplayDimmer(dimmer);
ApplyDisplayDimmer();
}
be_pushint(vm, GetDisplayDimmer());
be_return(vm);
}
}