-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_proto.ino
160 lines (123 loc) · 3.19 KB
/
test_proto.ino
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "board_wiring.h"
#include "adc.h"
#include "oled.h"
#define DISPLAY_MODE_AVG 0
#define DISPLAY_MODE_MAX 1
#define DISPLAY_MODE_AVG_RAW 2
#define DISPLAY_MODE_MAX_RAW 3
#define DISPLAY_MODE_CALIBRATION 4
#define DISPLAY_MODE_COUNT 5
char display_mode = DISPLAY_MODE_AVG_RAW;
void pinSetup() {
digitalWrite(PIN_TADrv, HIGH);
digitalWrite(PIN_TBDrv, HIGH);
digitalWrite(PIN_TCDrv, HIGH);
pinMode(PIN_TADrv, INPUT);
pinMode(PIN_TBDrv, INPUT);
pinMode(PIN_TCDrv, INPUT);
pinMode(PIN_TA1, INPUT);
digitalWrite(PIN_TA1, LOW);
pinMode(PIN_TB1, INPUT);
digitalWrite(PIN_TB1, LOW);
pinMode(PIN_TC1, INPUT);
digitalWrite(PIN_TC1, LOW);
}
void setup() {
//Serial.begin(9600);
Serial.println("initDisplay");
initDisplay();
// setup buttons
pinMode(BUTTON_A, INPUT_PULLUP);
pinMode(BUTTON_B, INPUT_PULLUP);
pinMode(BUTTON_C, INPUT_PULLUP);
Serial.println("IO test");
analogSetup();
pinSetup();
calibrateLevels();
display_current_mode();
}
void draw_all_samples(Sample *r) {
// double height.
display.setTextSize(1,2);
// erase as we write text
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
//display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.printf("A %4d B %4d C %4d\n", r->sAA1, r->sBB1, r->sCC1);
display.printf("AB%4d AC %4d BC%4d\n", r->sAB, r->sAC, r->sBC);
display.display();
}
bool msg_active = false;
unsigned long msg_until = 0;
void display_msg(const char *s) {
draw_msg(s);
}
void draw_msg(const char *s) {
display.clearDisplay();
display.setTextSize(2,2);
// erase as we write text
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
//display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(s);
display.display();
delay(400);
}
extern int32_t calib_floor;
extern int32_t calib_10_delta;
void draw_calibration() {
// double height.
display.setTextSize(1,2);
// erase as we write text
display.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
//display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.printf("Floor. : %4d \n", calib_floor);
display.printf("delta 10: %4d \n", calib_10_delta);
display.display();
}
void change_mode() {
display_mode = (display_mode + 1) % DISPLAY_MODE_COUNT;
display_current_mode();
}
void display_current_mode() {
char s[30];
sprintf(s, "Mode: %d", display_mode);
display_msg(s);
}
void loop() {
// buttons are pulled high, go low for click
if (!digitalRead(BUTTON_A)) {
display_msg("button A");
}
if (!digitalRead(BUTTON_B)) {
external_calibration();
display_msg("Update sample");
}
if (!digitalRead(BUTTON_C)) {
change_mode();
}
//Serial.println("loop()");
take_sample();
switch(display_mode) {
case DISPLAY_MODE_AVG:
draw_all_samples(&resistance_avg);
break;
case DISPLAY_MODE_MAX:
draw_all_samples(&resistance_max);
break;
case DISPLAY_MODE_AVG_RAW:
draw_all_samples(&adc_avg);
break;
case DISPLAY_MODE_MAX_RAW:
draw_all_samples(&adc_max);
break;
case DISPLAY_MODE_CALIBRATION:
draw_calibration();
break;
}
}