-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrangeCookModel.c
96 lines (83 loc) · 2.54 KB
/
rangeCookModel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
#include "rangeCookModelClass.h"
static state_t cookManager (
rangeCookModel_t *this,
watt_t watt,
int timer,
funcStop callback,
rangeController_t *rangeController);
static void cookStart (rangeCookModel_t *this, watt_t watt, int timer);
static int getCookTimer (rangeCookModel_t *this);
const rangeCookModel_t rangeCookModelInitValue = {
state_standby,
0,
&cookManager,
&cookStart,
&getCookTimer,
};
static int stateStandby (rangeCookModel_t *this, watt_t watt, int timer)
{
this->rangeMagnetronModel.init (&this->rangeMagnetronModel);
}
static int stateCook (rangeCookModel_t *this, watt_t watt, int timer)
{
this->rangeMagnetronModel.manager (&this->rangeMagnetronModel);
if (this->cookTimer <= 0) {
this->state = state_end;
}
}
static int stateEnd (
rangeCookModel_t *this,
funcStop callback,
rangeController_t *rangeController)
{
this->state = state_standby;
this->rangeTimerModel.pInitTimer (&this->rangeTimerModel);
callback (rangeController);
}
static state_t cookManager (
rangeCookModel_t *this,
watt_t watt,
int timer,
funcStop callback,
rangeController_t *rangeController)
{
switch (this->state) {
default:
case state_standby:
stateStandby (this, watt, timer);
break;
case state_cook:
stateCook (this, watt, timer);
break;
case state_end:
stateEnd (this, callback, rangeController);
break;
}
return (this->state);
}
static void cookStart (rangeCookModel_t *this, watt_t watt, int timer)
{
this->state = state_cook;
this->cookTimer = timer;
this->rangeTimerModel.pSetTimer (&this->rangeTimerModel, &this->cookTimer);
this->rangeMagnetronModel.mqStart (&this->rangeMagnetronModel, watt);
}
static int getCookTimer (rangeCookModel_t *this)
{
return (this->cookTimer);
}
void rangeCookModel_Constructor (rangeCookModel_t *this)
{
this->state = rangeCookModelInitValue.state;
this->cookTimer = rangeCookModelInitValue.cookTimer;
this->pCookManager = rangeCookModelInitValue.pCookManager;
this->pCookStart = rangeCookModelInitValue.pCookStart;
this->pGetCookTimer = rangeCookModelInitValue.pGetCookTimer;
rangeTimerModel_Constructor (&this->rangeTimerModel);
rangeMagnetronModel_Constructor (&this->rangeMagnetronModel);
}