Merge pull request #10349 from clanganke/pr_7segdispupate

- for 7 segment displays
This commit is contained in:
Theo Arends 2021-01-02 16:32:25 +01:00 committed by GitHub
commit 461e9a4c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 4 deletions

View File

@ -63,6 +63,7 @@ const uint8_t DISPLAY_LOG_ROWS = 32; // Number of lines in display log
#define D_CMND_DISP_TEXT "Text"
#define D_CMND_DISP_WIDTH "Width"
#define D_CMND_DISP_HEIGHT "Height"
#define D_CMND_DISP_BLINKRATE "Blinkrate"
enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_EVERY_50_MSECOND, FUNC_DISPLAY_EVERY_SECOND,
FUNC_DISPLAY_MODEL, FUNC_DISPLAY_MODE, FUNC_DISPLAY_POWER,
@ -70,19 +71,20 @@ enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_E
FUNC_DISPLAY_DRAW_HLINE, FUNC_DISPLAY_DRAW_VLINE, FUNC_DISPLAY_DRAW_LINE,
FUNC_DISPLAY_DRAW_CIRCLE, FUNC_DISPLAY_FILL_CIRCLE,
FUNC_DISPLAY_DRAW_RECTANGLE, FUNC_DISPLAY_FILL_RECTANGLE,
FUNC_DISPLAY_TEXT_SIZE, FUNC_DISPLAY_FONT_SIZE, FUNC_DISPLAY_ROTATION, FUNC_DISPLAY_DRAW_STRING };
FUNC_DISPLAY_TEXT_SIZE, FUNC_DISPLAY_FONT_SIZE, FUNC_DISPLAY_ROTATION, FUNC_DISPLAY_DRAW_STRING,
FUNC_DISPLAY_DIM, FUNC_DISPLAY_BLINKRATE };
enum DisplayInitModes { DISPLAY_INIT_MODE, DISPLAY_INIT_PARTIAL, DISPLAY_INIT_FULL };
const char kDisplayCommands[] PROGMEM = D_PRFX_DISPLAY "|" // Prefix
"|" D_CMND_DISP_MODEL "|" D_CMND_DISP_WIDTH "|" D_CMND_DISP_HEIGHT "|" D_CMND_DISP_MODE "|" D_CMND_DISP_REFRESH "|"
D_CMND_DISP_DIMMER "|" D_CMND_DISP_COLS "|" D_CMND_DISP_ROWS "|" D_CMND_DISP_SIZE "|" D_CMND_DISP_FONT "|"
D_CMND_DISP_ROTATE "|" D_CMND_DISP_TEXT "|" D_CMND_DISP_ADDRESS ;
D_CMND_DISP_ROTATE "|" D_CMND_DISP_TEXT "|" D_CMND_DISP_ADDRESS "|" D_CMND_DISP_BLINKRATE ;
void (* const DisplayCommand[])(void) PROGMEM = {
&CmndDisplay, &CmndDisplayModel, &CmndDisplayWidth, &CmndDisplayHeight, &CmndDisplayMode, &CmndDisplayRefresh,
&CmndDisplayDimmer, &CmndDisplayColumns, &CmndDisplayRows, &CmndDisplaySize, &CmndDisplayFont,
&CmndDisplayRotate, &CmndDisplayText, &CmndDisplayAddress };
&CmndDisplayRotate, &CmndDisplayText, &CmndDisplayAddress, &CmndDisplayBlinkrate };
char *dsp_str;
@ -1410,11 +1412,24 @@ void CmndDisplayDimmer(void)
else if (!Settings.display_dimmer && disp_power) {
ExecuteCommandPower(disp_device, POWER_OFF, SRC_DISPLAY);
}
if (renderer) renderer->dim(Settings.display_dimmer);
if (renderer)
renderer->dim(Settings.display_dimmer);
else
XdspCall(FUNC_DISPLAY_DIM);
}
ResponseCmndNumber(Settings.display_dimmer);
}
void CmndDisplayBlinkrate(void)
{
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) {
if (!renderer)
XdspCall(FUNC_DISPLAY_BLINKRATE);
}
ResponseCmndNumber(XdrvMailbox.payload);
}
void CmndDisplaySize(void)
{
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= 4)) {

View File

@ -62,6 +62,61 @@ void SevensegWrite(void)
}
}
void SevensegLog(void)
{
// get sensor data
ResponseClear();
ResponseAppendTime();
XsnsCall(FUNC_JSON_APPEND);
ResponseJsonEnd();
// display nth sensor value on nth display
// code adapted from xdrv_13_display.ino, DisplayAnalyzeJson()
uint8_t unit = 0;
int16_t valueDecimal = 0;
double valueFloat = 0;
uint8 fDigits = 0;
String jsonStr = TasmotaGlobal.mqtt_data; // Move from stack to heap to fix watchdogs (20180626)
JsonParser parser((char*)jsonStr.c_str());
JsonParserObject object_root = parser.getRootObject();
if (object_root) {
for (auto key_level1 : object_root) {
JsonParserToken token_level1 = key_level1.getValue();
if (token_level1.isObject()) {
JsonParserObject object_level1 = token_level1.getObject();
for (auto key_level2 : object_level1) {
const char* value_level2 = key_level2.getValue().getStr(nullptr);
if (value_level2 != nullptr) {
if ((unit < sevensegs) && (sevenseg[unit] != nullptr)) {
if (strchr( value_level2, '.') == NULL) {
sevenseg[unit]->print(atoi(value_level2), DEC);
} else {
sevenseg[unit]->printFloat(atof(value_level2), 1, DEC);
}
sevenseg[unit]->writeDisplay();
unit++;
}
}
}
}
}
}
}
void SevensegDim(void)
{
for (uint32_t i = 0; i < sevensegs; i++) {
sevenseg[i]->setBrightness(Settings.display_dimmer);
}
}
void SevensegBlinkrate( void)
{
for (uint32_t i = 0; i < sevensegs; i++) {
sevenseg[i]->blinkRate(XdrvMailbox.payload);
}
}
void SevensegClear(void)
{
for (uint32_t i = 0; i < sevensegs; i++) {
@ -352,6 +407,7 @@ void SevensegRefresh(void) // Every second
case 4: // Mqtt
case 3: // Local
case 5: { // Mqtt
SevensegLog();
break;
}
}
@ -396,6 +452,13 @@ bool Xdsp11(uint8_t function)
case FUNC_DISPLAY_DRAW_STRING:
SevensegDrawStringAt(dsp_x, dsp_y, dsp_str, dsp_color, dsp_flag);
break;
case FUNC_DISPLAY_DIM:
SevensegDim();
break;
case FUNC_DISPLAY_BLINKRATE:
SevensegBlinkrate();
break;
}
}
return result;