json_object *temperature;
int temp_start;
int temp_end;
+ int threshold;
int timer_interval_ms;
/* Get property values */
if (temperature) {
temp_start = get_int_from_object(temperature, "start");
temp_end = get_int_from_object(temperature, "end");
+ threshold = get_int_from_object(temperature, "threshold");
+ /* if threshold is not presented, using temp_end as default */
+ if (threshold < 0)
+ threshold = temp_end;
} else {
- temp_start = temp_end = 0;
+ temp_start = temp_end = threshold = 0;
}
timer_interval_ms = get_int_from_object(obj, "timer_interval_ms");
} else if (target_level < 0) {
_E("Failed to get 'target_level' property in scenario section\n");
return -EINVAL;
- } else if (temp_start < 0 || temp_end < 0 || temp_end < temp_start) {
- _E("Invalid values for temperature property\n");
- return -EINVAL;
+ } else if (temperature) {
+ if (temp_start < 0 || temp_end < 0 || temp_end < temp_start) {
+ _E("Invalid temperature range in scenario section\n");
+ return -EINVAL;
+ } else if (threshold < temp_start || threshold > temp_end) {
+ _W("Invalid thermal 'threshold', using default as range 'end'\n");
+ threshold = temp_end;
+ }
}
/* Initialize config_data from property values of confiugartion file */
/* - property for only thermal module */
scenario->thermal.temp_start = temp_start;
scenario->thermal.temp_end = temp_end;
+ scenario->thermal.threshold = threshold;
scenario->thermal.timer_interval = timer_interval_ms;
return 0;
for (i = 0; i < thermal->num_scenarios; i++) {
int temp_start = thermal->scenarios[i].thermal.temp_start;
int temp_end = thermal->scenarios[i].thermal.temp_end;
+ int threshold = thermal->scenarios[i].thermal.threshold;
if (thermal->scenarios[i].state != PASS_ON)
continue;
- if (temp_start < new_temp && new_temp <= temp_end) {
- new_scenario_idx = i;
- break;
+ /* check if scenario level can be lower */
+ if (i < thermal->curr_scenario_idx) {
+ if (temp_start < new_temp && new_temp <= threshold) {
+ new_scenario_idx = i;
+ break;
+ }
+ } else {
+ if (temp_start < new_temp && new_temp <= temp_end) {
+ new_scenario_idx = i;
+ break;
+ }
}
}
struct {
/**
* Range of temperature to determine scenario level represented
- * as (temp_start, temp_end].
+ * as (temp_start, temp_end]. For scenario level reduction,
+ * temperature should be in range of (temp_start, threshold] to
+ * prevent scenario is repeatedly changed at edge of original
+ * range.
*/
int temp_start;
int temp_end;
+ int threshold;
/** Interval of timer-based monitor (unit: millisecond) */
int timer_interval;
} thermal;