Forked from ksasao/ContactTracingAppFinder.ino
Last active
September 3, 2020 14:58
-
-
Save haratta27/7118c98c1e20ddb28b949627a497ac17 to your computer and use it in GitHub Desktop.
周辺にあるコロナ接触確認デバイスの数をカウントします。M5stickC−PLUS 用です。Closeは自分のデバイスやかなり近くのデバイス数です。Nearは受信した数、Sumは合計数です。加速度センサにて画面向きが切り替わります。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <M5StickCPlus.h> | |
| #include <BLEDevice.h> | |
| // Contact Tracing Bluetooth Specification (Apple/Google) | |
| // https://blog.google/documents/58/Contact_Tracing_-_Bluetooth_Specification_v1.1_RYGZbKW.pdf | |
| const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb"; | |
| unsigned int near_count = 0; | |
| unsigned int close_count = 0; | |
| BLEScan* pBLEScan; | |
| class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { | |
| void onResult(BLEAdvertisedDevice advertisedDevice) { | |
| if(advertisedDevice.haveServiceUUID()){ | |
| if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){ | |
| int rssi = advertisedDevice.getRSSI(); | |
| if(rssi > -50){ | |
| close_count++; | |
| }else{ | |
| near_count++; | |
| } | |
| } | |
| } | |
| } | |
| }; | |
| unsigned int vbat_check(void){ | |
| uint16_t vbat = 0; | |
| vbat= M5.Axp.GetVbatData(); | |
| return ((unsigned int)(((float)vbat-3000)/1200*100)); | |
| } | |
| float accX = 0.0f; | |
| float accY = 0.0f; | |
| float accZ = 0.0f; | |
| void RotateDisplay(void){ | |
| M5.IMU.getAccelData(&accX,&accY,&accZ); | |
| if(accX < -0.8) M5.Lcd.setRotation(3); | |
| if(accX > +0.8) M5.Lcd.setRotation(1); | |
| } | |
| void setup() { | |
| M5.begin(); | |
| M5.IMU.Init(); | |
| M5.Lcd.setRotation(3); | |
| BLEDevice::init(""); | |
| pBLEScan = BLEDevice::getScan(); | |
| pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); | |
| pBLEScan->setActiveScan(true); | |
| } | |
| void loop(){ | |
| near_count = 0; | |
| close_count = 0; | |
| RotateDisplay(); | |
| pBLEScan->start(1, false); | |
| M5.Lcd.fillScreen(TFT_BLACK); | |
| M5.Lcd.setTextSize(2); | |
| M5.Lcd.setCursor(0,12); | |
| M5.Lcd.println(" COCOA Checker"); | |
| M5.Lcd.printf(" Close: %2d \r\n",close_count); | |
| M5.Lcd.printf(" Near : %2d \r\n",near_count); | |
| M5.Lcd.printf(" Sum : %2d \r\n",(close_count+near_count)); | |
| M5.Lcd.setCursor(80,110); | |
| M5.Lcd.printf("Battery: %2d%%", vbat_check()); | |
| M5.update(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment