北海道情報専門学校 ライフハック研究所のエンベデッドUSBチーム松葉和仁により開発されたUSBSecのmbedに使用するソースコード by 和仁

Dependencies:   SDFileSystem MusicEngine

Fork of mbed-os-example-ble-LED by mbed-os-examples

北海道情報専門学校 ライフハック研究所 エンベデッドUSB USBSec用mbedプログラム

松葉和仁

Revision:
32:c547412e77e3
Parent:
31:0568376f3399
Child:
33:26072cb714d9
--- a/source/main.cpp	Mon Feb 06 01:59:13 2017 +0000
+++ b/source/main.cpp	Tue Feb 07 05:08:08 2017 +0000
@@ -49,6 +49,7 @@
 //http://mag.switch-science.com/2015/06/17/fathersday2015/
 //http://www.geocities.co.jp/Playtown-Denei/9628/whatsmml.html
 int speakerMode = 0;//1:接続 2:切断 3:認証エラー 4:パスワードリセット 5:起動 6:USB有効 7:USB無効
+int lastSpeakerId = -1;
 
 //接続
 void connectAlertOff();
@@ -61,7 +62,13 @@
     DEBUG("connectAlertOn\r\n");
     Speaker.play("T160L4CDEFEDCB+");//カエルの歌
     //Speaker.play("T240L4CO4DO4EO4F");//再現
-    eventQueue.call_in(3000.0f, &connectAlertOff);
+    
+    //直前のスピーカーの省電力モード移行をキャンセルする
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(3000.0f, &connectAlertOff);
 }
 
 /**
@@ -97,7 +104,12 @@
 void disconnectAlertOn() {
     DEBUG("disconnectAlertOn\r\n");
     Speaker.play("T160L4CR4CR4CR4CR4");
-    eventQueue.call_in(3000.0f, &disconnectAlertOff);
+    
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(3000.0f, &disconnectAlertOff);
 }
 
 /**
@@ -133,7 +145,12 @@
 void authErrorAlertOn() {
     DEBUG("authErrorAlertOn\r\n");
     Speaker.play("T160L4CC");
-    eventQueue.call_in(1500.0f, &authErrorAlertOff);
+    
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(1500.0f, &authErrorAlertOff);
 }
 
 /**
@@ -169,7 +186,12 @@
 void passwordResetAlertOn() {
     DEBUG("passwordResetAlertOn\r\n");
     Speaker.play("T160L4CDCDEFEF");
-    eventQueue.call_in(3000.0f, &passwordResetAlertOff);
+    
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(3000.0f, &passwordResetAlertOff);
 }
 
 void passwordResetAlertOff() {
@@ -197,7 +219,12 @@
 void startupAlertOn() {
     DEBUG("startupAlertOn\r\n");
     Speaker.play("T160L4CDCDEFE");
-    eventQueue.call_in(3000.0f, &startupAlertOff);
+    
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(3000.0f, &startupAlertOff);
 }
 
 void startupAlertOff() {
@@ -225,7 +252,12 @@
 void enableUSBAlertOn(){
     DEBUG("enableUSBAlertOn\r\n");
     Speaker.play("T200L4CE");
-    eventQueue.call_in(3000.0f, &enableUSBAlertOff);
+    
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(3000.0f, &enableUSBAlertOff);
 }
 
 void enableUSBAlertOff() {
@@ -257,7 +289,12 @@
 void disableUSBAlertOn(){
     DEBUG("disableUSBAlertOn\r\n");
     Speaker.play("T200L4EC");
-    eventQueue.call_in(3000.0f, &disableUSBAlertOff);
+    
+    if(lastSpeakerId >=0){
+        eventQueue.cancel(lastSpeakerId);
+        DEBUG("キュー %d をキャンセルしました\r\n",lastSpeakerId);
+    }
+    lastSpeakerId=eventQueue.call_in(3000.0f, &disableUSBAlertOff);
 }
 
 void disableUSBAlertOff() {