initial user code
This commit is contained in:
		
							parent
							
								
									4e36b9b3d1
								
							
						
					
					
						commit
						b4b1f12ba8
					
				
					 2 changed files with 50 additions and 29 deletions
				
			
		| 
						 | 
					@ -1,20 +1,24 @@
 | 
				
			||||||
#include <user_code.hpp>
 | 
					#include <user_code.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Timer Components
 | 
					 | 
				
			||||||
ESPMega_Timer timer1(0, 50, timer1_callback, 15001);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Display Componets
 | 
					// Display Componets
 | 
				
			||||||
// Link with Dual state button object with id 2 on page 1 named bt0
 | 
					// Link with Dual state button object with id 2 on page 1 named bt0
 | 
				
			||||||
NexDSButton bt0 = NexDSButton(1, 2, "bt0");
 | 
					NexButton row1_master = NexButton(1,11,"row1_master");
 | 
				
			||||||
// List of Component ID Message to listen to
 | 
					// List of Component ID Message to listen to
 | 
				
			||||||
NexTouch *nex_listen_list[] =
 | 
					NexTouch *nex_listen_list[] =
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        &bt0,
 | 
					        &row1_master,
 | 
				
			||||||
        NULL};
 | 
					        NULL};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bt0PopCallback(void *ptr)
 | 
					bool row1_is_on() {
 | 
				
			||||||
 | 
					    return pwm_get_state(LIGHT_THAW_NAH_THANG_KWAR) && pwm_get_state(LIGHT_THAW_NAH_THANG_SAI);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void row1_master_pop_callback(void *ptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    pwm_toggle(2);
 | 
					    bool new_state = !row1_is_on();
 | 
				
			||||||
 | 
					    pwm_set_state(LIGHT_THAW_NAH_THANG_KWAR, new_state);
 | 
				
			||||||
 | 
					    pwm_set_state(LIGHT_THAW_NAH_THANG_SAI, new_state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -31,12 +35,9 @@ This code will run after every component is initialized
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
void user_init()
 | 
					void user_init()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    timer1.begin();
 | 
					    elcd.print("page main");
 | 
				
			||||||
    ESPMega_EXTLCD.print("page home");
 | 
					    elcd_send_stop_bit();
 | 
				
			||||||
    ESPMega_EXTLCD.write(0xFF);
 | 
					    row1_master.attachPop(row1_master_pop_callback, &row1_master);
 | 
				
			||||||
    ESPMega_EXTLCD.write(0xFF);
 | 
					 | 
				
			||||||
    ESPMega_EXTLCD.write(0xFF);
 | 
					 | 
				
			||||||
    bt0.attachPop(bt0PopCallback, &bt0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -54,13 +55,27 @@ void virtual_interrupt_user_callback(int pin, int state)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void update_lcd_row1() {
 | 
				
			||||||
 | 
					    bool master_state = row1_is_on();
 | 
				
			||||||
 | 
					    //Assume 20 off, 21 on
 | 
				
			||||||
 | 
					    row1_master.Set_background_image_pic(master_state?21:20);
 | 
				
			||||||
 | 
					    bool lt1_state = pwm_get_state(LIGHT_THAW_NAH_THANG_KWAR);
 | 
				
			||||||
 | 
					    bool lt2_state = pwm_get_state(LIGHT_THAW_NAH_THANG_SAI);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pwm_changed_user_callback(int pin)
 | 
					void pwm_changed_user_callback(int pin)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (pin == 2)
 | 
					    // switch (pin)
 | 
				
			||||||
    {
 | 
					    // {
 | 
				
			||||||
        // inform the lcd when pwm 2 changed
 | 
					    // case LIGHT_THAW_NAH_THANG_KWAR:
 | 
				
			||||||
        bt0.setValue(pwm_get_state(2));
 | 
					    // case LIGHT_THAW_NAH_THANG_SAI:
 | 
				
			||||||
    }
 | 
					    // update_lcd_row1();
 | 
				
			||||||
 | 
					    // break;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    // default:
 | 
				
			||||||
 | 
					    //     break;
 | 
				
			||||||
 | 
					    // }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -70,15 +85,6 @@ void timer_tick_callback()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (standalone)
 | 
					    if (standalone)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        timer1.loop();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void timer1_callback()
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    for (int i = 0; i < 16; i++)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        pwm_set_state(i, 1);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,3 +103,9 @@ void user_state_request_callback() {
 | 
				
			||||||
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) {
 | 
					void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void elcd_send_stop_bit() {
 | 
				
			||||||
 | 
					    elcd.write(0xFF);
 | 
				
			||||||
 | 
					    elcd.write(0xFF);
 | 
				
			||||||
 | 
					    elcd.write(0xFF);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,12 @@
 | 
				
			||||||
#include "espmega_iot_timer.hpp"
 | 
					#include "espmega_iot_timer.hpp"
 | 
				
			||||||
#include "espmega_iot_external_lcd.hpp"
 | 
					#include "espmega_iot_external_lcd.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// I/O Assignment
 | 
				
			||||||
 | 
					#define LIGHT_THAW_NAH_THANG_KWAR 0
 | 
				
			||||||
 | 
					#define LIGHT_THAW_NAH_THANG_SAI 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Bus Overclocking Configuration
 | 
					// Bus Overclocking Configuration
 | 
				
			||||||
// Do not enable if you are using external I/O cards as it will cause signal integrity issues.
 | 
					// Do not enable if you are using external I/O cards as it will cause signal integrity issues.
 | 
				
			||||||
// Choose only one mode
 | 
					// Choose only one mode
 | 
				
			||||||
| 
						 | 
					@ -45,8 +51,11 @@
 | 
				
			||||||
#define ANALOG_REPORTING_INTERVAL 500
 | 
					#define ANALOG_REPORTING_INTERVAL 500
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// User Defined Functions
 | 
					// User Defined Functions
 | 
				
			||||||
void timer1_callback();
 | 
					#define elcd ESPMega_EXTLCD
 | 
				
			||||||
void bt0PopCallback(void *ptr);
 | 
					void elcd_send_stop_bit();
 | 
				
			||||||
 | 
					bool row1_is_on();
 | 
				
			||||||
 | 
					void update_lcd_row1();
 | 
				
			||||||
 | 
					void row1_master_pop_callback(void *ptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// User Defined IoT Core Callback Functions (Required)
 | 
					// User Defined IoT Core Callback Functions (Required)
 | 
				
			||||||
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
 | 
					void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue