Sends infinity hotkey combinations (Current: LCTRL + RALT + NUM) Cycles numbers 0 to 9 with gaps of 10 seconds.

Dependencies:   mbed C12832 USBDevice

Dependents:   mbed_alif4000_hotkeys_3chan_001

Revision:
4:6bf4cdb7b834
Parent:
3:e2f13978838c
Child:
5:fc7f3f5f4c2d
--- a/main.cpp	Mon Feb 26 11:31:13 2018 +0000
+++ b/main.cpp	Mon Jun 03 14:38:07 2019 +0000
@@ -1,5 +1,5 @@
 /****************************************************************************
-- Following program is to emulate Inifinity channel switching.
+- Following program is to emulate Infinity channel switching.
 - embeds are used to send hotkey combination to switch channel. 
 - CTRL+SHIFT+[1-4] is used to switch among four channels.
 - LCD screen on mbed application board is used to show switch status and count.
@@ -22,8 +22,12 @@
 // LCD interface on appication board
 C12832 lcd(p5, p7, p6, p8, p11);
 
-const float speed = 5;
+// Switching period: 'every <speed> seconds'
+const float speed = 10.0;
 const int hotkeys = KEY_CTRL | KEY_SHIFT;
+const int maxChannels = 3;
+const int maxChSw = 60;
+const int remainMinutesMax = 50;
 
 void lcd_print(int key, int count, float speed) {
     lcd.cls();
@@ -31,10 +35,16 @@
     lcd.printf("Sending CTRL+SHIFT+%c \nCount: %d\nSpeed: %4.2f\n", key, count, speed);
 }
 
+void lcd_print2(int rMinutes, int rMinutesMax) {
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Idle time:\n>>> %d/%d minutes\n", rMinutes, rMinutesMax);
+}
+
 // Start programm
 int main(void) {
     int key_base;
-    int count = 1;
+    int count = 1; // Cumulative channel switching count
     char key_modifier;
     
     //Disconnect any existing connections
@@ -42,19 +52,38 @@
     lcd.locate(0,0);
     lcd.printf("Starting Up..\nAllowing USB to settle\n>>Please Wait<< ");
     wait(10);
-    
+ 
+    // Loop forever:
+    // (1) Channel switch continuously for maxChSw in first part of hour.
+    // (2) Idle (no channel switching for remainder of hour.   
     while(1) {
-        key_base = 1;
-        while(key_base <= 6) {
-            lcd.cls();
-            leds = ~key_base;
-            myleds = key_base;
-            key_modifier = '0'+key_base;
-            keyboard.keyCode(key_modifier, hotkeys);
-            lcd_print(key_modifier, count, speed);
-            wait(speed);
-            key_base++;
-            count++;          
+        
+        int chswTotal = 1;
+        
+        // (1) Channel switch continuously.        
+        while(chswTotal <= maxChSw) {
+            key_base = 1;
+            while(key_base <= maxChannels) {
+                lcd.cls();
+                leds = ~key_base;
+                myleds = key_base;
+                key_modifier = '0'+key_base;
+                keyboard.keyCode(key_modifier, hotkeys);
+                lcd_print(key_modifier, count, speed);
+                wait(speed);
+                key_base++;
+                count++;
+                chswTotal++;          
+            }
         }
+        
+        // (2) Idle for remainder of hour, counting up
+        // every 1 minute.
+        int remainMin = 1;
+        while(remainMin <= remainMinutesMax) {
+            lcd_print2(remainMin, remainMinutesMax);
+            wait(60.0);
+            remainMin++;
+        }                      
     }
 }