
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
main.cpp@5:fc7f3f5f4c2d, 2020-10-15 (annotated)
- Committer:
- jwingar
- Date:
- Thu Oct 15 13:55:37 2020 +0000
- Revision:
- 5:fc7f3f5f4c2d
- Parent:
- 4:6bf4cdb7b834
updated to not have an idle state
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shivikas | 0:f4e0c6f139ea | 1 | /**************************************************************************** |
stevehousley | 4:6bf4cdb7b834 | 2 | - Following program is to emulate Infinity channel switching. |
shivikas | 0:f4e0c6f139ea | 3 | - embeds are used to send hotkey combination to switch channel. |
shivikas | 0:f4e0c6f139ea | 4 | - CTRL+SHIFT+[1-4] is used to switch among four channels. |
shivikas | 0:f4e0c6f139ea | 5 | - LCD screen on mbed application board is used to show switch status and count. |
shivikas | 0:f4e0c6f139ea | 6 | |
shivikas | 0:f4e0c6f139ea | 7 | ****************************************************************************/ |
shivikas | 0:f4e0c6f139ea | 8 | |
jwingar | 5:fc7f3f5f4c2d | 9 | //imports |
shivikas | 0:f4e0c6f139ea | 10 | #include "mbed.h" |
shivikas | 0:f4e0c6f139ea | 11 | #include "C12832.h" |
shivikas | 0:f4e0c6f139ea | 12 | #include "USBKeyboard.h" |
shivikas | 0:f4e0c6f139ea | 13 | |
shivikas | 0:f4e0c6f139ea | 14 | // To change LED colour at channel switching |
shivikas | 0:f4e0c6f139ea | 15 | BusOut leds(p23, p24, p25); |
shivikas | 3:e2f13978838c | 16 | BusOut myleds(LED1, LED2, LED3, LED4); |
shivikas | 0:f4e0c6f139ea | 17 | |
shivikas | 0:f4e0c6f139ea | 18 | // keyboard interface to emulate keyboard and send keys with modifiers |
shivikas | 0:f4e0c6f139ea | 19 | USBKeyboard keyboard; |
shivikas | 0:f4e0c6f139ea | 20 | |
shivikas | 0:f4e0c6f139ea | 21 | // LCD interface on appication board |
shivikas | 0:f4e0c6f139ea | 22 | C12832 lcd(p5, p7, p6, p8, p11); |
shivikas | 0:f4e0c6f139ea | 23 | |
stevehousley | 4:6bf4cdb7b834 | 24 | // Switching period: 'every <speed> seconds' |
stevehousley | 4:6bf4cdb7b834 | 25 | const float speed = 10.0; |
jwingar | 5:fc7f3f5f4c2d | 26 | const int hotkeys = KEY_CTRL | KEY_RALT; |
jwingar | 5:fc7f3f5f4c2d | 27 | const int max_channel = 9; |
shivikas | 0:f4e0c6f139ea | 28 | |
jwingar | 5:fc7f3f5f4c2d | 29 | //print to lcd screen while channel switching |
jwingar | 5:fc7f3f5f4c2d | 30 | void lcd_print_switching(int key, int total, float speed, int sets) { |
shivikas | 0:f4e0c6f139ea | 31 | lcd.cls(); |
shivikas | 0:f4e0c6f139ea | 32 | lcd.locate(0,0); |
jwingar | 5:fc7f3f5f4c2d | 33 | lcd.printf("Sending CTRL+RALT+%c \nCount: %d, Sets: %d\nSpeed: %4.2f seconds\n", key, total, sets, speed); |
shivikas | 0:f4e0c6f139ea | 34 | } |
shivikas | 0:f4e0c6f139ea | 35 | |
jwingar | 5:fc7f3f5f4c2d | 36 | // Start programme |
shivikas | 0:f4e0c6f139ea | 37 | int main(void) { |
jwingar | 5:fc7f3f5f4c2d | 38 | |
jwingar | 5:fc7f3f5f4c2d | 39 | int key_base; // channel number |
jwingar | 5:fc7f3f5f4c2d | 40 | int count = 0; // Cumulative channel switching count |
jwingar | 5:fc7f3f5f4c2d | 41 | int sets = 0; // Cumulative channel switching sets |
jwingar | 5:fc7f3f5f4c2d | 42 | char key_modifier; |
shivikas | 0:f4e0c6f139ea | 43 | |
shivikas | 0:f4e0c6f139ea | 44 | //Disconnect any existing connections |
shivikas | 0:f4e0c6f139ea | 45 | lcd.cls(); |
shivikas | 0:f4e0c6f139ea | 46 | lcd.locate(0,0); |
shivikas | 0:f4e0c6f139ea | 47 | lcd.printf("Starting Up..\nAllowing USB to settle\n>>Please Wait<< "); |
shivikas | 0:f4e0c6f139ea | 48 | wait(10); |
stevehousley | 4:6bf4cdb7b834 | 49 | |
jwingar | 5:fc7f3f5f4c2d | 50 | // Loop forever |
shivikas | 0:f4e0c6f139ea | 51 | while(1) { |
stevehousley | 4:6bf4cdb7b834 | 52 | |
jwingar | 5:fc7f3f5f4c2d | 53 | key_base = 0; |
stevehousley | 4:6bf4cdb7b834 | 54 | |
jwingar | 5:fc7f3f5f4c2d | 55 | while(key_base <= max_channel) { |
jwingar | 5:fc7f3f5f4c2d | 56 | lcd.cls(); |
jwingar | 5:fc7f3f5f4c2d | 57 | leds = ~key_base; |
jwingar | 5:fc7f3f5f4c2d | 58 | myleds = key_base; |
jwingar | 5:fc7f3f5f4c2d | 59 | key_modifier = '0'+key_base; //turn to ascii value |
jwingar | 5:fc7f3f5f4c2d | 60 | keyboard.keyCode(key_modifier, hotkeys); |
jwingar | 5:fc7f3f5f4c2d | 61 | count++; |
jwingar | 5:fc7f3f5f4c2d | 62 | lcd_print_switching(key_modifier, count, speed, sets); |
jwingar | 5:fc7f3f5f4c2d | 63 | key_base++; |
jwingar | 5:fc7f3f5f4c2d | 64 | wait(speed); |
shivikas | 0:f4e0c6f139ea | 65 | } |
jwingar | 5:fc7f3f5f4c2d | 66 | sets++; |
shivikas | 0:f4e0c6f139ea | 67 | } |
shivikas | 0:f4e0c6f139ea | 68 | } |