| ... | ... |
@@ -16,7 +16,12 @@ |
| 16 | 16 |
6. wait back to 3 |
| 17 | 17 |
|
| 18 | 18 |
*/ |
| 19 |
-#include <heltec.h> |
|
| 19 |
+ |
|
| 20 |
+//Uncomment the board you are using |
|
| 21 |
+// heltec.h : Wemos TTGO LoRa, Heltech LoRa |
|
| 22 |
+// M5Stick.h : Orange M5 Stick |
|
| 23 |
+//#include <heltec.h> |
|
| 24 |
+#include <M5StickC.h> |
|
| 20 | 25 |
#include "sys/time.h" |
| 21 | 26 |
|
| 22 | 27 |
#include "BLEDevice.h" |
| ... | ... |
@@ -33,10 +38,6 @@ |
| 33 | 38 |
|
| 34 | 39 |
BLEAdvertising *pAdvertising; |
| 35 | 40 |
|
| 36 |
- |
|
| 37 |
-//----------------------------------------------------------------------------------- |
|
| 38 |
- |
|
| 39 |
- |
|
| 40 | 41 |
void setBeacon() {
|
| 41 | 42 |
BLEBeacon oBeacon = BLEBeacon(); |
| 42 | 43 |
oBeacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!) |
| ... | ... |
@@ -82,6 +83,16 @@ void setup() {
|
| 82 | 83 |
Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial Enable*/, false /*LoRa use PABOOST*/, 0 /*LoRa RF working band*/); |
| 83 | 84 |
Heltec.display->clear(); |
| 84 | 85 |
#endif //_HELTEC_H_ |
| 86 |
+ #ifdef _M5STICKC_H_ |
|
| 87 |
+ M5.begin(); |
|
| 88 |
+ M5.Lcd.setRotation(3); |
|
| 89 |
+ double BatteryOrUSB = M5.Axp.GetIusbinData() * 0.375; |
|
| 90 |
+ backlight_level=15; |
|
| 91 |
+ if(0 == BatteryOrUSB) {
|
|
| 92 |
+ backlight_level=7;//Minimum backlight |
|
| 93 |
+ } |
|
| 94 |
+ M5.Axp.ScreenBreath(backlight_level); |
|
| 95 |
+ #endif //_M5STICKC_H_ |
|
| 85 | 96 |
Serial.begin(115200); |
| 86 | 97 |
EEPROM.begin(EEPROM_SIZE); |
| 87 | 98 |
|
| ... | ... |
@@ -153,7 +164,6 @@ void setup() {
|
| 153 | 164 |
} |
| 154 | 165 |
|
| 155 | 166 |
void loop() {
|
| 156 |
- |
|
| 157 | 167 |
//PRG Button |
| 158 | 168 |
pollPrg(); |
| 159 | 169 |
|
| ... | ... |
@@ -5,9 +5,14 @@ |
| 5 | 5 |
#include "beacon.h" |
| 6 | 6 |
|
| 7 | 7 |
int buttonState = 0; // variable for reading the pushbutton status |
| 8 |
+#ifdef _HELTEC_H_ |
|
| 8 | 9 |
const int BUTTON_PRG = 0; // PRG Button |
| 10 |
+#endif //_HELTEC_H_ |
|
| 11 |
+#ifdef _M5STICKC_H_ |
|
| 12 |
+const int BUTTON_PRG = M5_BUTTON_HOME; // Home Button |
|
| 13 |
+#endif //_M5STICKC_H_ |
|
| 9 | 14 |
const int ledPin = 13; // the number of the LED pin |
| 10 |
- |
|
| 15 |
+ |
|
| 11 | 16 |
void pollPrg() |
| 12 | 17 |
{
|
| 13 | 18 |
buttonState = digitalRead(BUTTON_PRG); |
| ... | ... |
@@ -16,34 +21,54 @@ void pollPrg() |
| 16 | 21 |
switch( beacon_type ) {
|
| 17 | 22 |
case EN_BEACON_TYPE_entry: |
| 18 | 23 |
beacon_type = EN_BEACON_TYPE_hazard; |
| 19 |
- beaconTypeStr="Hazard "; |
|
| 24 |
+ beaconTypeStr="Hazard "; |
|
| 20 | 25 |
break; |
| 21 | 26 |
case EN_BEACON_TYPE_hazard: |
| 22 | 27 |
beacon_type = EN_BEACON_TYPE_safe; |
| 23 |
- beaconTypeStr="Safe "; |
|
| 28 |
+ beaconTypeStr="Safe "; |
|
| 24 | 29 |
break; |
| 25 | 30 |
case EN_BEACON_TYPE_safe: |
| 26 | 31 |
beacon_type = EN_BEACON_TYPE_exit; |
| 27 |
- beaconTypeStr="Exit "; |
|
| 32 |
+ beaconTypeStr="Exit "; |
|
| 28 | 33 |
break; |
| 29 | 34 |
case EN_BEACON_TYPE_exit: |
| 30 | 35 |
beacon_type = EN_BEACON_TYPE_other; |
| 31 |
- beaconTypeStr="Other "; |
|
| 36 |
+ beaconTypeStr="Other "; |
|
| 32 | 37 |
break; |
| 33 | 38 |
case EN_BEACON_TYPE_other: |
| 34 | 39 |
beacon_type = EN_BEACON_TYPE_entry; |
| 35 |
- beaconTypeStr="Entry "; |
|
| 40 |
+ beaconTypeStr="Entry "; |
|
| 36 | 41 |
break; |
| 37 | 42 |
default: |
| 38 | 43 |
beacon_type = EN_BEACON_TYPE_safe; |
| 39 |
- beaconTypeStr="Safe "; |
|
| 44 |
+ beaconTypeStr="Safe "; |
|
| 40 | 45 |
break; |
| 41 | 46 |
} |
| 42 | 47 |
Serial.println("Switching to "+beaconTypeStr);
|
| 48 |
+ #ifdef _M5STICKC_H_ |
|
| 49 |
+ M5.Lcd.fillRect(0, LINE2, 160, 10, BLACK); |
|
| 50 |
+ M5.Lcd.fillRect(0, LINE4, 160, 10, BLACK); |
|
| 51 |
+ #endif //_M5STICKC_H_ |
|
| 43 | 52 |
EEPROM.write(0, beacon_type); |
| 44 | 53 |
EEPROM.commit(); |
| 45 | 54 |
} |
| 46 | 55 |
DisplayButtonStatus(); |
| 56 |
+ #ifdef _M5STICKC_H_ |
|
| 57 |
+ if(digitalRead(M5_BUTTON_RST) == LOW){
|
|
| 58 |
+ backlight_level++; |
|
| 59 |
+ if(backlight_level >= 16) |
|
| 60 |
+ backlight_level = 7; |
|
| 61 |
+ while(digitalRead(M5_BUTTON_RST) == LOW); |
|
| 62 |
+ Serial.println("loop::M5_BUTTON_RST");
|
|
| 63 |
+ double BatteryOrUSB = M5.Axp.GetIusbinData() * 0.375; |
|
| 64 |
+ if(0 != BatteryOrUSB) {
|
|
| 65 |
+ M5.Axp.ScreenBreath(backlight_level); |
|
| 66 |
+ }else{
|
|
| 67 |
+ backlight_level = 7; |
|
| 68 |
+ M5.Axp.ScreenBreath(backlight_level); |
|
| 69 |
+ } |
|
| 70 |
+ } |
|
| 71 |
+ #endif //_M5STICKC_H_ |
|
| 47 | 72 |
} |
| 48 | 73 |
|
| 49 | 74 |
#endif //_BUTTON_H |
| ... | ... |
@@ -9,7 +9,19 @@ |
| 9 | 9 |
#define LINE3 24 |
| 10 | 10 |
#define LINE4 36 |
| 11 | 11 |
#define LINE5 48 |
| 12 |
-#define LINEBOTTOM 54 |
|
| 12 |
+#ifndef _M5STICKC_H_ |
|
| 13 |
+ #define LINEBOTTOM 54 |
|
| 14 |
+#else |
|
| 15 |
+ #define LINE6 60 //M5Only |
|
| 16 |
+ #define LINEBOTTOM 72 |
|
| 17 |
+#endif //_M5STICKC_H_ |
|
| 18 |
+ |
|
| 19 |
+//----------------------------------------------------------------------------------- |
|
| 20 |
+#ifdef _M5STICKC_H_ |
|
| 21 |
+uint8_t backlight_level = 15; //15 High Luminosity, 7 lowest luminosity |
|
| 22 |
+#endif //_M5STICKC_H_ |
|
| 23 |
+//----------------------------------------------------------------------------------- |
|
| 24 |
+ |
|
| 13 | 25 |
|
| 14 | 26 |
// Display String Variables for updating all screen at once |
| 15 | 27 |
//--------------------------------------------------------------------- |
| ... | ... |
@@ -32,5 +44,18 @@ void DisplayButtonStatus() {
|
| 32 | 44 |
} |
| 33 | 45 |
Heltec.display->display(); |
| 34 | 46 |
#endif //_HELTEC_H_ |
| 47 |
+ #ifdef _M5STICKC_H_ |
|
| 48 |
+ //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));
|
|
| 51 |
+ 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"; |
|
| 54 |
+ if( 1 == ad_running ) {
|
|
| 55 |
+ M5.Lcd.setCursor(150, LINEBOTTOM, 1);M5.Lcd.setTextColor(WHITE, GREEN); M5.Lcd.println(String("X"));
|
|
| 56 |
+ } else {
|
|
| 57 |
+ M5.Lcd.fillRect(150, LINEBOTTOM, 10, 10, BLACK); |
|
| 58 |
+ } |
|
| 59 |
+ #endif //_M5STICKC_H_ |
|
| 35 | 60 |
} |
| 36 | 61 |
#endif //_DISPLAY_H |