-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.cpp
More file actions
54 lines (43 loc) · 1.22 KB
/
State.cpp
File metadata and controls
54 lines (43 loc) · 1.22 KB
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
#include "State.h"
State::State(unsigned id, unsigned dosage, unsigned moisture_percent, unsigned days_to, unsigned days_pass) {
state_id = id;
water_dosage = dosage;
moisture = moisture_percent;
days_to_watering = days_to;
days_passed = days_pass;
watering_time = water_dosage / (ML_PER_SECOND / 1000);
}
void State::setContext(unsigned id) {
context_id = id;
}
void State::setStateId(int id) {
state_id = id;
digitalWrite(AUTO_LED_PIN, id == AUTO_STATE_ID);
digitalWrite(MANUAL_LED_PIN, id == MANUAL_STATE_ID);
}
void State::setWateringType(int type) {
watering_type = type;
}
void State::setDosage(unsigned dose) {
water_dosage = dose;
watering_time = water_dosage / (ML_PER_SECOND / 1000);
}
void State::setNextWatering(unsigned nxt) {
if (watering_type == w_types::by_days) {
days_to_watering = nxt;
} else if (watering_type == w_types::by_moisture) {
moisture_to_watering = nxt;
}
}
bool State::isSettings() {
return context_id == contexts::settings_ctx;
}
int State::getContext() {
return context_id;
}
bool State::isAutoState() {
return state_id == AUTO_STATE_ID;
}
bool State::isManualState() {
return state_id == MANUAL_STATE_ID;
}