Skip to content

Commit

Permalink
Merge pull request pvvx#73 from michapr/measure_delay
Browse files Browse the repository at this point in the history
Measure delay
  • Loading branch information
atc1441 authored Nov 10, 2020
2 parents ae97fd9 + cae91b0 commit e99f719
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
58 changes: 36 additions & 22 deletions ATC_Thermometer/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RAM uint32_t last_delay = 0xFFFF0000, last_adv_delay = 0xFFFF0000, last_battery_
RAM bool last_smiley;
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;
Expand All @@ -19,8 +21,9 @@ 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 uint8_t advertising_interval = 6;//multiply by 10 for value
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 = 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
Expand Down Expand Up @@ -71,47 +74,58 @@ 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_enabled)show_batt_or_humi = true;
if(show_batt_or_humi){//Change between Humidity displaying and battery level
show_small_number(humi,1);
show_battery_symbol(0);
if(show_batt_or_humi){//Change between Humidity displaying and battery level if show_batt_enabled=true
show_small_number(last_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
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_interval*(advertising_type?5000:10000)*CLOCK_SYS_CLOCK_1MS){//Advetise data delay
set_adv_data(temp, humi, battery_level, battery_mv);

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(last_temp, last_humi, battery_level, battery_mv);
last_adv_delay = clock_time();
}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);
adv_count=0;
}
adv_count++;
}
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);
Expand Down
2 changes: 1 addition & 1 deletion ATC_Thermometer/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e99f719

Please sign in to comment.