You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
3.6 KiB
160 lines
3.6 KiB
|
|
#include <stdbool.h> //定义布尔
|
|
#include <string.h>
|
|
|
|
#include "key.h"
|
|
#include "port.h"
|
|
#include "systicket.h"
|
|
#include "this_device.h"
|
|
|
|
static key_t s_keys[] = {
|
|
s_key_init("powerkey", port_gpio_get_power_key_state),
|
|
s_key_init("levelkey", port_gpio_get_level_key_state),
|
|
s_key_init("timerkey", port_gpio_get_timer_key_state),
|
|
s_key_init("intervalkey", port_gpio_get_interval_key_state),
|
|
};
|
|
|
|
static ThisDevice_t this_device;
|
|
|
|
static void mf_init_all_subdevice_state() {
|
|
port_debug_set(false);
|
|
port_fan_set(false);
|
|
port_led0_set(false);
|
|
port_led1_set(false);
|
|
port_led2_set(false);
|
|
port_led3_set(false);
|
|
port_led_r_set(false);
|
|
port_led_g_set(false);
|
|
port_led_b_set(false);
|
|
}
|
|
|
|
//开始工作
|
|
static void startwork() { port_fan_set(true); }
|
|
//停止工作
|
|
static void stopwork() { port_fan_set(false); }
|
|
|
|
static void poweron() {
|
|
this_device.power = true;
|
|
this_device.ozone_level = level_low;
|
|
this_device.ozone_module = normal;
|
|
startwork();
|
|
|
|
return;
|
|
}
|
|
static void powerdown() {
|
|
this_device.power = false;
|
|
stopwork();
|
|
|
|
return;
|
|
}
|
|
|
|
// 各个按键处理逻辑
|
|
static void mf_process_poweron_key(key_t *key) {
|
|
printf("key name:%s\n", key->name);
|
|
|
|
if (!this_device.power) {
|
|
mf_init_all_subdevice_state();
|
|
poweron();
|
|
} else {
|
|
powerdown();
|
|
}
|
|
|
|
return;
|
|
}
|
|
static void mf_process_level_key(key_t *key) {
|
|
if (!this_device.power) {
|
|
mf_init_all_subdevice_state();
|
|
return;
|
|
}
|
|
printf("key name:%s\n", key->name);
|
|
return;
|
|
}
|
|
static void mf_process_timer_key(key_t *key) {
|
|
if (!this_device.power) {
|
|
mf_init_all_subdevice_state();
|
|
return;
|
|
}
|
|
printf("key name:%s\n", key->name);
|
|
return;
|
|
}
|
|
static void mf_process_interval_key(key_t *key) {
|
|
if (!this_device.power) {
|
|
mf_init_all_subdevice_state();
|
|
return;
|
|
}
|
|
printf("key name:%s\n", key->name);
|
|
return;
|
|
}
|
|
|
|
static void onkey(key_t *key, key_state_t key_state) {
|
|
if /* */ (strcmp(key->name, "powerkey") == 0 && zks_rising_edge == key_state) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
key_module_t key_module = key_module_init(s_keys, onkey);
|
|
|
|
//等级处理
|
|
void device_level_process() {}
|
|
//定时处理
|
|
void device_time_process() {}
|
|
|
|
void hcis_shcedule_process() {
|
|
if (!this_device.power) {
|
|
mf_init_all_subdevice_state();
|
|
return;
|
|
}
|
|
|
|
device_level_process();
|
|
device_time_process();
|
|
}
|
|
|
|
void hcis_shcedule() {
|
|
static uint32_t ticket = 0;
|
|
|
|
if (systicket_haspassedms(ticket) > 30) {
|
|
ticket = systicket_get_now_ms();
|
|
hcis_shcedule_process();
|
|
}
|
|
}
|
|
|
|
void hardware_init() {
|
|
SystemInit(); //配置系统时钟
|
|
DeviceClockAllEnable(); //打开所有外设时钟
|
|
systicket_init();
|
|
port_init();
|
|
}
|
|
void hardware_default_settings() { mf_init_all_subdevice_state(); }
|
|
|
|
void flip_debuf_light_level() {
|
|
static uint8_t debug_led_state = 1;
|
|
debug_led_state = !debug_led_state;
|
|
port_debug_set(debug_led_state);
|
|
}
|
|
|
|
int main() {
|
|
hardware_init();
|
|
hardware_default_settings();
|
|
|
|
key_init(&key_module);
|
|
|
|
while (true) {
|
|
// scan key
|
|
DO_IT_EACH_MS(20) { key_do_loop_in_each_period(); };
|
|
END();
|
|
|
|
// debug light
|
|
DO_IT_EACH_MS(150) { flip_debuf_light_level(); }
|
|
END();
|
|
|
|
hcis_shcedule();
|
|
}
|
|
|
|
return 0;
|
|
}
|