From 2af32ff45ee0d08fae816b82e7f0ac3b1bdc7f8e Mon Sep 17 00:00:00 2001 From: Michael P Date: Wed, 4 Nov 2020 16:42:03 +0100 Subject: [PATCH 01/10] Update app.c --- ATC_Thermometer/app.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 8a1de316..65612722 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -18,8 +18,8 @@ RAM bool show_batt_or_humi; RAM bool temp_C_or_F; RAM bool blinking_smiley = false; RAM bool comfort_smiley = true; -RAM bool show_batt_enabled = true; -RAM bool advertising_type = false;//Custom or Mi Advertising +RAM bool show_batt_enabled = false; +RAM bool advertising_type = false;//Custom or Mi Advertising (true) RAM uint8_t advertising_interval = 6;//multiply by 10 for value RAM int8_t temp_offset; RAM int8_t humi_offset; @@ -85,7 +85,14 @@ void main_loop(){ } - if(!show_batt_enabled)show_batt_or_humi = true; + if(!show_batt_enabled){ + show_batt_or_humi = true; + if(battery_level <= 15) { + show_battery_symbol(1); + }else{ + show_battery_symbol(0); + } + } if(show_batt_or_humi){//Change between Humidity displaying and battery level show_small_number(humi,1); show_battery_symbol(0); From 8eba58e2ec15716dd8cd8ba1914f79f502c5efde Mon Sep 17 00:00:00 2001 From: Michael P Date: Wed, 4 Nov 2020 16:43:54 +0100 Subject: [PATCH 02/10] Update battery.c --- ATC_Thermometer/battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ATC_Thermometer/battery.c b/ATC_Thermometer/battery.c index f99a6750..261c6f1a 100644 --- a/ATC_Thermometer/battery.c +++ b/ATC_Thermometer/battery.c @@ -77,6 +77,6 @@ return batt_vol_mv; uint8_t get_battery_level(uint16_t battery_mv){ uint8_t battery_level = (battery_mv-2200)/(31-22); if(battery_level>100)battery_level=100; - if(battery_level<0)battery_level=0; + if(battery_mv<2200)battery_level=0; return battery_level; } \ No newline at end of file From 527c81c9406816483d3aece7fce66924130ef9f4 Mon Sep 17 00:00:00 2001 From: Michael P Date: Thu, 5 Nov 2020 18:19:47 +0100 Subject: [PATCH 03/10] Update app.c used old copy of source code :( --- ATC_Thermometer/app.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 65612722..72eb6ae3 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -85,21 +85,20 @@ void main_loop(){ } - if(!show_batt_enabled){ - show_batt_or_humi = true; + if(!show_batt_enabled) show_batt_or_humi = true; + + if(show_batt_or_humi){//Change between Humidity displaying and battery level if show_batt_enabled=true + show_small_number(humi,1); if(battery_level <= 15) { show_battery_symbol(1); }else{ - show_battery_symbol(0); + show_battery_symbol(0); } - } - if(show_batt_or_humi){//Change between Humidity displaying and battery level - show_small_number(humi,1); - show_battery_symbol(0); }else{ show_small_number((battery_level==100)?99:battery_level,1); show_battery_symbol(1); } + show_batt_or_humi = !show_batt_or_humi; if(ble_get_connected()){//If connected notify Sensor data From 4ae51daa0794f3758d3e832aff7505f3d15b9eca Mon Sep 17 00:00:00 2001 From: Michael P Date: Thu, 5 Nov 2020 18:23:40 +0100 Subject: [PATCH 04/10] Update app.c --- ATC_Thermometer/app.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 72eb6ae3..10a87fb4 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -8,6 +8,7 @@ RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_ RAM bool last_smiley; int16_t temp = 0; uint16_t humi = 0; +AM uint8_t adv_count = 0; RAM int16_t last_temp; RAM uint16_t last_humi; RAM uint8_t battery_level; @@ -107,9 +108,13 @@ void main_loop(){ ble_send_battery(battery_level); } - if((clock_time()-last_adv_delay) > advertising_interval*(advertising_type?5000:10000)*CLOCK_SYS_CLOCK_1MS){//Advetise data delay + if((clock_time() - last_adv_delay) > (advertising_type?5000:10000)*CLOCK_SYS_CLOCK_1MS){//Advetise data delay + if(adv_count >= advertising_interval){ set_adv_data(temp, humi, battery_level, battery_mv); last_adv_delay = clock_time(); + adv_count=0; + } + adv_count++; }else if((temp-last_temp > temp_alarm_point)||(last_temp-temp > temp_alarm_point)||(humi-last_humi > humi_alarm_point)||(last_humi-humi > humi_alarm_point)){// instant advertise on to much sensor difference set_adv_data(temp, humi, battery_level, battery_mv); } From ec113476886f147cbb1ef6ee68aa5191e852bb6b Mon Sep 17 00:00:00 2001 From: Michael P Date: Thu, 5 Nov 2020 18:26:00 +0100 Subject: [PATCH 05/10] Update app.c fix for overflow for advertising interval using counter --- ATC_Thermometer/app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 10a87fb4..03173710 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -8,7 +8,7 @@ RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_ RAM bool last_smiley; int16_t temp = 0; uint16_t humi = 0; -AM uint8_t adv_count = 0; +RAM uint8_t adv_count = 0; RAM int16_t last_temp; RAM uint16_t last_humi; RAM uint8_t battery_level; From 973932eadb1ad121ea2ccf5abbe8c02bf86d68d5 Mon Sep 17 00:00:00 2001 From: Michael P Date: Thu, 5 Nov 2020 19:37:59 +0100 Subject: [PATCH 06/10] Update app.c --- ATC_Thermometer/app.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 03173710..c340ce6e 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -4,8 +4,9 @@ #include "stack/ble/ble.h" #include "vendor/common/blt_common.h" -RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_delay = 0xFFFF0000; +RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_delay = 0xFFFF0000, last_battsym_delay = 0xFFFF0000; RAM bool last_smiley; +RAM bool last_batt; int16_t temp = 0; uint16_t humi = 0; RAM uint8_t adv_count = 0; @@ -21,11 +22,11 @@ RAM bool blinking_smiley = false; RAM bool comfort_smiley = true; RAM bool show_batt_enabled = false; RAM bool advertising_type = false;//Custom or Mi Advertising (true) -RAM uint8_t advertising_interval = 6;//multiply by 10 for value +RAM uint8_t advertising_interval = 20;//multiply by 10 for value RAM int8_t temp_offset; RAM int8_t humi_offset; -RAM uint8_t temp_alarm_point = 5;//divide by ten for value -RAM uint8_t humi_alarm_point = 5; +RAM uint8_t temp_alarm_point = 50;//divide by ten for value +RAM uint8_t humi_alarm_point = 50; RAM int16_t comfort_x[] = {2000, 2560, 2700, 2500, 2050, 1700, 1600, 1750}; RAM uint16_t comfort_y[] = {2000, 1980, 3200, 6000, 8200, 8600, 7700, 3800}; @@ -65,7 +66,15 @@ _attribute_ram_code_ void user_init_deepRetn(void){//after sleep this will get e } void main_loop(){ - if((clock_time()-last_delay) > 5000*CLOCK_SYS_CLOCK_1MS){//main loop delay +/* if((clock_time()-last_battsym_delay) > 400*CLOCK_SYS_CLOCK_1MS){ //batt blinking delay + if((battery_level < 25) && (battery_level > 15) && (!show_batt_enabled)) { + last_batt=!last_batt; + show_battery_symbol(last_batt); + update_lcd(); + last_battsym_delay = clock_time(); + } + } +*/ if((clock_time()-last_delay) > 5000*CLOCK_SYS_CLOCK_1MS){//main loop delay if((clock_time()-last_battery_delay) > 5*60000*CLOCK_SYS_CLOCK_1MS){//Read battery delay battery_mv = get_battery_mv(); @@ -84,10 +93,15 @@ void main_loop(){ show_temp_symbol(1); show_big_number(temp,1); } + + if(!show_batt_enabled) show_batt_or_humi = true; +<<<<<<< Updated upstream if(!show_batt_enabled) show_batt_or_humi = true; +======= +>>>>>>> Stashed changes if(show_batt_or_humi){//Change between Humidity displaying and battery level if show_batt_enabled=true show_small_number(humi,1); if(battery_level <= 15) { @@ -99,7 +113,11 @@ void main_loop(){ show_small_number((battery_level==100)?99:battery_level,1); show_battery_symbol(1); } +<<<<<<< Updated upstream +======= + +>>>>>>> Stashed changes show_batt_or_humi = !show_batt_or_humi; if(ble_get_connected()){//If connected notify Sensor data From a8f5a5efaca16bb618face88dc344ff235330e8c Mon Sep 17 00:00:00 2001 From: Michael P Date: Thu, 5 Nov 2020 19:39:29 +0100 Subject: [PATCH 07/10] Update app.c --- ATC_Thermometer/app.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index c340ce6e..6cc27202 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -96,12 +96,6 @@ void main_loop(){ if(!show_batt_enabled) show_batt_or_humi = true; -<<<<<<< Updated upstream - - if(!show_batt_enabled) show_batt_or_humi = true; - -======= ->>>>>>> Stashed changes if(show_batt_or_humi){//Change between Humidity displaying and battery level if show_batt_enabled=true show_small_number(humi,1); if(battery_level <= 15) { @@ -113,11 +107,7 @@ void main_loop(){ show_small_number((battery_level==100)?99:battery_level,1); show_battery_symbol(1); } -<<<<<<< Updated upstream -======= - ->>>>>>> Stashed changes show_batt_or_humi = !show_batt_or_humi; if(ble_get_connected()){//If connected notify Sensor data From 5961ea3947b39ddaacbb8bc80529e8e62bb7ff2f Mon Sep 17 00:00:00 2001 From: Michael P Date: Tue, 10 Nov 2020 16:54:00 +0100 Subject: [PATCH 08/10] Update app.c --- ATC_Thermometer/app.c | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 6cc27202..eaa66525 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -10,6 +10,7 @@ RAM bool last_batt; int16_t temp = 0; uint16_t humi = 0; RAM uint8_t adv_count = 0; +RAM uint8_t meas_count = 254; RAM int16_t last_temp; RAM uint16_t last_humi; RAM uint8_t battery_level; @@ -22,11 +23,12 @@ RAM bool blinking_smiley = false; RAM bool comfort_smiley = true; RAM bool show_batt_enabled = false; RAM bool advertising_type = false;//Custom or Mi Advertising (true) -RAM uint8_t advertising_interval = 20;//multiply by 10 for value +RAM uint8_t advertising_interval = 6;//advise new values - multiply by 10 for value +RAM uint8_t measure_interval = 25;//time = sensor advertising interval * factor (def: 2s * X) RAM int8_t temp_offset; RAM int8_t humi_offset; -RAM uint8_t temp_alarm_point = 50;//divide by ten for value -RAM uint8_t humi_alarm_point = 50; +RAM uint8_t temp_alarm_point = 5;//divide by ten for value +RAM uint8_t humi_alarm_point = 5; RAM int16_t comfort_x[] = {2000, 2560, 2700, 2500, 2050, 1700, 1600, 1750}; RAM uint16_t comfort_y[] = {2000, 1980, 3200, 6000, 8200, 8600, 7700, 3800}; @@ -81,23 +83,33 @@ void main_loop(){ battery_level = get_battery_level(get_battery_mv()); last_battery_delay = clock_time(); } - read_sensor(&temp,&humi,true); + + if(meas_count >= measure_interval){ + read_sensor(&temp,&humi,true); + temp += temp_offset; + humi += humi_offset; + meas_count=0; - temp += temp_offset; - humi += humi_offset; + if((temp-last_temp > temp_alarm_point)||(last_temp-temp > temp_alarm_point)||(humi-last_humi > humi_alarm_point)||(last_humi-humi > humi_alarm_point)){// instant advertise on to much sensor difference + set_adv_data(temp, humi, battery_level, battery_mv); + } + last_temp = temp; + last_humi = humi; + } + meas_count++; if(temp_C_or_F){ show_temp_symbol(2); - show_big_number(((((temp*10)/5)*9)+3200)/10,1);//convert C to F + show_big_number(((((last_temp*10)/5)*9)+3200)/10,1);//convert C to F }else{ show_temp_symbol(1); - show_big_number(temp,1); + show_big_number(last_temp,1); } if(!show_batt_enabled) show_batt_or_humi = true; if(show_batt_or_humi){//Change between Humidity displaying and battery level if show_batt_enabled=true - show_small_number(humi,1); + show_small_number(last_humi,1); if(battery_level <= 15) { show_battery_symbol(1); }else{ @@ -107,30 +119,26 @@ void main_loop(){ show_small_number((battery_level==100)?99:battery_level,1); show_battery_symbol(1); } - + show_batt_or_humi = !show_batt_or_humi; if(ble_get_connected()){//If connected notify Sensor data - ble_send_temp(temp); - ble_send_humi(humi); + ble_send_temp(last_temp); + ble_send_humi(last_humi); ble_send_battery(battery_level); } - + if((clock_time() - last_adv_delay) > (advertising_type?5000:10000)*CLOCK_SYS_CLOCK_1MS){//Advetise data delay if(adv_count >= advertising_interval){ - set_adv_data(temp, humi, battery_level, battery_mv); + set_adv_data(last_temp, last_humi, battery_level, battery_mv); last_adv_delay = clock_time(); adv_count=0; } adv_count++; - }else if((temp-last_temp > temp_alarm_point)||(last_temp-temp > temp_alarm_point)||(humi-last_humi > humi_alarm_point)||(last_humi-humi > humi_alarm_point)){// instant advertise on to much sensor difference - set_adv_data(temp, humi, battery_level, battery_mv); } - last_temp = temp; - last_humi = humi; if(comfort_smiley) { - if(is_comfort(temp * 10, humi * 100)){ + if(is_comfort(last_temp * 10, last_humi * 100)){ show_smiley(1); } else { show_smiley(2); From 24cb95dfff083a58ca021994b1c2da749b92432f Mon Sep 17 00:00:00 2001 From: Michael P Date: Tue, 10 Nov 2020 17:03:07 +0100 Subject: [PATCH 09/10] Update app.c --- ATC_Thermometer/app.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index eaa66525..20d99496 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -4,9 +4,8 @@ #include "stack/ble/ble.h" #include "vendor/common/blt_common.h" -RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_delay = 0xFFFF0000, last_battsym_delay = 0xFFFF0000; +RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_delay = 0xFFFF0000; RAM bool last_smiley; -RAM bool last_batt; int16_t temp = 0; uint16_t humi = 0; RAM uint8_t adv_count = 0; @@ -21,7 +20,7 @@ RAM bool show_batt_or_humi; RAM bool temp_C_or_F; RAM bool blinking_smiley = false; RAM bool comfort_smiley = true; -RAM bool show_batt_enabled = false; +RAM bool show_batt_enabled = true; RAM bool advertising_type = false;//Custom or Mi Advertising (true) RAM uint8_t advertising_interval = 6;//advise new values - multiply by 10 for value RAM uint8_t measure_interval = 25;//time = sensor advertising interval * factor (def: 2s * X) @@ -68,15 +67,7 @@ _attribute_ram_code_ void user_init_deepRetn(void){//after sleep this will get e } void main_loop(){ -/* if((clock_time()-last_battsym_delay) > 400*CLOCK_SYS_CLOCK_1MS){ //batt blinking delay - if((battery_level < 25) && (battery_level > 15) && (!show_batt_enabled)) { - last_batt=!last_batt; - show_battery_symbol(last_batt); - update_lcd(); - last_battsym_delay = clock_time(); - } - } -*/ if((clock_time()-last_delay) > 5000*CLOCK_SYS_CLOCK_1MS){//main loop delay + if((clock_time()-last_delay) > 5000*CLOCK_SYS_CLOCK_1MS){//main loop delay if((clock_time()-last_battery_delay) > 5*60000*CLOCK_SYS_CLOCK_1MS){//Read battery delay battery_mv = get_battery_mv(); @@ -110,11 +101,7 @@ void main_loop(){ if(show_batt_or_humi){//Change between Humidity displaying and battery level if show_batt_enabled=true show_small_number(last_humi,1); - if(battery_level <= 15) { - show_battery_symbol(1); - }else{ - show_battery_symbol(0); - } + show_battery_symbol(0); }else{ show_small_number((battery_level==100)?99:battery_level,1); show_battery_symbol(1); From cae91b00a99cb8799ae3e64b07455388803da0bf Mon Sep 17 00:00:00 2001 From: Michael P Date: Tue, 10 Nov 2020 17:23:46 +0100 Subject: [PATCH 10/10] Update app.c sorry, corrected description and default value measure_interval = 10;//time = loop interval * factor (def: about 7 * X) --- ATC_Thermometer/app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ATC_Thermometer/app.c b/ATC_Thermometer/app.c index 20d99496..cb7ed276 100644 --- a/ATC_Thermometer/app.c +++ b/ATC_Thermometer/app.c @@ -23,7 +23,7 @@ RAM bool comfort_smiley = true; RAM bool show_batt_enabled = true; RAM bool advertising_type = false;//Custom or Mi Advertising (true) RAM uint8_t advertising_interval = 6;//advise new values - multiply by 10 for value -RAM uint8_t measure_interval = 25;//time = sensor advertising interval * factor (def: 2s * X) +RAM uint8_t measure_interval = 10;//time = loop interval * factor (def: about 7 * X) RAM int8_t temp_offset; RAM int8_t humi_offset; RAM uint8_t temp_alarm_point = 5;//divide by ten for value