113 lines
2.2 KiB
C++
113 lines
2.2 KiB
C++
void nextion_send(const char* idx, const char* val)
|
|
{
|
|
char buf[50];
|
|
|
|
char* part1 = "=\"";
|
|
char* part2 = "\"";
|
|
|
|
strcpy(buf, idx);
|
|
strcpy(buf + strlen(idx), part1);
|
|
strcpy(buf + strlen(idx) + strlen(part1), val);
|
|
strcpy(buf + strlen(idx) + strlen(part1) + strlen(val), part2);
|
|
#ifdef DEBUG
|
|
Serial.println(buf);
|
|
#endif
|
|
sendCommand(buf);
|
|
}
|
|
|
|
|
|
void nex_send_float(const char* idx, float val, int len, int dec)
|
|
{
|
|
char buf[50];
|
|
|
|
char result[8]; // Buffer big enough for 7-character float
|
|
dtostrf(val, len, dec, result); // Leave room for too large numbers!
|
|
|
|
char* part1 = "=\"";
|
|
char* part2 = "\"";
|
|
|
|
strcpy(buf, idx);
|
|
strcpy(buf + strlen(idx), part1);
|
|
strcpy(buf + strlen(idx) + strlen(part1), result);
|
|
strcpy(buf + strlen(idx) + strlen(part1) + strlen(result), part2);
|
|
#ifdef DEBUG
|
|
Serial.println(buf);
|
|
#endif
|
|
sendCommand(buf);
|
|
}
|
|
|
|
|
|
void btn_1_PopCallback(void *ptr)
|
|
{
|
|
uint32_t dual_state;
|
|
|
|
btn_1.getValue(&dual_state);
|
|
if (dual_state)
|
|
main_btn_hanglamp = 1;
|
|
else
|
|
main_btn_hanglamp = 0;
|
|
|
|
domoticz_send_nvalue(idx_hanglamp, main_btn_hanglamp);
|
|
}
|
|
|
|
|
|
void btn_2_PopCallback(void *ptr)
|
|
{
|
|
uint32_t dual_state;
|
|
|
|
btn_2.getValue(&dual_state);
|
|
if (dual_state)
|
|
main_btn_staandelamp = 1;
|
|
else
|
|
main_btn_staandelamp = 0;
|
|
|
|
domoticz_send_nvalue(idx_staandelamp, main_btn_staandelamp);
|
|
}
|
|
|
|
|
|
void btn_3_PopCallback(void *ptr)
|
|
{
|
|
uint32_t dual_state;
|
|
|
|
/* Get the state value of dual state button component . */
|
|
btn_3.getValue(&dual_state);
|
|
if (dual_state)
|
|
main_btn_haardverlichting = 1;
|
|
else
|
|
main_btn_haardverlichting = 0;
|
|
|
|
domoticz_send_nvalue(idx_haardverlichting, main_btn_haardverlichting);
|
|
}
|
|
|
|
|
|
void btn_4_PopCallback(void *ptr)
|
|
{
|
|
uint32_t dual_state;
|
|
|
|
/* Get the state value of dual state button component . */
|
|
btn_4.getValue(&dual_state);
|
|
if (dual_state)
|
|
main_btn_tuinverlichting = 1;
|
|
else
|
|
main_btn_tuinverlichting = 0;
|
|
|
|
domoticz_send_nvalue(idx_tuinverlichting, main_btn_tuinverlichting);
|
|
}
|
|
|
|
|
|
void btn_5_PopCallback(void *ptr)
|
|
{
|
|
uint32_t dual_state;
|
|
|
|
/* Get the state value of dual state button component . */
|
|
btn_5.getValue(&dual_state);
|
|
if (dual_state)
|
|
{
|
|
domoticz_send_nvalue(idx_rooster, 1);
|
|
}
|
|
else
|
|
{
|
|
domoticz_send_nvalue(idx_rooster, 0);
|
|
}
|
|
}
|