Browse Source

重构部分方法名

master
zhaohe 3 years ago
parent
commit
3c54f65b79
  1. 66
      APP/main.c
  2. 11
      APP/service/human_computer_interaction_service.c
  3. 14
      APP/service/human_computer_interaction_service.h
  4. 17
      APP/service/light_control_service.h
  5. 12
      APP/service/ozone_control_service.c
  6. 9
      APP/service/thisdevice.h
  7. 1
      APP/state_machine.c
  8. 1520
      project_ozone/Listings/project_o.map
  9. 67
      project_ozone/project_o.uvgui.zel

66
APP/main.c

@ -10,7 +10,7 @@
#include "zes8p5066lib/systicket.h" #include "zes8p5066lib/systicket.h"
#include "zes8p5066lib/uart0.h" #include "zes8p5066lib/uart0.h"
// //
#include "service/light_control_service.h"
#include "service/human_computer_interaction_service.h"
#include "service/ozone_control_service.h" #include "service/ozone_control_service.h"
#include "service/thisdevice.h" #include "service/thisdevice.h"
#include "test.h" #include "test.h"
@ -39,12 +39,21 @@ static uint32_t compute_countdown_num(int countdowns) {
if (countdowns) return countdowns / kconst_countdown_step_s + !!(countdowns % kconst_countdown_step_s); if (countdowns) return countdowns / kconst_countdown_step_s + !!(countdowns % kconst_countdown_step_s);
} }
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() { static void shutdwon() {
printf("power off\n"); printf("power off\n");
thisDevice.poweron = false; thisDevice.poweron = false;
port_fan_set(false);
//@TODO:
port_ozone_pwm_stop();
stopwork();
} }
static void increase_and_assign_countdonwnum() { static void increase_and_assign_countdonwnum() {
@ -52,7 +61,7 @@ static void increase_and_assign_countdonwnum() {
thisDevice.countdonwnum = 0; thisDevice.countdonwnum = 0;
thisDevice.countdonwnum_s = 0; thisDevice.countdonwnum_s = 0;
thisDevice.countdonw_setting_num = 0; thisDevice.countdonw_setting_num = 0;
lcs_active_input(knone_active);
hcis_active_input(knone_active);
thisDevice.mode = knormal; thisDevice.mode = knormal;
} else { } else {
thisDevice.countdonwnum_s = (thisDevice.countdonwnum + 1) * kconst_countdown_step_s; thisDevice.countdonwnum_s = (thisDevice.countdonwnum + 1) * kconst_countdown_step_s;
@ -77,10 +86,7 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
thisDevice.poweron = true; thisDevice.poweron = true;
thisDevice.level = klevel1; thisDevice.level = klevel1;
thisDevice.mode = knormal; thisDevice.mode = knormal;
//
port_fan_set(true);
//@TODO:
startwork();
} else { } else {
shutdwon(); shutdwon();
} }
@ -94,8 +100,8 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
/** /**
* @brief * @brief
*/ */
if (!lcs_input_is_active(kchange_level_input)) {
lcs_active_input(kchange_level_input);
if (!hcis_input_is_active(kchange_level_input)) {
hcis_active_input(kchange_level_input);
return; return;
} }
@ -108,7 +114,7 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
thisDevice.level = klevel1; thisDevice.level = klevel1;
// //
} }
lcs_active_input(kchange_level_input);
hcis_active_input(kchange_level_input);
return; return;
} }
// timerkey // timerkey
@ -117,8 +123,8 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
printf("on %s \n", key->name); printf("on %s \n", key->name);
port_fan_set(true); port_fan_set(true);
// TODO: // TODO:
if (!lcs_input_is_active(kchange_countdonw_time_input)) {
lcs_active_input(kchange_countdonw_time_input);
if (!hcis_input_is_active(kchange_countdonw_time_input)) {
hcis_active_input(kchange_countdonw_time_input);
if (thisDevice.mode != ktimingMode || thisDevice.countdonwnum_s == 0) { if (thisDevice.mode != ktimingMode || thisDevice.countdonwnum_s == 0) {
set_countdown(1); set_countdown(1);
thisDevice.mode = ktimingMode; thisDevice.mode = ktimingMode;
@ -126,7 +132,7 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
return; return;
} }
lcs_active_input(kchange_countdonw_time_input);
hcis_active_input(kchange_countdonw_time_input);
increase_and_assign_countdonwnum(); increase_and_assign_countdonwnum();
} }
if (strcmp(key->name, "intervalkey") == 0 && zks_rising_edge == key_state) { if (strcmp(key->name, "intervalkey") == 0 && zks_rising_edge == key_state) {
@ -136,8 +142,8 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
port_fan_set(true); port_fan_set(true);
if (!lcs_input_is_active(kchange_intermittentmode_time_input)) {
lcs_active_input(kchange_intermittentmode_time_input);
if (!hcis_input_is_active(kchange_intermittentmode_time_input)) {
hcis_active_input(kchange_intermittentmode_time_input);
if (thisDevice.mode != kintermittentMode || thisDevice.countdonwnum_s == 0) { if (thisDevice.mode != kintermittentMode || thisDevice.countdonwnum_s == 0) {
set_countdown(1); set_countdown(1);
thisDevice.mode = kintermittentMode; thisDevice.mode = kintermittentMode;
@ -145,12 +151,12 @@ static void onkey(zkey_t* key, zkey_state_t key_state) {
return; return;
} }
lcs_active_input(kchange_intermittentmode_time_input);
hcis_active_input(kchange_intermittentmode_time_input);
increase_and_assign_countdonwnum(); increase_and_assign_countdonwnum();
} }
} }
void compute_countdown() {
void update_countdown() {
if /* */ (thisDevice.mode == knormal) { if /* */ (thisDevice.mode == knormal) {
thisDevice.countdonwnum = 0; thisDevice.countdonwnum = 0;
thisDevice.countdonwnum_s = 0; thisDevice.countdonwnum_s = 0;
@ -164,8 +170,8 @@ void compute_countdown() {
} }
void process_countdwonevent() { void process_countdwonevent() {
//countdown
compute_countdown();
//
update_countdown();
/** /**
* @brief * @brief
*/ */
@ -181,20 +187,14 @@ void process_countdwonevent() {
* @brief * @brief
* ,,,,, * ,,,,,
*/ */
if (!thisDevice.intermittentMode_idle) {
if (thisDevice.countdonwnum_s == 0) {
//
// TODO:
thisDevice.intermittentMode_idle = true;
port_fan_set(false);
}
if (thisDevice.working) {
//,
if (thisDevice.countdonwnum_s == 0) stopwork();
} else { } else {
//,
if (systicket_haspassedms(thisDevice.countdonw_start_ticket) / 1000 > INTERMITTENTMODE_PERIOD_S) { if (systicket_haspassedms(thisDevice.countdonw_start_ticket) / 1000 > INTERMITTENTMODE_PERIOD_S) {
thisDevice.intermittentMode_idle = false;
set_countdown(thisDevice.countdonw_setting_num); set_countdown(thisDevice.countdonw_setting_num);
//
port_fan_set(true);
startwork();
} }
} }
} }
@ -253,7 +253,7 @@ int main(void) {
DO_IT_EACH_MS(150) { do_debug_light_state(); } DO_IT_EACH_MS(150) { do_debug_light_state(); }
END(); END();
ozone_control_schedule(); ozone_control_schedule();
lcs_shcedule();
hcis_shcedule();
process_countdwonevent(); process_countdwonevent();
// printf("countddonw %d\n", thisDevice.countdonwnum_s); // printf("countddonw %d\n", thisDevice.countdonwnum_s);
} }

11
APP/service/light_control_service.c → APP/service/human_computer_interaction_service.c

@ -1,15 +1,15 @@
#include "light_control_service.h"
#include "human_computer_interaction_service.h"
#include "port.h" #include "port.h"
#include "zes8p5066lib/systicket.h" #include "zes8p5066lib/systicket.h"
#include "zsimple_timer/zsimple_timer.h" #include "zsimple_timer/zsimple_timer.h"
void lcs_active_input(active_input_t input) {
void hcis_active_input(active_input_t input) {
thisDevice.active_start_ticket = systicket_get_now_ms(); thisDevice.active_start_ticket = systicket_get_now_ms();
thisDevice.active_input = input; thisDevice.active_input = input;
} }
bool lcs_input_is_active(active_input_t input) { return (thisDevice.active_input == input); }
bool hcis_input_is_active(active_input_t input) { return (thisDevice.active_input == input); }
/*********************************************************************************************************************** /***********************************************************************************************************************
* =====================================================schedule====================================================== * * =====================================================schedule====================================================== *
***********************************************************************************************************************/ ***********************************************************************************************************************/
@ -90,7 +90,7 @@ void process_level_light() {
} }
} }
} else { } else {
if (thisDevice.mode == kintermittentMode && thisDevice.intermittentMode_idle) {
if (thisDevice.mode == kintermittentMode && thisDevice.working) {
mf_set_status_light_state(/*rgb:*/ 0, 1, 0); mf_set_status_light_state(/*rgb:*/ 0, 1, 0);
} else { } else {
mf_set_status_light_by_level(thisDevice.level); mf_set_status_light_by_level(thisDevice.level);
@ -98,6 +98,7 @@ void process_level_light() {
} }
} }
void lcs_schedule_process() { void lcs_schedule_process() {
if (!thisDevice.poweron) { if (!thisDevice.poweron) {
close_all_light(); close_all_light();
@ -112,7 +113,7 @@ void lcs_schedule_process() {
// //
process_level_light(); process_level_light();
} }
void lcs_shcedule() {
void hcis_shcedule() {
static uint32_t ticket = 0; static uint32_t ticket = 0;
if (systicket_haspassedms(ticket) > 30) { if (systicket_haspassedms(ticket) > 30) {
ticket = systicket_get_now_ms(); ticket = systicket_get_now_ms();

14
APP/service/human_computer_interaction_service.h

@ -0,0 +1,14 @@
#pragma once
//
#include <stdbool.h>
#include <stdint.h>
#include "service/thisdevice.h"
/**
* @brief
*
*/
void hcis_active_input(active_input_t input);
bool hcis_input_is_active(active_input_t input);
void hcis_shcedule();

17
APP/service/light_control_service.h

@ -1,17 +0,0 @@
#pragma once
//
#include <stdbool.h>
#include <stdint.h>
#include "service/thisdevice.h"
void lcs_active_input(active_input_t input);
bool lcs_input_is_active(active_input_t input);
/***********************************************************************************************************************
* =====================================================ErrorPage===================================================== *
***********************************************************************************************************************/
void lcs_error_light__set_error(int errorNum);
void lcs_error_light__clear_error(int errorNum);
//
void lcs_shcedule();

12
APP/service/ozone_control_service.c

@ -17,8 +17,8 @@
#define PRV_STOP_EVENT (STATE_MACHINE_PUBLIC_EVENT + 2) #define PRV_STOP_EVENT (STATE_MACHINE_PUBLIC_EVENT + 2)
typedef struct { typedef struct {
float resonant_frequency; //
float nowfreq; //
uint16_t resonant_frequency; //
uint16_t nowfreq; //
bool changefreqdirection; // bool changefreqdirection; //
bool adjustedToTheProperPower; // bool adjustedToTheProperPower; //
} Context_t; } Context_t;
@ -107,16 +107,17 @@ static state_machine_state_t* processBeforeWorkingStateSweepFrequency(state_mach
if (event == ENTER_STATE) { if (event == ENTER_STATE) {
frequency_sweep_start(20000, 100, 40000, 3000); frequency_sweep_start(20000, 100, 40000, 3000);
} else if (event == TIME_EVENT) { } else if (event == TIME_EVENT) {
if (frequency_sweep_is_done()) {
if (frequency_sweep_is_finished()) {
context.resonant_frequency = get_resonant_frequency(25000, 100, 35000); context.resonant_frequency = get_resonant_frequency(25000, 100, 35000);
printf("----------Summarize--------\n"); printf("----------Summarize--------\n");
printf("-resonant_frequency: %f\n", context.resonant_frequency);
printf("-resonant_frequency: %d\n", context.resonant_frequency);
context.nowfreq = context.resonant_frequency; context.nowfreq = context.resonant_frequency;
return &m_states[kWorkingState]; return &m_states[kWorkingState];
} }
} else if (event == EXIT_STATE) { } else if (event == EXIT_STATE) {
frequency_sweep_stop(); frequency_sweep_stop();
} }
return NULL;
} }
static state_machine_state_t* processWorkingState(state_machine_t* machine, state_machine_state_t* nowstate, int event) { static state_machine_state_t* processWorkingState(state_machine_t* machine, state_machine_state_t* nowstate, int event) {
@ -180,6 +181,7 @@ static state_machine_state_t* processWorkingState(state_machine_t* machine, stat
} else if (event == EXIT_STATE) { } else if (event == EXIT_STATE) {
port_ozone_pwm_stop(); port_ozone_pwm_stop();
} }
return NULL;
} }
static state_machine_state_t* state_machine_process_event(state_machine_t* machine, state_machine_state_t* nowstate, int event) { static state_machine_state_t* state_machine_process_event(state_machine_t* machine, state_machine_state_t* nowstate, int event) {
@ -216,7 +218,7 @@ void ozone_control_start() { state_machine_trigger_event(&m_statemachine, PRV_ST
void ozone_control_stop() { state_machine_trigger_event(&m_statemachine, PRV_STOP_EVENT); } void ozone_control_stop() { state_machine_trigger_event(&m_statemachine, PRV_STOP_EVENT); }
void ozone_control_schedule() { void ozone_control_schedule() {
static uint32_t ticket = 0; static uint32_t ticket = 0;
if (systicket_haspassedms(&ticket) > 10 * 1000) {
if (systicket_haspassedms(ticket) > 10 * 1000) {
ticket = systicket_get_now_ms(); ticket = systicket_get_now_ms();
state_machine_schedule_each10ms(&m_statemachine); state_machine_schedule_each10ms(&m_statemachine);
} }

9
APP/service/thisdevice.h

@ -30,9 +30,9 @@ typedef struct {
bool poweron; bool poweron;
mode_t mode; mode_t mode;
level_t level; level_t level;
//
active_input_t active_input;
uint32_t active_start_ticket;
active_input_t active_input; //human_computer_interaction_service维护
uint32_t active_start_ticket; //human_computer_interaction_service维护
int countdonwnum; int countdonwnum;
int countdonwnum_s; int countdonwnum_s;
@ -40,7 +40,8 @@ typedef struct {
int countdonw_setting_num; int countdonw_setting_num;
uint32_t countdonw_start_ticket; uint32_t countdonw_start_ticket;
bool intermittentMode_idle;
// bool intermittentMode_idle;
bool working;
} ThisDevice_t; } ThisDevice_t;

1
APP/state_machine.c

@ -1,5 +1,6 @@
#include "state_machine.h" #include "state_machine.h"
#include <stdio.h>
void state_machine_init(state_machine_t* machine, state_machine_state_t* statetable, size_t len, state_machine_process_event_t process_event) { void state_machine_init(state_machine_t* machine, state_machine_state_t* statetable, size_t len, state_machine_process_event_t process_event) {
machine->states = statetable; machine->states = statetable;
machine->nstate = len; machine->nstate = len;

1520
project_ozone/Listings/project_o.map
File diff suppressed because it is too large
View File

67
project_ozone/project_o.uvgui.zel
File diff suppressed because it is too large
View File

Loading…
Cancel
Save