1
- #include < M5Stack .h>
1
+ #include < ESP32-Chimera-Core .h>
2
2
#include " Free_Fonts.h"
3
3
#include " Seeed_BMP280.h"
4
4
#include < Wire.h>
@@ -11,7 +11,7 @@ BLECharacteristic *pCharacteristic;
11
11
bool deviceConnected = false ;
12
12
BMP280 bmp280;
13
13
double t0, t1;
14
- float seaLevel = 1010.4 ;
14
+ float seaLevel = 1013.3 ;
15
15
float readAltitude (float SL, float pressure) {
16
16
float atmospheric = pressure / 100 .0F ;
17
17
return 44330.0 * (1.0 - pow (atmospheric / SL, 0.1903 ));
@@ -23,13 +23,14 @@ float readAltitude(float SL, float pressure) {
23
23
#define SERVICE_UUID " 6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
24
24
#define CHARACTERISTIC_UUID_RX " 6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
25
25
#define CHARACTERISTIC_UUID_TX " 6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
26
-
26
+ // TODO
27
+ // Add notif characteristic
28
+ // Add menu
27
29
28
30
class MyServerCallbacks : public BLEServerCallbacks {
29
31
void onConnect (BLEServer* pServer) {
30
32
deviceConnected = true ;
31
33
};
32
-
33
34
void onDisconnect (BLEServer* pServer) {
34
35
deviceConnected = false ;
35
36
}
@@ -57,21 +58,22 @@ class MyCallbacks: public BLECharacteristicCallbacks {
57
58
};
58
59
59
60
void buttons_test () {
60
- if (M5.BtnA .wasPressed ()) {
61
+ if (M5.BtnA .isPressed ()) {
61
62
Serial.printf (" -0.10 HPa" );
62
63
seaLevel -= 0.1 ;
63
64
displayBMP ();
65
+ delay (200 );
64
66
}
65
- if (M5.BtnB .wasPressed ()) {
67
+ if (M5.BtnB .isPressed ()) {
66
68
Serial.printf (" B" );
67
69
}
68
- if (M5.BtnC .wasPressed ()) {
70
+ if (M5.BtnC .isPressed ()) {
69
71
Serial.printf (" +0.10 HPa" );
70
72
seaLevel += 0.1 ;
71
73
displayBMP ();
74
+ delay (200 );
72
75
}
73
76
}
74
-
75
77
void setup () {
76
78
Serial.begin (115200 );
77
79
delay (1000 );
@@ -86,12 +88,10 @@ void setup() {
86
88
Serial.println (" Device error!" );
87
89
M5.Lcd .drawString (F (" Starting BMP280 failed!" ), 24 , 57 , GFXFF);
88
90
M5.Lcd .drawString (F (" Cannot do anything!" ), 24 , 82 , GFXFF);
89
- M5.Lcd .drawJpgFile (SD, " /XMark20.jpg" , 2 , 55 );
90
91
while (1 );
91
92
}
92
93
Serial.println (F (" BMP280 init succeeded." ));
93
94
M5.Lcd .drawString (F (" BMP280 init succeeded." ), 24 , 57 , GFXFF);
94
- M5.Lcd .drawJpgFile (SD, " /Check20.jpg" , 2 , 55 );
95
95
// Create the BLE Device
96
96
BLEDevice::init (" BMP Sea Level Service" );
97
97
// Create the BLE Server
@@ -114,6 +114,8 @@ void setup() {
114
114
115
115
void displayBMP () {
116
116
float pressure, temp, alt;
117
+ char txString[23 ];
118
+ String ret;
117
119
M5.Lcd .fillRect (0 , 100 , 320 , 137 , TFT_WHITE);
118
120
// get and print temperatures
119
121
Serial.print (" Temp: " );
@@ -123,15 +125,23 @@ void displayBMP() {
123
125
124
126
// get and print atmospheric pressure data
125
127
Serial.print (" Pressure: " );
126
- Serial.print (pressure = bmp280.getPressure ());
127
- Serial.println (" Pa" );
128
+ pressure = bmp280.getPressure ();
129
+ Serial.print (pressure / 100.0 );
130
+ Serial.println (" HPa" );
128
131
129
132
// get and print altitude data
130
133
Serial.print (" Altitude: " );
131
134
alt = readAltitude (seaLevel, pressure);
132
135
Serial.print (alt);
133
136
Serial.println (" m" );
134
137
Serial.println (" \n " );
138
+ ret = String (temp, 2 ) + " C @ " + String (alt, 2 ) + " m" ;
139
+ ret.toCharArray (txString, ret.length () + 1 );
140
+ pCharacteristic->setValue (txString);
141
+ pCharacteristic->notify (); // Send the value to the app!
142
+ Serial.print (" *** Sent Value: " );
143
+ Serial.print (txString);
144
+ Serial.println (" ***" );
135
145
136
146
uint8_t linePos = 110 ;
137
147
M5.Lcd .setFreeFont (FSSB9);
@@ -156,8 +166,9 @@ void displayBMP() {
156
166
157
167
void loop () {
158
168
t1 = millis () - t0;
159
- if (t1 > 4999 ) {
169
+ if (t1 > 9999 ) {
160
170
displayBMP ();
171
+ t0 = millis ();
161
172
}
162
173
buttons_test ();
163
174
M5.update (); // 好importantですね!
0 commit comments