... | ... |
@@ -36,6 +36,8 @@ |
36 | 36 |
#include <EEPROM.h> |
37 | 37 |
#define EEPROM_SIZE 1 // To save BeaconType upon restart |
38 | 38 |
|
39 |
+//#define DISABLE_BT //For Battery charging test |
|
40 |
+ |
|
39 | 41 |
BLEAdvertising *pAdvertising; |
40 | 42 |
|
41 | 43 |
void setBeacon() { |
... | ... |
@@ -86,10 +88,10 @@ void setup() { |
86 | 88 |
#ifdef _M5STICKC_H_ |
87 | 89 |
M5.begin(); |
88 | 90 |
M5.Lcd.setRotation(3); |
89 |
- double BatteryOrUSB = M5.Axp.GetIusbinData() * 0.375; |
|
90 |
- backlight_level=15; |
|
91 |
+ double BatteryOrUSB = M5.Axp.GetIusbinData(); |
|
92 |
+ backlight_level = DEFAULT_BACKLIGHT; |
|
91 | 93 |
if(0 == BatteryOrUSB) { |
92 |
- backlight_level=7;//Minimum backlight |
|
94 |
+ backlight_level = MIN_BACKLIGHT;//Minimum backlight |
|
93 | 95 |
} |
94 | 96 |
M5.Axp.ScreenBreath(backlight_level); |
95 | 97 |
#endif //_M5STICKC_H_ |
... | ... |
@@ -160,12 +162,17 @@ void setup() { |
160 | 162 |
} |
161 | 163 |
|
162 | 164 |
// Create the BLE Device |
165 |
+ #ifndef DISABLE_BT |
|
163 | 166 |
BLEDevice::init(BEACON_NAME); |
167 |
+ #endif //DISABLE_BT |
|
164 | 168 |
} |
165 | 169 |
|
166 | 170 |
void loop() { |
167 | 171 |
Serial.println("DeviceAddress: "+String(macStr)); |
168 | 172 |
|
173 |
+ beacon_count++; |
|
174 |
+ |
|
175 |
+ #ifndef DISABLE_BT |
|
169 | 176 |
// Create the BLE Server |
170 | 177 |
pAdvertising = BLEDevice::getAdvertising(); |
171 | 178 |
BLEDevice::startAdvertising(); |
... | ... |
@@ -173,7 +180,6 @@ void loop() { |
173 | 180 |
// Start advertising |
174 | 181 |
pAdvertising->addServiceUUID(BLEUUID(BEACON_SERVICE_UUID)); |
175 | 182 |
|
176 |
- beacon_count++; |
|
177 | 183 |
ad_running = 1; |
178 | 184 |
DisplayButtonStatus(); |
179 | 185 |
pAdvertising->start(); |
... | ... |
@@ -183,9 +189,16 @@ void loop() { |
183 | 189 |
ad_running = 0; |
184 | 190 |
DisplayButtonStatus(); |
185 | 191 |
Serial.println("Advertizing stopped."); |
192 |
+ #else |
|
193 |
+ DisplayButtonStatus(); |
|
194 |
+ #endif //DISABLE_BT |
|
186 | 195 |
|
187 | 196 |
//PRG Button |
188 | 197 |
pollPrg(); |
189 | 198 |
|
199 |
+ #ifndef DISABLE_BT |
|
190 | 200 |
delay(BEACON_SLEEP_ADV); |
201 |
+ #else |
|
202 |
+ delay(5*BEACON_SLEEP_ADV); |
|
203 |
+ #endif //DISABLE_BT |
|
191 | 204 |
} |
... | ... |
@@ -14,11 +14,21 @@ |
14 | 14 |
#else |
15 | 15 |
#define LINE6 60 //M5Only |
16 | 16 |
#define LINEBOTTOM 72 |
17 |
+ //Battery see : http://community.m5stack.com/topic/1361/ischarging-and-getbatterylevel/5 |
|
18 |
+ //#define VMAX 3500.0f // |
|
19 |
+ #define VMAX 3900.0f // Observed Maximum: 3943.5 after 7h charge |
|
20 |
+ #define VMIN 2973.0f // Observed Minimum: 2973.0 |
|
21 |
+ #define COLUMN_BAT 80 |
|
17 | 22 |
#endif //_M5STICKC_H_ |
18 | 23 |
|
19 | 24 |
//----------------------------------------------------------------------------------- |
20 | 25 |
#ifdef _M5STICKC_H_ |
21 |
-uint8_t backlight_level = 15; //15 High Luminosity, 7 lowest luminosity |
|
26 |
+//uint8_t backlight_level = 15; //15 High Luminosity, 7 lowest luminosity |
|
27 |
+#define MIN_BACKLIGHT 7 |
|
28 |
+#define MID_BACKLIGHT 11 |
|
29 |
+#define MAX_BACKLIGHT 15 |
|
30 |
+#define DEFAULT_BACKLIGHT MID_BACKLIGHT |
|
31 |
+uint8_t backlight_level = DEFAULT_BACKLIGHT; //15 High Luminosity, 7 lowest luminosity |
|
22 | 32 |
#endif //_M5STICKC_H_ |
23 | 33 |
//----------------------------------------------------------------------------------- |
24 | 34 |
|
... | ... |
@@ -30,11 +40,20 @@ char macStr[18] = ""; |
30 | 40 |
int ad_running = 0; |
31 | 41 |
uint32_t beacon_count = 0; |
32 | 42 |
|
43 |
+#ifdef _M5STICKC_H_ |
|
44 |
+float getBatteryLevel(void) |
|
45 |
+{ |
|
46 |
+ uint16_t vbatData = M5.Axp.GetVbatData(); |
|
47 |
+ float vbat = vbatData * 1.1; |
|
48 |
+ //return 100.0 * ((vbat - 3000) / (4070 - 3000)); |
|
49 |
+ return 100.0 * ((vbat - VMIN) / (VMAX - VMIN)); |
|
50 |
+} |
|
51 |
+#endif //_M5STICKC_H_ |
|
33 | 52 |
//--------------------------------------------------------------------- |
34 | 53 |
void DisplayButtonStatus() { |
35 | 54 |
#ifdef _HELTEC_H_ |
36 | 55 |
Heltec.display->clear(); |
37 |
- Heltec.display->drawString(0, LINE1, "MAC: "+String(macStr)); |
|
56 |
+ Heltec.display->drawString(0, LINE1, "BT: "+String(macStr)); |
|
38 | 57 |
Heltec.display->drawString(0, LINE2, "I : "+String(instanceStr)); |
39 | 58 |
Heltec.display->drawString(0, LINE4, beaconTypeStr); |
40 | 59 |
Heltec.display->drawString(0, LINEBOTTOM, "Cnt: "+String(beacon_count)); |
... | ... |
@@ -46,16 +65,30 @@ void DisplayButtonStatus() { |
46 | 65 |
#endif //_HELTEC_H_ |
47 | 66 |
#ifdef _M5STICKC_H_ |
48 | 67 |
//M5.Lcd.fillScreen(BLACK); |
49 |
- M5.Lcd.setCursor(0, LINE1, 1);M5.Lcd.setTextColor(WHITE, BLACK); M5.Lcd.println("MAC: "+String(macStr)); |
|
50 |
- M5.Lcd.setCursor(0, LINE2, 1);M5.Lcd.setTextColor(WHITE, BLACK); M5.Lcd.println("I : "+String(instanceStr)); |
|
68 |
+ M5.Lcd.setTextColor(0x7bef, BLACK); |
|
69 |
+ M5.Lcd.setCursor(0, LINE1, 1);M5.Lcd.println("BT: "+String(macStr)); |
|
70 |
+ M5.Lcd.setCursor(0, LINE2, 1);M5.Lcd.println("I : "+String(instanceStr)); |
|
51 | 71 |
M5.Lcd.setCursor(0, LINE4, 1);M5.Lcd.setTextColor(GREEN, BLACK); M5.Lcd.println(beaconTypeStr); |
52 |
- M5.Lcd.setCursor(0, LINE6, 1);M5.Lcd.setTextColor(BLUE, BLACK); M5.Lcd.println( "Cnt: "+String(beacon_count)); |
|
53 |
- String running="X"; |
|
72 |
+ M5.Lcd.setCursor(0, LINE6, 1);M5.Lcd.setTextColor(0x7bef, BLACK); M5.Lcd.println( "Cnt: "+String(beacon_count)); |
|
54 | 73 |
if( 1 == ad_running ) { |
55 | 74 |
M5.Lcd.setCursor(150, LINEBOTTOM, 1);M5.Lcd.setTextColor(WHITE, GREEN); M5.Lcd.println(String("X")); |
56 | 75 |
} else { |
57 |
- M5.Lcd.fillRect(150, LINEBOTTOM, 10, 10, BLACK); |
|
76 |
+ M5.Lcd.fillRect(150, LINEBOTTOM, 160, 10, BLACK); |
|
58 | 77 |
} |
78 |
+ float BatteryValue = M5.Axp.GetVbatData() * 1.1;// mV |
|
79 |
+ float BatteryPercent = 100*(BatteryValue-VMIN)/ (VMAX-VMIN); |
|
80 |
+ float BatteryLevel = getBatteryLevel(); |
|
81 |
+ if( BatteryPercent > 100 ) BatteryPercent = 100; |
|
82 |
+ M5.Lcd.setTextColor(0x7bef, BLACK); |
|
83 |
+ M5.Lcd.setCursor(0, LINEBOTTOM, 1); |
|
84 |
+ M5.Lcd.fillRect(0, LINEBOTTOM, 50, 10, BLACK); |
|
85 |
+ M5.Lcd.fillRect(COLUMN_BAT, LINEBOTTOM, 60, 10, BLACK); |
|
86 |
+ M5.Lcd.printf("%.1fmV",BatteryValue); |
|
87 |
+ if( BatteryPercent <= 80 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.0f%%",BatteryPercent); } |
|
88 |
+ else if( BatteryPercent > 80 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.1f%%",BatteryPercent); } |
|
89 |
+ else if( BatteryPercent > 90 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.2f%%",BatteryPercent); } |
|
90 |
+ else if( BatteryPercent > 95 ) { M5.Lcd.setCursor(COLUMN_BAT, LINEBOTTOM, 1);M5.Lcd.setTextColor(0x7bef, BLACK);M5.Lcd.printf("%.3f%%",BatteryPercent); } |
|
91 |
+ Serial.println(BatteryValue); |
|
59 | 92 |
#endif //_M5STICKC_H_ |
60 | 93 |
} |
61 | 94 |
#endif //_DISPLAY_H |