2023-01-27 22:37:42 +08:00

54 lines
1.7 KiB
C

#include <stdio.h>
#include "gpio.h"
#include "ui.h"
#include "keypad.h"
#include "global.h"
void app_init() {
// 程序开始时执行一次
ui_screen_main();
kp_query();
printf("\n====start====\n");
}
void app_main_loop() {
// 反复被调用执行
uint8_t event = kp_query();
uint8_t event_type = kp_Type(event);
uint8_t event_value = kp_Value(event);
if (event_type == kp_ROTATE_RIGHT || event_type == kp_ROTATE_LEFT) {
// 调整频率
if (event_type == kp_ROTATE_RIGHT) {
global_data.freq += event_value;
} else {
global_data.freq -= event_value;
}
uint16_t limit_min = (global_data.rf_mode == G_RF_MODE_AM) ? G_AM_FREQ_MIN : G_FM_FREQ_MIN;
uint16_t limit_max = (global_data.rf_mode == G_RF_MODE_AM) ? G_AM_FREQ_MAX : G_FM_FREQ_MAX;
if (global_data.freq < limit_min) {
global_data.freq = limit_min;
} else if (global_data.freq > limit_max) {
global_data.freq = limit_max;
}
printf("Freq: %d\n", global_data.freq);
ui_com_freq_digital(1);
} else if (event_type == kp_SHORT_CLICK) {
if (event_value == kp_KEY1) {
// 切换FM和AM
if (global_data.rf_mode == G_RF_MODE_AM) {
global_data.rf_mode = G_RF_MODE_FM;
global_data.freq = G_FM_FREQ_MIN;
} else {
global_data.rf_mode = G_RF_MODE_AM;
global_data.freq = G_AM_FREQ_MIN;
}
ui_com_fm_am(1);
ui_com_freq_digital(1);
}
} else if (event_type == kp_LONG_PRESS) {
//
} else if (event_type != kp_NOP) {
printf("event: %d, key: %d\n", event_type, event_value);
}
}