Compare commits

...

44 Commits
main ... ise

Author SHA1 Message Date
reaw55 06ee00d60e add pressed state for mvp 2024-01-19 12:06:33 +07:00
reaw55 1357f212f5 add update_lcd_ac() 2024-01-08 22:41:43 +07:00
reaw55 684652d0fc fix toggle stuck on 2024-01-08 22:29:17 +07:00
reaw55 cad22768ce fix ac_toggle -> air_toggle 2024-01-08 22:25:34 +07:00
reaw55 74cb7530fe fix toggle 2 2024-01-08 22:13:24 +07:00
reaw55 a6f1eb34e3 try to fix toggle 2024-01-08 22:07:39 +07:00
reaw55 c4fe483975 fix toggle 2024-01-08 21:53:02 +07:00
reaw55 595a13a7c1 update mode_pop_callback to not loop to 0 2024-01-08 21:38:16 +07:00
reaw55 9739ddcf16 update ac mode 2024-01-08 18:30:17 +07:00
reaw55 d5baddd873 add loading screen 2023-12-27 01:37:41 +07:00
reaw55 c34486d2ae add pic2 to all function 2023-12-27 01:16:25 +07:00
reaw55 c53c49daa1 add ';' 2023-12-27 01:02:35 +07:00
reaw55 9a11c68ffc update ac code 2023-12-27 01:01:13 +07:00
reaw55 aec65f3292 fix logic error 2023-12-27 00:53:14 +07:00
reaw55 2bb6b813cc fix typo 2023-12-27 00:50:55 +07:00
reaw55 55c6cf45cb change state to be correct 2023-12-27 00:46:19 +07:00
reaw55 4b781f0982 add ac to header 2023-12-27 00:31:52 +07:00
reaw55 c12a909f66 band aid fix on light toggle 2023-12-27 00:28:41 +07:00
reaw55 bda80d340b fix unintended error 2023-12-27 00:15:17 +07:00
reaw55 c014b72532 make light control UI change more efficient 2023-12-27 00:12:00 +07:00
Siwat Sirichai 040fcef814 Merge branch 'main' into ise 2023-12-26 23:55:11 +07:00
reaw55 b6e862d1d2 change user_acmode 2023-12-26 23:02:28 +07:00
reaw55 ca27f6de89 update user_acmode to work 2023-12-26 23:00:03 +07:00
reaw55 424312952c Merge branch 'ise' of https://git.siwatsystem.com/ise-senior-iot/iot-firmware into ise 2023-12-26 22:56:38 +07:00
Siwat Sirichai 821e200874 upload lcd 2023-12-26 22:54:59 +07:00
reaw55 fb22e48d33 update acmode to user_acmode 2023-12-26 22:53:12 +07:00
reaw55 8c01ccb18a add ac control 2023-12-26 22:37:11 +07:00
reaw55 b05c75a0a1 add light control 2023-12-25 00:41:16 +07:00
reaw55 b4b1f12ba8 initial user code 2023-12-24 23:41:27 +07:00
reaw55 4e36b9b3d1 Merge branch 'ise' of https://git.siwatsystem.com/ise-senior-iot/iot-firmware into ise 2023-12-24 23:16:35 +07:00
reaw55 ffd695b209 add MVP Display 2023-12-24 23:16:32 +07:00
Siwat Sirichai b4e15c6cae Merge branch 'main' into ise 2023-12-11 11:33:28 +07:00
Siwat Sirichai 655b1e6f58 Merge branch 'main' into ise 2023-12-08 18:33:39 +07:00
Siwat Sirichai b123f74953 Merge branch 'main' into ise 2023-12-08 17:58:17 +07:00
Siwat Sirichai 54a75ac700 Update Jenkinsfile 2023-12-07 16:44:32 +07:00
Siwat Sirichai 876fd3b84f Merge branch 'main' into ise 2023-12-07 16:44:19 +07:00
Siwat Sirichai 7117579c6b Merge branch 'main' into ise 2023-12-07 15:02:52 +07:00
Siwat Sirichai b416b68b16 Merge branch 'main' into ise 2023-12-04 23:04:00 +07:00
Siwat Sirichai 766d1b7395 Merge branch 'main' into ise 2023-12-03 16:13:09 +07:00
Siwat Sirichai 789729153e Merge branch 'main' into ise 2023-12-03 15:17:48 +07:00
Siwat Sirichai 0c0e4b6af7 Merge branch 'main' into ise 2023-11-30 20:01:43 +07:00
Siwat Sirichai c882db3327 Merge branch 'main' into ise 2023-11-30 19:51:25 +07:00
Siwat Sirichai 2501e4ab2e update slider 2023-11-25 11:55:48 +07:00
reaw55 078bb5930f init main page for Nextion 2023-11-25 00:02:54 +07:00
78 changed files with 577 additions and 34 deletions

2
Jenkinsfile vendored
View File

@ -4,7 +4,7 @@ pipeline {
stages {
stage('Build') {
steps {
git branch: 'main', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git'
git branch: 'ise', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git'
sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio'
sh '/usr/bin/python3 gen_release.py'
stash includes: 'release/**/*', name: 'release_binaries'

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
ise_display/ise_display.HMI Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,20 +1,220 @@
#include <user_code.hpp>
//Timer Components
ESPMega_Timer timer1(0, 50, timer1_callback, 15001);
uint8_t user_acmode = 1;
// Display Componets
// Link with Dual state button object with id 2 on page 1 named bt0
NexDSButton bt0 = NexDSButton(1, 2, "bt0");
NexButton light_toggle = NexButton(1, 2, "light_toggle");
NexButton row1_master = NexButton(1, 11, "row1_master");
NexButton row2_master = NexButton(1, 12, "row2_master");
NexButton row3_master = NexButton(1, 14, "row3_master");
NexButton row4_master = NexButton(1, 13, "row4_master");
NexButton row1_lv1 = NexButton(1, 3, "row1_lv1");
NexButton row1_lv2 = NexButton(1, 4, "row1_lv2");
NexButton row2_lv1 = NexButton(1, 5, "row2_lv1");
NexButton row2_lv2 = NexButton(1, 6, "row2_lv2");
NexButton row3_lv1 = NexButton(1, 10, "row3_lv1");
NexButton row3_lv2 = NexButton(1, 7, "row3_lv2");
NexButton row4_lv1 = NexButton(1, 9, "row4_lv1");
NexButton row4_lv2 = NexButton(1, 8, "row4_lv2");
NexButton temp_plus = NexButton(1, 18, "temp_plus");
NexButton temp_neg = NexButton(1, 17, "temp_neg");
NexButton fan = NexButton(1, 16, "fan");
NexButton mode = NexButton(1, 15, "mode");
NexButton air_toggle = NexButton(1, 1, "air_toggle");
NexText cur_temp = NexText(1, 19, "cur_temp");
// List of Component ID Message to listen to
NexTouch *nex_listen_list[] =
{
&bt0,
&light_toggle,
&row1_master,
&row2_master,
&row3_master,
&row4_master,
&row1_lv1,
&row1_lv2,
&row2_lv1,
&row2_lv2,
&row3_lv1,
&row3_lv2,
&row4_lv1,
&row4_lv2,
&temp_plus,
&temp_neg,
&fan,
&mode,
&air_toggle,
NULL};
void bt0PopCallback(void *ptr)
bool row_is_on(int light1_pin, int light2_pin)
{
pwm_toggle(2);
return pwm_get_state(light1_pin) && pwm_get_state(light2_pin);
}
bool row_is_on_or(int light1_pin, int light2_pin)
{
return pwm_get_state(light1_pin) || pwm_get_state(light2_pin);
}
void light_toggle_pop_callback(void *ptr)
{
bool new_state = !row_is_on(ROW1_LIGHT1, ROW1_LIGHT2) && !row_is_on(ROW2_LIGHT1, ROW2_LIGHT2) && !row_is_on(ROW3_LIGHT1, ROW3_LIGHT2) && !row_is_on(ROW4_LIGHT1, ROW4_LIGHT2);
pwm_set_state(ROW1_LIGHT1, new_state);
pwm_set_state(ROW1_LIGHT2, new_state);
pwm_set_state(ROW2_LIGHT1, new_state);
pwm_set_state(ROW2_LIGHT2, new_state);
pwm_set_state(ROW3_LIGHT1, new_state);
pwm_set_state(ROW3_LIGHT2, new_state);
pwm_set_state(ROW4_LIGHT1, new_state);
pwm_set_state(ROW4_LIGHT2, new_state);
}
void row1_lv1_pop_callback(void *ptr)
{
pwm_toggle(ROW1_LIGHT1);
}
void row1_lv2_pop_callback(void *ptr)
{
pwm_toggle(ROW1_LIGHT2);
}
void row2_lv1_pop_callback(void *ptr)
{
pwm_toggle(ROW2_LIGHT1);
}
void row2_lv2_pop_callback(void *ptr)
{
pwm_toggle(ROW2_LIGHT2);
}
void row3_lv1_pop_callback(void *ptr)
{
pwm_toggle(ROW3_LIGHT1);
}
void row3_lv2_pop_callback(void *ptr)
{
pwm_toggle(ROW3_LIGHT2);
}
void row4_lv1_pop_callback(void *ptr)
{
pwm_toggle(ROW4_LIGHT1);
}
void row4_lv2_pop_callback(void *ptr)
{
pwm_toggle(ROW4_LIGHT2);
}
void increase_temp()
{
uint8_t current_temp = ac_get_temperature();
ac_set_state(ac_get_mode(), current_temp + 1, ac_get_fan_speed());
}
void decrease_temp()
{
uint8_t current_temp = ac_get_temperature();
ac_set_state(ac_get_mode(), current_temp - 1, ac_get_fan_speed());
}
void temp_plus_pop_callback(void *ptr)
{
increase_temp();
}
void temp_neg_pop_callback(void *ptr)
{
decrease_temp();
}
void fan_pop_callback(void *ptr)
{
uint8_t current_fan_speed = ac_get_fan_speed();
uint8_t new_fan_speed = (current_fan_speed + 1) % 4; // Loop back to 0 when reaching 3
ac_set_state(ac_get_mode(), ac_get_temperature(), new_fan_speed);
}
void mode_pop_callback(void *ptr)
{
uint8_t current_mode = ac_get_mode();
//user_acmode = ac_get_mode();
// uint8_t new_mode = (current_mode + 1) % 3; // Loop back to 1 when reaching 2
if (current_mode == 1)
{
user_acmode = 2;
ac_set_state(2, ac_get_temperature(), ac_get_fan_speed());
}
else if (current_mode == 2)
{
user_acmode = 1;
ac_set_state(1, ac_get_temperature(), ac_get_fan_speed());
}
else {
if (user_acmode == 1)
{
user_acmode = 2;
}
else
{
user_acmode = 1;
}
update_lcd_ac();
}
// ac_set_state(new_mode, ac_get_temperature(), ac_get_fan_speed());
}
void air_toggle_pop_callback(void *ptr)
{
// this function should set the state of the AC to toggle between off (mode 0) and the same state as before store in variable acmode
// val user_acmode already initialized to 1 (cool mode)
if (ac_get_mode() == 0)
{
ac_set_state(user_acmode, ac_get_temperature(), ac_get_fan_speed());
}
else
{
user_acmode = ac_get_mode();
ac_set_state(0, ac_get_temperature(), ac_get_fan_speed());
}
/* if (ac_get_mode() == 0) {
//ac_set_state(user_acmode, ac_get_temperature(), ac_get_fan_speed());
} else {
user_acmode = ac_get_mode();
ac_set_state(0, ac_get_temperature(), ac_get_fan_speed());
}
*/
}
void row1_master_pop_callback(void *ptr)
{
bool new_state = !row_is_on(ROW1_LIGHT1, ROW1_LIGHT2);
pwm_set_state(ROW1_LIGHT1, new_state);
pwm_set_state(ROW1_LIGHT2, new_state);
}
void row2_master_pop_callback(void *ptr)
{
bool new_state = !row_is_on(ROW2_LIGHT1, ROW2_LIGHT2);
pwm_set_state(ROW2_LIGHT1, new_state);
pwm_set_state(ROW2_LIGHT2, new_state);
}
void row3_master_pop_callback(void *ptr)
{
bool new_state = !row_is_on(ROW3_LIGHT1, ROW3_LIGHT2);
pwm_set_state(ROW3_LIGHT1, new_state);
pwm_set_state(ROW3_LIGHT2, new_state);
}
void row4_master_pop_callback(void *ptr)
{
bool new_state = !row_is_on(ROW4_LIGHT1, ROW4_LIGHT2);
pwm_set_state(ROW4_LIGHT1, new_state);
pwm_set_state(ROW4_LIGHT2, new_state);
}
/*
@ -31,14 +231,33 @@ This code will run after every component is initialized
*/
void user_init()
{
timer1.begin();
ESPMega_EXTLCD.print("page home");
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
bt0.attachPop(bt0PopCallback, &bt0);
elcd.print("page main");
elcd_send_stop_bit();
light_toggle.attachPop(light_toggle_pop_callback, &light_toggle);
row1_lv1.attachPop(row1_lv1_pop_callback, &row1_lv1);
row1_lv2.attachPop(row1_lv2_pop_callback, &row1_lv2);
row2_lv1.attachPop(row2_lv1_pop_callback, &row2_lv1);
row2_lv2.attachPop(row2_lv2_pop_callback, &row2_lv2);
row3_lv1.attachPop(row3_lv1_pop_callback, &row3_lv1);
row3_lv2.attachPop(row3_lv2_pop_callback, &row3_lv2);
row4_lv1.attachPop(row4_lv1_pop_callback, &row4_lv1);
row4_lv2.attachPop(row4_lv2_pop_callback, &row4_lv2);
row1_master.attachPop(row1_master_pop_callback, &row1_master);
row2_master.attachPop(row2_master_pop_callback, &row2_master);
row3_master.attachPop(row3_master_pop_callback, &row3_master);
row4_master.attachPop(row4_master_pop_callback, &row4_master);
temp_plus.attachPop(temp_plus_pop_callback, &temp_plus);
temp_neg.attachPop(temp_neg_pop_callback, &temp_neg);
fan.attachPop(fan_pop_callback, &fan);
mode.attachPop(mode_pop_callback, &mode);
air_toggle.attachPop(air_toggle_pop_callback, &air_toggle);
update_lcd_row1();
update_lcd_row2();
update_lcd_row3();
update_lcd_row4();
update_toggle_button();
update_lcd_ac();
}
/*
This code will run once every event loop
*/
@ -54,12 +273,290 @@ void virtual_interrupt_user_callback(int pin, int state)
{
}
void update_lcd_row1()
{
bool master_state = row_is_on_or(ROW1_LIGHT1, ROW1_LIGHT2);
// row1_master.Set_background_image_pic(master_state?10:9);
elcd_send_stop_bit();
elcd.print("row1_master.pic=");
elcd.print(master_state ? 10 : 9);
elcd_send_stop_bit();
elcd.print("row1_master.pic2=");
elcd.print(master_state ? 46 : 45);
elcd_send_stop_bit();
bool lt1_state = pwm_get_state(ROW1_LIGHT1);
bool lt2_state = pwm_get_state(ROW1_LIGHT2);
// also update the light1 and light2 buttons background to reflect the current state
// row1_lv1.Set_background_image_pic(lt1_state?6:5);
// row1_lv2.Set_background_image_pic(lt2_state?8:7);
elcd.print("row1_lv1.pic=");
elcd.print(lt1_state ? 6 : 5); // 6 on ; 5 off
elcd_send_stop_bit();
elcd.print("row1_lv2.pic=");
elcd.print(lt2_state ? 8 : 7);
elcd_send_stop_bit();
elcd.print("row1_lv1.pic2=");
elcd.print(lt1_state ? 38 : 37);
elcd_send_stop_bit();
elcd.print("row1_lv2.pic2=");
elcd.print(lt2_state ? 40 : 39);
elcd_send_stop_bit();
}
void update_lcd_row2()
{
bool master_state = row_is_on_or(ROW2_LIGHT1, ROW2_LIGHT2);
// row2_master.Set_background_image_pic(master_state?12:11);
elcd_send_stop_bit();
elcd.print("row2_master.pic=");
elcd.print(master_state ? 12 : 11);
elcd_send_stop_bit();
elcd.print("row2_master.pic2=");
elcd.print(master_state ? 48 : 47);
elcd_send_stop_bit();
bool lt1_state = pwm_get_state(ROW2_LIGHT1);
bool lt2_state = pwm_get_state(ROW2_LIGHT2);
// also update the light1 and light2 buttons background to reflect the current state
// row2_lv1.Set_background_image_pic(lt1_state?6:5);
// row2_lv2.Set_background_image_pic(lt2_state?8:7);
elcd.print("row2_lv1.pic=");
elcd.print(lt1_state ? 6 : 5);
elcd_send_stop_bit();
elcd.print("row2_lv2.pic=");
elcd.print(lt2_state ? 8 : 7);
elcd_send_stop_bit();
elcd.print("row2_lv1.pic2=");
elcd.print(lt1_state ? 38 : 37);
elcd_send_stop_bit();
elcd.print("row2_lv2.pic2=");
elcd.print(lt2_state ? 40 : 39);
elcd_send_stop_bit();
}
void update_lcd_row3()
{
bool master_state = row_is_on_or(ROW3_LIGHT1, ROW3_LIGHT2);
// row3_master.Set_background_image_pic(master_state?14:13);
elcd_send_stop_bit();
elcd.print("row3_master.pic=");
elcd.print(master_state ? 14 : 13);
elcd_send_stop_bit();
elcd.print("row3_master.pic2=");
elcd.print(master_state ? 50 : 49);
elcd_send_stop_bit();
bool lt1_state = pwm_get_state(ROW3_LIGHT1);
bool lt2_state = pwm_get_state(ROW3_LIGHT2);
// also update the light1 and light2 buttons background to reflect the current state
// row3_lv1.Set_background_image_pic(lt1_state?6:5);
// row3_lv2.Set_background_image_pic(lt2_state?8:7);
elcd.print("row3_lv1.pic=");
elcd.print(lt1_state ? 6 : 5);
elcd_send_stop_bit();
elcd.print("row3_lv2.pic=");
elcd.print(lt2_state ? 8 : 7);
elcd_send_stop_bit();
elcd.print("row3_lv1.pic2=");
elcd.print(lt1_state ? 38 : 37);
elcd_send_stop_bit();
elcd.print("row3_lv2.pic2=");
elcd.print(lt2_state ? 40 : 39);
elcd_send_stop_bit();
}
void update_lcd_row4()
{
bool master_state = row_is_on_or(ROW4_LIGHT1, ROW4_LIGHT2);
// row4_master.Set_background_image_pic(master_state?16:15);
elcd_send_stop_bit();
elcd.print("row4_master.pic=");
elcd.print(master_state ? 16 : 15);
elcd_send_stop_bit();
elcd.print("row4_master.pic2=");
elcd.print(master_state ? 52 : 51);
elcd_send_stop_bit();
bool lt1_state = pwm_get_state(ROW4_LIGHT1);
bool lt2_state = pwm_get_state(ROW4_LIGHT2);
// also update the light1 and light2 buttons background to reflect the current state
// row4_lv1.Set_background_image_pic(lt1_state?6:5);
// row4_lv2.Set_background_image_pic(lt2_state?8:7);
elcd.print("row4_lv1.pic=");
elcd.print(lt1_state ? 6 : 5);
elcd_send_stop_bit();
elcd.print("row4_lv2.pic=");
elcd.print(lt2_state ? 8 : 7);
elcd_send_stop_bit();
elcd.print("row4_lv1.pic2=");
elcd.print(lt1_state ? 38 : 37);
elcd_send_stop_bit();
elcd.print("row4_lv2.pic2=");
elcd.print(lt2_state ? 40 : 39);
elcd_send_stop_bit();
}
void update_toggle_button()
{
// calcuate the current state of the toggle button
bool current_state = row_is_on_or(ROW1_LIGHT1, ROW1_LIGHT2) || row_is_on_or(ROW2_LIGHT1, ROW2_LIGHT2) || row_is_on_or(ROW3_LIGHT1, ROW3_LIGHT2) || row_is_on_or(ROW4_LIGHT1, ROW4_LIGHT2);
// light_toggle.Set_background_image_pic(current_state?4:3);
elcd_send_stop_bit();
elcd.print("light_toggle.pic=");
elcd.print(current_state ? 4 : 3);
elcd_send_stop_bit();
elcd.print("light_toggle.pic2=");
elcd.print(current_state ? 44 : 43);
elcd_send_stop_bit();
}
void update_lcd_ac()
{
// update the current temperature
char temp_str[3];
sprintf(temp_str, "%d", ac_get_temperature());
cur_temp.setText(temp_str);
// update the fan speed auto is 18, high 19, medium 21, low 20
// Fan Speed 0: Auto, 1: High, 2: Mid, 3: Low
uint8_t fan_speed = ac_get_fan_speed();
if (fan_speed == 0)
{
// fan.Set_background_image_pic(18);
elcd_send_stop_bit();
elcd.print("fan.pic=18");
elcd_send_stop_bit();
elcd.print("fan.pic2=30");
elcd_send_stop_bit();
}
else if (fan_speed == 1)
{
// fan.Set_background_image_pic(19);
elcd_send_stop_bit();
elcd.print("fan.pic=19");
elcd_send_stop_bit();
elcd.print("fan.pic2=31");
elcd_send_stop_bit();
}
else if (fan_speed == 2)
{
// fan.Set_background_image_pic(21);
elcd_send_stop_bit();
elcd.print("fan.pic=21");
elcd_send_stop_bit();
elcd.print("fan.pic2=33");
elcd_send_stop_bit();
}
else if (fan_speed == 3)
{
// fan.Set_background_image_pic(20);
elcd_send_stop_bit();
elcd.print("fan.pic=20");
elcd_send_stop_bit();
elcd.print("fan.pic2=32");
elcd_send_stop_bit();
}
else
{
// fan.Set_background_image_pic(18);
elcd_send_stop_bit();
elcd.print("fan.pic=18");
elcd_send_stop_bit();
elcd.print("fan.pic2=30");
elcd_send_stop_bit();
}
// update the mode cool is 22, fan mode is 24, for off the toggle button act as indicator
// Mode 0: Off, 1: Cool, 2: Fan
//uint8_t mode_state = user_acmode;
// mode.Set_background_image_pic(mode_state==1?22:24);
elcd_send_stop_bit();
if (ac_get_mode() == 1)
{
elcd_send_stop_bit();
elcd.print("air_toggle.pic=2");
elcd_send_stop_bit();
elcd.print("air_toggle.pic2=42");
elcd_send_stop_bit();
elcd.print("mode.pic=22");
elcd_send_stop_bit();
elcd.print("mode.pic2=34");
elcd_send_stop_bit();
}
else if (ac_get_mode() == 2)
{
elcd_send_stop_bit();
elcd.print("air_toggle.pic=2");
elcd_send_stop_bit();
elcd.print("air_toggle.pic2=42");
elcd_send_stop_bit();
elcd.print("mode.pic=24");
elcd_send_stop_bit();
elcd.print("mode.pic2=36");
elcd_send_stop_bit();
}
else if (ac_get_mode() == 0)
{
elcd_send_stop_bit();
elcd.print("air_toggle.pic=1");
elcd_send_stop_bit();
elcd.print("air_toggle.pic2=41");
if (user_acmode == 1)
{
elcd_send_stop_bit();
elcd.print("mode.pic=22");
elcd_send_stop_bit();
elcd.print("mode.pic2=34");
elcd_send_stop_bit();
}
else
{
elcd_send_stop_bit();
elcd.print("mode.pic=24");
elcd_send_stop_bit();
elcd.print("mode.pic2=36");
elcd_send_stop_bit();
}
}
/* elcd.print("mode.pic=");
elcd.print(mode_state==1?22:24);
elcd_send_stop_bit();
elcd.print("mode.pic2=");
elcd.print(mode_state==1?22:24);
elcd_send_stop_bit();
//update the ac toggle button
//air_toggle.Set_background_image_pic(ac_get_mode()==0?1:2);
elcd_send_stop_bit();
elcd.print("air_toggle.pic=");
elcd.print(ac_get_mode()==0?2:1);
elcd_send_stop_bit();
elcd.print("air_toggle.pic2=");
elcd.print(ac_get_mode()==0?2:1);
elcd_send_stop_bit(); */
}
void pwm_changed_user_callback(int pin)
{
if (pin == 2)
switch (pin)
{
// inform the lcd when pwm 2 changed
bt0.setValue(pwm_get_state(2));
case ROW1_LIGHT1:
case ROW1_LIGHT2:
update_lcd_row1();
update_toggle_button();
break;
case ROW2_LIGHT1:
case ROW2_LIGHT2:
update_lcd_row2();
update_toggle_button();
break;
case ROW3_LIGHT1:
case ROW3_LIGHT2:
update_lcd_row3();
update_toggle_button();
break;
case ROW4_LIGHT1:
case ROW4_LIGHT2:
update_lcd_row4();
update_toggle_button();
break;
default:
break;
}
}
@ -70,30 +567,29 @@ void timer_tick_callback()
{
if (standalone)
{
timer1.loop();
}
}
void timer1_callback()
void ac_changed_user_callback(int mode, int temperature, int fan_speed)
{
for (int i = 0; i < 16; i++)
update_lcd_ac();
}
void mqtt_connected_user_callback()
{
pwm_set_state(i, 1);
}
}
void ac_changed_user_callback(int mode, int temperature, int fan_speed) {
void user_state_request_callback()
{
}
void mqtt_connected_user_callback() {
void user_mqtt_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
{
}
void user_state_request_callback() {
}
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);
}

View File

@ -6,6 +6,22 @@
#include "espmega_iot_timer.hpp"
#include "espmega_iot_external_lcd.hpp"
// I/O Assignment
// Available Inputs 0-15
// Available Outputs 0-3, 7-11
// There are 4 rows of lights
// Each row has 2 lights
// Each light has 2 states
#define ROW1_LIGHT1 0
#define ROW1_LIGHT2 1
#define ROW2_LIGHT1 2
#define ROW2_LIGHT2 3
#define ROW3_LIGHT1 7
#define ROW3_LIGHT2 8
#define ROW4_LIGHT1 9
#define ROW4_LIGHT2 10
#define COMPUTER_DESK_CONTACTOR 12
// Bus Overclocking Configuration
// Do not enable if you are using external I/O cards as it will cause signal integrity issues.
// Choose only one mode
@ -44,9 +60,40 @@
// Analog Module Configuration
#define ANALOG_REPORTING_INTERVAL 500
// User Defined Variables
// User Defined Functions
void timer1_callback();
void bt0PopCallback(void *ptr);
#define elcd ESPMega_EXTLCD
void elcd_send_stop_bit();
bool row_is_on(int light1_pin, int light2_pin);
bool row_is_on_or(int light1_pin, int light2_pin);
void update_lcd_row1();
void update_lcd_row2();
void update_lcd_row3();
void update_lcd_row4();
void update_lcd_ac();
void update_toggle_button();
void light_toggle_pop_callback(void *ptr);
void row1_lv1_pop_callback(void *ptr);
void row1_lv2_pop_callback(void *ptr);
void row2_lv1_pop_callback(void *ptr);
void row2_lv2_pop_callback(void *ptr);
void row3_lv1_pop_callback(void *ptr);
void row3_lv2_pop_callback(void *ptr);
void row4_lv1_pop_callback(void *ptr);
void row4_lv2_pop_callback(void *ptr);
void row1_master_pop_callback(void *ptr);
void row2_master_pop_callback(void *ptr);
void row3_master_pop_callback(void *ptr);
void row4_master_pop_callback(void *ptr);
void increase_temp();
void decrease_temp();
void temp_plus_pop_callback(void *ptr);
void temp_neg_pop_callback(void *ptr);
void fan_pop_callback(void *ptr);
void mode_pop_callback(void *ptr);
void ac_toggle_pop_callback(void *ptr);
// User Defined IoT Core Callback Functions (Required)
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);