📄 dc550_phonesm.c
字号:
* has two parameters: firstline is 1 if that state "owns" the first line,
* and secondline is 1 if the state "owns" the second line.
*****************************************************************************/
void phonesm_exec_periodic(void) {
// Declare temporary variable
unsigned int i;
// Repeat until something returns 0
do {
switch(phonesm_currentstate) {
case PHONESM_STATE_IDLE:
i = phonesm_idle_exec_periodic(1,1);
break;
case PHONESM_STATE_INIT:
i = phonesm_init_exec_periodic(1,1);
break;
case PHONESM_STATE_ACTIVE:
i = phonesm_active_exec_periodic(1,1);
break;
case PHONESM_STATE_PROGRAM:
i = phonesm_program_exec_periodic(1,1);
break;
case PHONESM_STATE_DISPLAY12:
i = phonesm_display12_exec_periodic(1,1);
break;
case PHONESM_STATE_VOLUME:
i = phonesm_volume_exec_periodic(1,1);
break;
case PHONESM_STATE_CONTRAST:
i = phonesm_contrast_exec_periodic(1,1);
break;
case PHONESM_STATE_MEMORY:
i = phonesm_memory_exec_periodic(1,1);
break;
case PHONESM_STATE_PREDIAL:
i = phonesm_predial_exec_periodic(1,1);
break;
};
} while(i);
}
/******************************************************************************
* FUNCTION: void phonesm_activate_state(PHONESM_STATE_E state)
******************************************************************************
* DESCRIPTION:
* This function places the state passed in as a parameter on top of the
* State Machine "stack", which is effectively a linked list without
* pointers. It evaluates four scenarios:
* 1. state == PHONESM_STATE_IDLE
* 2. state == previous_currentstate
* 3. state == something else that was formerly active
* 4. state == something else that was not formerly active
*****************************************************************************/
void phonesm_activate_state(PHONESM_STATE_E state) {
PHONESM_STATE_E preceding_state;
PHONESM_STATE_E previous_currentstate = phonesm_currentstate;
// Runs through the state stack looking for either the state (passed in as
// a parameter) or the PHONESM_STATE_IDLE state
while((phonesm_currentstate != PHONESM_STATE_IDLE) &&
(phonesm_currentstate != state)) {
preceding_state = phonesm_currentstate;
phonesm_currentstate = phonesm_get_exitstate(phonesm_currentstate);
}
// Reached the bottom of the state stack: handles scenarios 1 and 4
if(phonesm_currentstate == PHONESM_STATE_IDLE) {
phonesm_currentstate = state;
// This should work even if previous_currentstate was PHONESM_STATE_IDLE
phonesm_set_exitstate(state, previous_currentstate);
phonesm_state_enter(state);
}
// (phonesm_currentstate == state): Did not reach the bottom of the stack
// Scenario 2 should never happen, but if it does, this handles it
else if(state == previous_currentstate) {
phonesm_currentstate = previous_currentstate;
phonesm_state_enter(phonesm_currentstate);
}
// (phonesm_currentstate == state): scenario 3
else {
phonesm_set_exitstate(state, phonesm_get_exitstate(preceding_state));
phonesm_set_exitstate(phonesm_currentstate, previous_currentstate);
phonesm_state_enter(phonesm_currentstate);
}
}
/******************************************************************************
* FUNCTION: void phonesm_deactivate_state(PHONESM_STATE_E state)
******************************************************************************
* DESCRIPTION:
* This function removes the state passed in as a parameter from the State
* Machine "stack". Either one of the following could be true:
* 1. state == PHONESM_STATE_IDLE, in which case this function does nothing
* 2. state == something else in the stack, in which case the state is removed
* 3. state == something else not in teh stack, in which case this function
* does nothing
*****************************************************************************/
void phonesm_deactivate_state(PHONESM_STATE_E state) {
PHONESM_STATE_E preceding_state;
PHONESM_STATE_E previous_currentstate = phonesm_currentstate;
// Runs through the state stack looking for either the state (passed in as
// a parameter) or the PHONESM_STATE_IDLE state
while((phonesm_currentstate != PHONESM_STATE_IDLE) &&
(phonesm_currentstate != state)) {
preceding_state = phonesm_currentstate;
phonesm_currentstate = phonesm_get_exitstate(phonesm_currentstate);
}
// Makes sure that this is scenario 2
if(phonesm_currentstate != PHONESM_STATE_IDLE) {
// State was on top of the stack
if(phonesm_currentstate == previous_currentstate) {
phonesm_currentstate = phonesm_get_exitstate(previous_currentstate);
phonesm_state_enter(phonesm_currentstate);
}
// State was not on top of the stack
else {
phonesm_set_exitstate(preceding_state,
phonesm_get_exitstate(phonesm_currentstate));
phonesm_currentstate = previous_currentstate;
}
}
}
/******************************************************************************
* FUNCTION: void phonesm_set_exitstate(PHONESM_STATE_E state,
* PHONESM_STATE_E exitstate)
******************************************************************************
* DESCRIPTION:
*
*****************************************************************************/
void phonesm_set_exitstate(PHONESM_STATE_E state, PHONESM_STATE_E exitstate) {
switch (state) {
case PHONESM_STATE_IDLE:
// Nobody should ever try to set an exit state for the Idle State
return;
case PHONESM_STATE_INIT:
phonesm_init_exitstate = exitstate;
return;
case PHONESM_STATE_ACTIVE:
phonesm_active_exitstate = exitstate;
return;
case PHONESM_STATE_PROGRAM:
phonesm_program_exitstate = exitstate;
return;
case PHONESM_STATE_DISPLAY12:
phonesm_display12_exitstate = exitstate;
return;
case PHONESM_STATE_VOLUME:
phonesm_volume_exitstate = exitstate;
return;
case PHONESM_STATE_CONTRAST:
phonesm_contrast_exitstate = exitstate;
return;
case PHONESM_STATE_MEMORY:
phonesm_memory_exitstate = exitstate;
return;
case PHONESM_STATE_PREDIAL:
phonesm_predial_exitstate = exitstate;
return;
}
}
/******************************************************************************
* FUNCTION: PHONESM_STATE_E phonesm_get_exitstate(PHONESM_STATE_E state)
******************************************************************************
* DESCRIPTION:
*
*****************************************************************************/
PHONESM_STATE_E phonesm_get_exitstate(PHONESM_STATE_E state) {
switch (state) {
case PHONESM_STATE_IDLE:
return PHONESM_STATE_IDLE;
case PHONESM_STATE_INIT:
return phonesm_init_exitstate;
case PHONESM_STATE_ACTIVE:
return phonesm_active_exitstate;
case PHONESM_STATE_PROGRAM:
return phonesm_program_exitstate;
case PHONESM_STATE_DISPLAY12:
return phonesm_display12_exitstate;
case PHONESM_STATE_VOLUME:
return phonesm_volume_exitstate;
case PHONESM_STATE_CONTRAST:
return phonesm_contrast_exitstate;
case PHONESM_STATE_MEMORY:
return phonesm_memory_exitstate;
case PHONESM_STATE_PREDIAL:
return phonesm_predial_exitstate;
}
// This line makes the error go away.
return PHONESM_STATE_IDLE;
}
/******************************************************************************
* FUNCTION: void phonesm_state_enter(PHONESM_STATE_E state)
******************************************************************************
* DESCRIPTION:
*
*****************************************************************************/
void phonesm_state_enter(PHONESM_STATE_E state) {
switch (state) {
case PHONESM_STATE_IDLE:
phonesm_idle_state_enter();
break;
case PHONESM_STATE_INIT:
phonesm_init_state_enter();
break;
case PHONESM_STATE_ACTIVE:
phonesm_active_state_enter();
break;
case PHONESM_STATE_PROGRAM:
phonesm_program_state_enter();
break;
case PHONESM_STATE_DISPLAY12:
phonesm_display12_state_enter();
break;
case PHONESM_STATE_VOLUME:
phonesm_volume_state_enter();
break;
case PHONESM_STATE_CONTRAST:
phonesm_contrast_state_enter();
break;
case PHONESM_STATE_MEMORY:
phonesm_memory_state_enter();
break;
case PHONESM_STATE_PREDIAL:
phonesm_predial_state_enter();
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -