-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock.h
77 lines (67 loc) · 1.42 KB
/
mock.h
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
// mock the system so the code can be tested on command-line
#include <stdio.h>
#define DHT22 1
#define HIGH 1
#define LOW 0
#define INPUT 0
#define OUTPUT 1
#define WDTO_4S 4
int mock_time = 0;
int mock_heater = 0;
int mock_fan = 0;
int mock_switch = 1;
class DHT {
public:
enum {
inside,
outside
} sensor;
double temp;
double hum;
DHT(int pin, int type) {
temp = 22;
hum = 60;
if (pin == 7)
sensor = inside;
else
sensor = outside;
}
float readHumidity() { mock_time += 250; return hum; }
float readTemperature() { return temp; }
void begin() {}
};
class LiquidCrystal_I2C {
public:
LiquidCrystal_I2C(int, int, int) {}
void init() {}
void home() {}
void backlight() {}
void print(const char* line) {
printf("LCD: %s\n", line);
}
void setCursor(int, int) {}
};
void delay(int time) { mock_time += time; }
void wdt_enable(int time) {}
void wdt_reset() {}
void digitalWrite(int pin, int on) {
if (pin == 3) {
mock_heater = on;
printf("time: %02d:%02d Heat: %s\n",
mock_time / 1000 / 60,
mock_time / 1000 % 60,
on ? "ON" : "OFF");
}
else if (pin == 4) {
mock_fan = on;
printf("time: %02d:%02d Fan: %s\n",
mock_time / 1000 / 60,
mock_time / 1000 % 60,
on ? "ON" : "OFF");
}
}
int digitalRead(int pin) {
/* power switch */
return mock_switch;
}
void pinMode(int pin, int mode) {}