|
|
@ -35,128 +35,164 @@ zkey_module_t key_module = ZMODULE_INIT(s_keys, onkey); |
|
|
|
* =======================================================方法======================================================== * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
/*********************************************************************************************************************** |
|
|
|
* ===================================================COUNT_COMPUTE=================================================== * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
static uint32_t compute_countdown_num(int countdowns) { |
|
|
|
if (countdowns) return countdowns / kconst_countdown_step_s + !!(countdowns % kconst_countdown_step_s); |
|
|
|
} |
|
|
|
|
|
|
|
static void increase_and_assign_countdonwnum() { |
|
|
|
if (thisDevice.countdonwnum == 4) { |
|
|
|
thisDevice.countdonwnum = 0; |
|
|
|
thisDevice.countdonwnum_s = 0; |
|
|
|
thisDevice.countdonw_setting_num = 0; |
|
|
|
} else { |
|
|
|
thisDevice.countdonwnum_s = (thisDevice.countdonwnum + 1) * kconst_countdown_step_s; |
|
|
|
thisDevice.countdonwnum = thisDevice.countdonwnum + 1; |
|
|
|
thisDevice.countdonw_setting_num = thisDevice.countdonwnum; |
|
|
|
thisDevice.countdonw_start_ticket = systicket_get_now_ms(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void mf_set_countdown(int countdownnum) { |
|
|
|
thisDevice.countdonwnum = countdownnum; |
|
|
|
thisDevice.countdonwnum_s = thisDevice.countdonwnum * kconst_countdown_step_s; |
|
|
|
thisDevice.countdonw_setting_num = thisDevice.countdonwnum; |
|
|
|
thisDevice.countdonw_start_ticket = systicket_get_now_ms(); |
|
|
|
} |
|
|
|
|
|
|
|
/*********************************************************************************************************************** |
|
|
|
* ===================================================POWER_CONTROL=================================================== * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
//设备开始工作 |
|
|
|
static void startwork() { |
|
|
|
port_fan_set(true); |
|
|
|
ozone_control_start(); |
|
|
|
thisDevice.working = true; |
|
|
|
} |
|
|
|
//停止设备工作 |
|
|
|
static void stopwork() { |
|
|
|
ozone_control_stop(); |
|
|
|
port_fan_set(false); |
|
|
|
thisDevice.working = false; |
|
|
|
} |
|
|
|
|
|
|
|
//关机 |
|
|
|
static void shutdwon() { |
|
|
|
printf("power off\n"); |
|
|
|
thisDevice.poweron = false; |
|
|
|
stopwork(); |
|
|
|
} |
|
|
|
//开机 |
|
|
|
static void poweron() { |
|
|
|
printf("power on\n"); |
|
|
|
thisDevice.poweron = true; |
|
|
|
thisDevice.level = klevel1; |
|
|
|
thisDevice.mode = knormal; |
|
|
|
startwork(); |
|
|
|
} |
|
|
|
|
|
|
|
static void increase_and_assign_countdonwnum() { |
|
|
|
if (thisDevice.countdonwnum == 4) { |
|
|
|
thisDevice.countdonwnum = 0; |
|
|
|
thisDevice.countdonwnum_s = 0; |
|
|
|
thisDevice.countdonw_setting_num = 0; |
|
|
|
/*********************************************************************************************************************** |
|
|
|
* =================================================KEY_EVENT_PROCESS================================================= * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
//电源按键处理 |
|
|
|
static void mf_process_poweron_key(zkey_t* key) { |
|
|
|
printf("on %s \n", key->name); |
|
|
|
if (!thisDevice.poweron) { |
|
|
|
poweron(); |
|
|
|
} else { |
|
|
|
shutdwon(); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
//等级按键处理 |
|
|
|
static void mf_process_level_key(zkey_t* key) { |
|
|
|
if (!thisDevice.poweron) return; |
|
|
|
printf("on %s \n", key->name); |
|
|
|
/** |
|
|
|
* @brief 当前在不在修改状态,不在,则进入修改状态 |
|
|
|
*/ |
|
|
|
if (thisDevice.level == klevel1) { |
|
|
|
printf("changet level to level2\n"); |
|
|
|
thisDevice.level = klevel2; |
|
|
|
//更改臭氧状态 |
|
|
|
} else if (thisDevice.level == klevel2) { |
|
|
|
printf("changet level to level1\n"); |
|
|
|
thisDevice.level = klevel1; |
|
|
|
//更改臭氧状态 |
|
|
|
} |
|
|
|
hcis_active_input(kchange_level_input); |
|
|
|
return; |
|
|
|
} |
|
|
|
//定时按键处理 |
|
|
|
static void mf_process_timer_key(zkey_t* key) { |
|
|
|
if (!thisDevice.poweron) return; |
|
|
|
printf("on %s \n", key->name); |
|
|
|
if (!thisDevice.working) { |
|
|
|
startwork(); |
|
|
|
} |
|
|
|
increase_and_assign_countdonwnum(); |
|
|
|
if (thisDevice.countdonwnum_s == 0) { |
|
|
|
hcis_active_input(knone_active); |
|
|
|
thisDevice.mode = knormal; |
|
|
|
} else { |
|
|
|
thisDevice.countdonwnum_s = (thisDevice.countdonwnum + 1) * kconst_countdown_step_s; |
|
|
|
thisDevice.countdonwnum = thisDevice.countdonwnum + 1; |
|
|
|
thisDevice.countdonw_setting_num = thisDevice.countdonwnum; |
|
|
|
thisDevice.countdonw_start_ticket = systicket_get_now_ms(); |
|
|
|
hcis_active_input(kchange_countdonw_time_input); |
|
|
|
thisDevice.mode = ktimingMode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void set_countdown(int countdownnum) { |
|
|
|
thisDevice.countdonwnum = countdownnum; |
|
|
|
thisDevice.countdonwnum_s = thisDevice.countdonwnum * kconst_countdown_step_s; |
|
|
|
thisDevice.countdonw_setting_num = thisDevice.countdonwnum; |
|
|
|
thisDevice.countdonw_start_ticket = systicket_get_now_ms(); |
|
|
|
//间隔按键处理 |
|
|
|
static void mf_process_interval_key(zkey_t* key) { |
|
|
|
if (!thisDevice.poweron) return; |
|
|
|
printf("on %s \n", key->name); |
|
|
|
if (!thisDevice.working) { |
|
|
|
startwork(); |
|
|
|
} |
|
|
|
increase_and_assign_countdonwnum(); |
|
|
|
if (thisDevice.countdonwnum_s == 0) { |
|
|
|
hcis_active_input(knone_active); |
|
|
|
thisDevice.mode = knormal; |
|
|
|
} else { |
|
|
|
hcis_active_input(kchange_countdonw_time_input); |
|
|
|
thisDevice.mode = kintermittentMode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void onkey(zkey_t* key, zkey_state_t key_state) { |
|
|
|
if /* */ (strcmp(key->name, "powerkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
printf("on %s \n", key->name); |
|
|
|
if (!thisDevice.poweron) { |
|
|
|
printf("power on\n"); |
|
|
|
thisDevice.poweron = true; |
|
|
|
thisDevice.level = klevel1; |
|
|
|
thisDevice.mode = knormal; |
|
|
|
startwork(); |
|
|
|
} else { |
|
|
|
shutdwon(); |
|
|
|
} |
|
|
|
return; |
|
|
|
mf_process_poweron_key(key); |
|
|
|
} else if (strcmp(key->name, "levelkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
mf_process_level_key(key); |
|
|
|
} else if (strcmp(key->name, "timerkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
mf_process_timer_key(key); |
|
|
|
} else if (strcmp(key->name, "intervalkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
mf_process_interval_key(key); |
|
|
|
} |
|
|
|
// levelkey |
|
|
|
if (strcmp(key->name, "levelkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
if (!thisDevice.poweron) return; |
|
|
|
printf("on %s \n", key->name); |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 当前在不在修改状态,不在,则进入修改状态 |
|
|
|
*/ |
|
|
|
if (!hcis_input_is_active(kchange_level_input)) { |
|
|
|
hcis_active_input(kchange_level_input); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (thisDevice.level == klevel1) { |
|
|
|
printf("changet level to level2\n"); |
|
|
|
thisDevice.level = klevel2; |
|
|
|
//更改臭氧状态 |
|
|
|
} else if (thisDevice.level == klevel2) { |
|
|
|
printf("changet level to level1\n"); |
|
|
|
thisDevice.level = klevel1; |
|
|
|
//更改臭氧状态 |
|
|
|
} |
|
|
|
hcis_active_input(kchange_level_input); |
|
|
|
return; |
|
|
|
} |
|
|
|
// timerkey |
|
|
|
if (strcmp(key->name, "timerkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
if (!thisDevice.poweron) return; |
|
|
|
printf("on %s \n", key->name); |
|
|
|
port_fan_set(true); |
|
|
|
// TODO:启动臭氧 |
|
|
|
if (!hcis_input_is_active(kchange_countdonw_time_input)) { |
|
|
|
hcis_active_input(kchange_countdonw_time_input); |
|
|
|
if (thisDevice.mode != ktimingMode || thisDevice.countdonwnum_s == 0) { |
|
|
|
set_countdown(1); |
|
|
|
thisDevice.mode = ktimingMode; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
/*********************************************************************************************************************** |
|
|
|
* ===============================================THIS_MODULE_SCHEDULE================================================ * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
static void mf_try_autoshutdown() { |
|
|
|
if (thisDevice.poweron) { |
|
|
|
if (thisDevice.countdonwnum_s == 0) { |
|
|
|
shutdwon(); |
|
|
|
} |
|
|
|
|
|
|
|
hcis_active_input(kchange_countdonw_time_input); |
|
|
|
increase_and_assign_countdonwnum(); |
|
|
|
} |
|
|
|
if (strcmp(key->name, "intervalkey") == 0 && zks_rising_edge == key_state) { |
|
|
|
if (!thisDevice.poweron) return; |
|
|
|
printf("on %s \n", key->name); |
|
|
|
// TODO:启动臭氧 |
|
|
|
|
|
|
|
port_fan_set(true); |
|
|
|
} |
|
|
|
|
|
|
|
if (!hcis_input_is_active(kchange_intermittentmode_time_input)) { |
|
|
|
hcis_active_input(kchange_intermittentmode_time_input); |
|
|
|
if (thisDevice.mode != kintermittentMode || thisDevice.countdonwnum_s == 0) { |
|
|
|
set_countdown(1); |
|
|
|
thisDevice.mode = kintermittentMode; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
static void mf_try_autostop() { |
|
|
|
//间歇模式下,定时到达定时时间,停止工作 |
|
|
|
if (thisDevice.countdonwnum_s == 0) stopwork(); |
|
|
|
} |
|
|
|
|
|
|
|
hcis_active_input(kchange_intermittentmode_time_input); |
|
|
|
increase_and_assign_countdonwnum(); |
|
|
|
static void mf_try_auto_restart() { |
|
|
|
//间歇模式下,再次到达工作时间,再次工作 |
|
|
|
if (systicket_haspassedms(thisDevice.countdonw_start_ticket) / 1000 > INTERMITTENTMODE_PERIOD_S) { |
|
|
|
mf_set_countdown(thisDevice.countdonw_setting_num); |
|
|
|
startwork(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void update_countdown() { |
|
|
|
static void mf_update_countdown() { |
|
|
|
if /* */ (thisDevice.mode == knormal) { |
|
|
|
thisDevice.countdonwnum = 0; |
|
|
|
thisDevice.countdonwnum_s = 0; |
|
|
@ -169,48 +205,39 @@ void update_countdown() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void process_countdwonevent() { |
|
|
|
//更新倒计时计数 |
|
|
|
update_countdown(); |
|
|
|
void this_module_schedule() { |
|
|
|
/** |
|
|
|
* @brief 处理倒计时事件发生时的事件 |
|
|
|
* @brief 定时模式下 |
|
|
|
*/ |
|
|
|
if (thisDevice.mode == ktimingMode) { |
|
|
|
//定时自动关机 |
|
|
|
if (thisDevice.poweron) { |
|
|
|
if (thisDevice.countdonwnum_s == 0) { |
|
|
|
shutdwon(); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (thisDevice.mode == kintermittentMode) { |
|
|
|
/** |
|
|
|
* @brief 如果当前处于间歇模式下 |
|
|
|
* 定时时间到,关闭风扇,关闭臭氧,等待大周期过去后,开启风扇,开启臭氧,并重新计时 |
|
|
|
*/ |
|
|
|
mf_update_countdown(); |
|
|
|
mf_try_autoshutdown(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief 间歇模式下,自动停止,自动重启 |
|
|
|
*/ |
|
|
|
if (thisDevice.mode == kintermittentMode) { |
|
|
|
mf_update_countdown(); |
|
|
|
if (thisDevice.working) { |
|
|
|
//间歇模式下,定时到达定时时间,停止工作 |
|
|
|
if (thisDevice.countdonwnum_s == 0) stopwork(); |
|
|
|
mf_try_autostop(); |
|
|
|
} else { |
|
|
|
//间歇模式下,再次到达工作时间,再次工作 |
|
|
|
if (systicket_haspassedms(thisDevice.countdonw_start_ticket) / 1000 > INTERMITTENTMODE_PERIOD_S) { |
|
|
|
set_countdown(thisDevice.countdonw_setting_num); |
|
|
|
startwork(); |
|
|
|
} |
|
|
|
mf_try_auto_restart(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
void ozone_control_start(); |
|
|
|
void ozone_control_stop(); |
|
|
|
void ozone_control_schedule(); |
|
|
|
|
|
|
|
void do_debug_light_state() { |
|
|
|
/*********************************************************************************************************************** |
|
|
|
* =======================================================MAIN======================================================== * |
|
|
|
***********************************************************************************************************************/ |
|
|
|
static void mf_do_debug_light_state() { |
|
|
|
static uint8_t debug_led_state = 1; |
|
|
|
debug_led_state = !debug_led_state; |
|
|
|
port_debug_set(debug_led_state); |
|
|
|
} |
|
|
|
|
|
|
|
void init_all_subdevice_state() { |
|
|
|
static void mf_init_all_subdevice_state() { |
|
|
|
port_debug_set(false); |
|
|
|
port_fan_set(false); |
|
|
|
port_led0_set(false); |
|
|
@ -230,7 +257,7 @@ int main(void) { |
|
|
|
/*系统初始化*/ |
|
|
|
zgpio_init_all_gpio(); // |
|
|
|
port_init(); // |
|
|
|
init_all_subdevice_state(); // |
|
|
|
mf_init_all_subdevice_state(); // |
|
|
|
printf("==========OZONE_GENERATOR==========\n"); // |
|
|
|
printf("= manufactor: iflytop\n"); // |
|
|
|
printf("= version : %s\n", VERSION); // |
|
|
@ -244,17 +271,18 @@ int main(void) { |
|
|
|
* @brief |
|
|
|
* 频率从20k起步,递增50hz,每次等待100ms计算功率 |
|
|
|
*/ |
|
|
|
// printf_ozone_freq_and_power_table(); |
|
|
|
// ozone_control_init(); |
|
|
|
while (true) { |
|
|
|
//按键扫描逻辑 |
|
|
|
DO_IT_EACH_MS(KEY_PERIOD) { zkey_do_loop_in_each_period(NULL); } |
|
|
|
END(); |
|
|
|
DO_IT_EACH_MS(150) { do_debug_light_state(); } |
|
|
|
//调试指示灯 |
|
|
|
DO_IT_EACH_MS(150) { mf_do_debug_light_state(); } |
|
|
|
END(); |
|
|
|
//臭氧控制逻辑Schedule |
|
|
|
ozone_control_schedule(); |
|
|
|
//人机交互逻辑Schedule |
|
|
|
hcis_shcedule(); |
|
|
|
process_countdwonevent(); |
|
|
|
// printf("countddonw %d\n", thisDevice.countdonwnum_s); |
|
|
|
//当前模块逻辑Schedule |
|
|
|
this_module_schedule(); |
|
|
|
} |
|
|
|
} |