update user code
This commit is contained in:
		
							parent
							
								
									2fe04bcdfa
								
							
						
					
					
						commit
						b97c00605e
					
				
					 3 changed files with 63 additions and 30 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -1,24 +1,47 @@
 | 
			
		|||
#include <user_code.hpp>
 | 
			
		||||
 | 
			
		||||
//Timer Components
 | 
			
		||||
ESPMega_Timer timer1(0, 50, timer1_callback, 15001);
 | 
			
		||||
/*
 | 
			
		||||
Environment Details
 | 
			
		||||
P0-P2: Fans
 | 
			
		||||
P3-P6: Lights
 | 
			
		||||
P7: Air Purifier
 | 
			
		||||
I0-I2: Fan Switch
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Display Componets
 | 
			
		||||
// Link with Dual state button object with id 2 on page 1 named bt0
 | 
			
		||||
NexDSButton bt0 = NexDSButton(1, 2, "bt0");
 | 
			
		||||
NexText clock_txt = NexText(1,3,"clock_txt");
 | 
			
		||||
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");
 | 
			
		||||
NexButton up_bt = NexButton(1, 6, "up_bt");
 | 
			
		||||
NexButton down_bt = NexButton(1, 7, "down_bt");
 | 
			
		||||
NexButton mode_off_btn = NexButton(1, 8, "mode_off_btn");
 | 
			
		||||
NexButton mode_fan_btn = NexButton(1, 9, "mode_fan_btn");
 | 
			
		||||
NexButton mode_cool_btn = NexButton(1, 10, "mode_cool_btn");
 | 
			
		||||
NexButton fan_auto_btn = NexButton(1, 11, "fan_auto_btn");
 | 
			
		||||
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[] =
 | 
			
		||||
    {
 | 
			
		||||
        &bt0,
 | 
			
		||||
        <_bt,
 | 
			
		||||
        &fan_bt,
 | 
			
		||||
        &puri_bt,
 | 
			
		||||
        &up_bt,
 | 
			
		||||
        &down_bt,
 | 
			
		||||
        &mode_off_btn,
 | 
			
		||||
        &mode_fan_btn,
 | 
			
		||||
        &mode_cool_btn,
 | 
			
		||||
        &fan_auto_btn,
 | 
			
		||||
        &fan_1_btn,
 | 
			
		||||
        &fan_2_btn,
 | 
			
		||||
        &fan_3_btn,
 | 
			
		||||
        NULL};
 | 
			
		||||
 | 
			
		||||
void bt0PopCallback(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    pwm_toggle(2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
This Code will run right after ESPMega PRO's
 | 
			
		||||
Peripheral Initialization Routine
 | 
			
		||||
| 
						 | 
				
			
			@ -33,12 +56,13 @@ This code will run after every component is initialized
 | 
			
		|||
*/
 | 
			
		||||
void user_init()
 | 
			
		||||
{
 | 
			
		||||
    timer1.begin();
 | 
			
		||||
    ESPMega_EXTLCD.print("page dashboard");
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    bt0.attachPop(bt0PopCallback, &bt0);
 | 
			
		||||
    lt_bt.attachPop(lt_btn_cb, <_bt);
 | 
			
		||||
    fan_bt.attachPop(fan_btn_cb, &fan_bt);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -58,11 +82,7 @@ void virtual_interrupt_user_callback(int pin, int state)
 | 
			
		|||
 | 
			
		||||
void pwm_changed_user_callback(int pin)
 | 
			
		||||
{
 | 
			
		||||
    if (pin == 2)
 | 
			
		||||
    {
 | 
			
		||||
        // inform the lcd when pwm 2 changed
 | 
			
		||||
        bt0.setValue(pwm_get_state(2));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -70,16 +90,24 @@ This code will run every 15 seconds
 | 
			
		|||
*/
 | 
			
		||||
void timer_tick_callback()
 | 
			
		||||
{
 | 
			
		||||
    if (standalone)
 | 
			
		||||
    {
 | 
			
		||||
        timer1.loop();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void timer1_callback()
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < 16; i++)
 | 
			
		||||
    {
 | 
			
		||||
        pwm_set_state(i, 1);
 | 
			
		||||
void lt_btn_cb(void *comp) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
void fan_btn_cb(void *comp) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
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) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -22,8 +22,13 @@ void user_loop();
 | 
			
		|||
void virtual_interrupt_user_callback(int pin, int state);
 | 
			
		||||
void pwm_changed_user_callback(int pin);
 | 
			
		||||
void timer_tick_callback();
 | 
			
		||||
void timer1_callback();
 | 
			
		||||
void bt0PopCallback(void *ptr);
 | 
			
		||||
void lt_btn_cb(void *comp);
 | 
			
		||||
void fan_btn_cb(void *comp);
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// ESPMega IoT Core Build-in Functions
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue