top three button
This commit is contained in:
parent
b97c00605e
commit
41131514cb
|
@ -1,16 +1,7 @@
|
|||
#include <user_code.hpp>
|
||||
|
||||
/*
|
||||
Environment Details
|
||||
P0-P2: Fans
|
||||
P3-P6: Lights
|
||||
P7: Air Purifier
|
||||
I0-I2: Fan Switch
|
||||
*/
|
||||
|
||||
|
||||
// Display Componets
|
||||
NexText clock_txt = NexText(1,2,"clock");
|
||||
NexText clock_txt = NexText(1, 2, "clock");
|
||||
NexDSButton lt_bt = NexDSButton(1, 3, "lt_bt");
|
||||
NexDSButton fan_bt = NexDSButton(1, 4, "fan_bt");
|
||||
NexDSButton puri_bt = NexDSButton(1, 5, "puri_bt");
|
||||
|
@ -24,7 +15,6 @@ NexButton fan_1_btn = NexButton(1, 12, "fan_1_btn");
|
|||
NexButton fan_2_btn = NexButton(1, 13, "fan_2_btn");
|
||||
NexButton fan_3_btn = NexButton(1, 14, "fan_3_btn");
|
||||
|
||||
|
||||
// List of Component ID Message to listen to
|
||||
NexTouch *nex_listen_list[] =
|
||||
{
|
||||
|
@ -62,7 +52,16 @@ void user_init()
|
|||
ESPMega_EXTLCD.write(0xFF);
|
||||
lt_bt.attachPop(lt_btn_cb, <_bt);
|
||||
fan_bt.attachPop(fan_btn_cb, &fan_bt);
|
||||
|
||||
puri_bt.attachPop(puri_btn_cb, &puri_bt);
|
||||
up_bt.attachPop(ac_temp_adj_btn_cb, &up_bt);
|
||||
down_bt.attachPop(ac_temp_adj_btn_cb, &down_bt);
|
||||
mode_off_btn.attachPop(ac_mode_adj_btn_cb, &mode_off_btn);
|
||||
mode_fan_btn.attachPop(ac_mode_adj_btn_cb, &mode_fan_btn);
|
||||
mode_cool_btn.attachPop(ac_mode_adj_btn_cb, &mode_cool_btn);
|
||||
fan_auto_btn.attachPop(ac_fan_adj_btn_cb, &fan_auto_btn);
|
||||
fan_1_btn.attachPop(ac_fan_adj_btn_cb, &fan_1_btn);
|
||||
fan_2_btn.attachPop(ac_fan_adj_btn_cb, &fan_2_btn);
|
||||
fan_3_btn.attachPop(ac_fan_adj_btn_cb, &fan_3_btn);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -82,7 +81,18 @@ void virtual_interrupt_user_callback(int pin, int state)
|
|||
|
||||
void pwm_changed_user_callback(int pin)
|
||||
{
|
||||
|
||||
if ((pin == LIGHT1_PIN) || (pin == LIGHT2_PIN) || (pin == LIGHT3_PIN) || (pin = LIGHT4_PIN))
|
||||
{
|
||||
lt_bt.setValue(cud_light_group_state());
|
||||
}
|
||||
else if (pin == FAN1_PIN || pin == FAN2_PIN || pin == FAN3_PIN)
|
||||
{
|
||||
fan_bt.setValue(cud_fan_group_state());
|
||||
}
|
||||
else if (pin == AIR_PURIFIER_PIN)
|
||||
{
|
||||
puri_bt.setValue(pwm_get_state(pin));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -90,24 +100,54 @@ This code will run every 15 seconds
|
|||
*/
|
||||
void timer_tick_callback()
|
||||
{
|
||||
|
||||
char time_buffer[15];
|
||||
rtctime_t time = ESPMega_getTime();
|
||||
sprintf(time_buffer, "%02d:%02d", time.hours, time.minutes);
|
||||
clock_txt.setText(time_buffer);
|
||||
}
|
||||
|
||||
void lt_btn_cb(void *comp) {
|
||||
|
||||
void lt_btn_cb(void *comp)
|
||||
{
|
||||
cud_light_toggle();
|
||||
}
|
||||
void fan_btn_cb(void *comp) {
|
||||
|
||||
void fan_btn_cb(void *comp)
|
||||
{
|
||||
cud_fan_toggle();
|
||||
}
|
||||
void puri_btn_cb(void *comp) {
|
||||
|
||||
void puri_btn_cb(void *comp)
|
||||
{
|
||||
pwm_toggle(AIR_PURIFIER_PIN);
|
||||
}
|
||||
void ac_temp_adj_btn_cb(void *comp) {
|
||||
|
||||
void ac_temp_adj_btn_cb(void *comp)
|
||||
{
|
||||
}
|
||||
void ac_mode_adj_btn_cb(void *comp) {
|
||||
|
||||
void ac_mode_adj_btn_cb(void *comp)
|
||||
{
|
||||
}
|
||||
void ac_fan_adj_btn_cb(void *comp)
|
||||
{
|
||||
}
|
||||
void ac_fan_adj_btn_cb(void *comp) {
|
||||
|
||||
void cud_light_toggle()
|
||||
{
|
||||
bool new_state = !cud_light_group_state();
|
||||
pwm_set_state(LIGHT1_PIN, new_state);
|
||||
pwm_set_state(LIGHT2_PIN, new_state);
|
||||
pwm_set_state(LIGHT3_PIN, new_state);
|
||||
pwm_set_state(LIGHT4_PIN, new_state);
|
||||
}
|
||||
bool cud_light_group_state()
|
||||
{
|
||||
return pwm_get_state(LIGHT1_PIN) || pwm_get_state(LIGHT2_PIN) || pwm_get_state(LIGHT3_PIN) || pwm_get_state(LIGHT4_PIN);
|
||||
}
|
||||
void cud_fan_toggle()
|
||||
{
|
||||
bool new_state = !cud_fan_group_state();
|
||||
pwm_set_state(FAN1_PIN, new_state);
|
||||
pwm_set_state(FAN2_PIN, new_state);
|
||||
pwm_set_state(FAN3_PIN, new_state);
|
||||
}
|
||||
bool cud_fan_group_state()
|
||||
{
|
||||
return pwm_get_state(FAN1_PIN) || pwm_get_state(FAN2_PIN) || pwm_get_state(FAN3_PIN);
|
||||
}
|
|
@ -6,6 +6,32 @@
|
|||
#include "espmega_iot_timer.hpp"
|
||||
#include "espmega_iot_external_lcd.hpp"
|
||||
|
||||
/*
|
||||
Environment Details
|
||||
P0-P2: Fans
|
||||
P3-P6: Lights
|
||||
P7: Air Purifier
|
||||
I0-I2: Fan Switch
|
||||
*/
|
||||
|
||||
// Pin Definition
|
||||
#define FAN1_PIN 0
|
||||
#define FAN2_PIN 1
|
||||
#define FAN3_PIN 2
|
||||
#define LIGHT1_PIN 3
|
||||
#define LIGHT2_PIN 4
|
||||
#define LIGHT3_PIN 5
|
||||
#define LIGHT4_PIN 6
|
||||
#define AIR_PURIFIER_PIN 7
|
||||
#define FAN1_BTN_PIN 0
|
||||
#define FAN2_BTN_PIN 1
|
||||
#define FAN3_BTN_PIN 2
|
||||
#define LIGHT1_BTN_PIN 3
|
||||
#define LIGHT2_BTN_PIN 4
|
||||
#define LIGHT3_BTN_PIN 5
|
||||
#define LIGHT4_BTN_PIN 6
|
||||
#define AIR_PURIFIER_BTN_PIN 7
|
||||
|
||||
// External LCD Configuration
|
||||
#define ENABLE_EXTERNAL_LCD
|
||||
#define TXD2 4
|
||||
|
@ -28,7 +54,10 @@ void puri_btn_cb(void *comp);
|
|||
void ac_temp_adj_btn_cb(void *comp);
|
||||
void ac_mode_adj_btn_cb(void *comp);
|
||||
void ac_fan_adj_btn_cb(void *comp);
|
||||
|
||||
void cud_light_toggle();
|
||||
bool cud_light_group_state();
|
||||
void cud_fan_toggle();
|
||||
bool cud_fan_group_state();
|
||||
|
||||
|
||||
// ESPMega IoT Core Build-in Functions
|
||||
|
|
Loading…
Reference in New Issue