Dependencies:   mbed C12832 MMA7660 USBDevice

Committer:
wojt86
Date:
Sun Oct 27 12:19:15 2019 +0000
Revision:
21:53426ae5b7b1
Parent:
10:150f8d03f18d
Child:
22:f7e4b453f684
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 1:291a88a2c151 1 #include "mbed.h"
samux 1:291a88a2c151 2 #include "USBKeyboard.h"
knasp 7:ffe2220d3880 3 #include "MMA7660.h"
knasp 10:150f8d03f18d 4 #include "C12832.h"
knasp 9:66681432403a 5
wojt86 21:53426ae5b7b1 6 #include "stdint.h"
wojt86 21:53426ae5b7b1 7 #define REPORT_ID_KEYBOARD 1
wojt86 21:53426ae5b7b1 8 #define REPORT_ID_VOLUME 3
knasp 9:66681432403a 9
knasp 9:66681432403a 10
wojt86 21:53426ae5b7b1 11 typedef struct {
wojt86 21:53426ae5b7b1 12 unsigned char usage;
wojt86 21:53426ae5b7b1 13 unsigned char modifier;
wojt86 21:53426ae5b7b1 14 } KEYMAP;
knasp 10:150f8d03f18d 15
wojt86 21:53426ae5b7b1 16 #ifdef US_KEYBOARD
wojt86 21:53426ae5b7b1 17 /* US keyboard (as HID standard) */
wojt86 21:53426ae5b7b1 18 #define KEYMAP_SIZE (152)
wojt86 21:53426ae5b7b1 19 const KEYMAP keymap[KEYMAP_SIZE] = {
wojt86 21:53426ae5b7b1 20
wojt86 21:53426ae5b7b1 21 {0x28, 0}, /* LF */ /* Keyboard Return (Enter) */
wojt86 21:53426ae5b7b1 22
wojt86 21:53426ae5b7b1 23 };
wojt86 21:53426ae5b7b1 24 #endif
knasp 9:66681432403a 25
knasp 9:66681432403a 26
wojt86 21:53426ae5b7b1 27 MMA7660 Accelerometer (p28,p27); //define accelerometer
wojt86 21:53426ae5b7b1 28 USBKeyboard Usbkeyboard; //define keyboard
wojt86 21:53426ae5b7b1 29 C12832 LCD (p5,p7,p6,p8,p11); //define LCD
wojt86 21:53426ae5b7b1 30
wojt86 21:53426ae5b7b1 31 DigitalOut led1(p12); //leds
wojt86 21:53426ae5b7b1 32 DigitalOut led2(p13);
wojt86 21:53426ae5b7b1 33 DigitalOut led3(p14);
wojt86 21:53426ae5b7b1 34 DigitalOut led4(p15);
knasp 10:150f8d03f18d 35
wojt86 21:53426ae5b7b1 36 DigitalIn Switch1 (p8); //switch mode 1 (arrows) and 2 (letters)
wojt86 21:53426ae5b7b1 37 DigitalIn Switch2 (p16); //switch to numbers
wojt86 21:53426ae5b7b1 38 DigitalIn Switch3 (p15); //enter
wojt86 21:53426ae5b7b1 39 DigitalIn Switch4 (p14); //spacebar
wojt86 21:53426ae5b7b1 40
wojt86 21:53426ae5b7b1 41 int main (void) //main program
wojt86 21:53426ae5b7b1 42 {
wojt86 21:53426ae5b7b1 43 //enum Orientation {Up, Down,Right, Left,Back, Front,Unknown};
wojt86 21:53426ae5b7b1 44 MMA7660::Orientation myOrientation; //defining orientation
knasp 10:150f8d03f18d 45
wojt86 21:53426ae5b7b1 46 while (true) {
wojt86 21:53426ae5b7b1 47
wojt86 21:53426ae5b7b1 48
wojt86 21:53426ae5b7b1 49 myOrientation = Accelerometer.getOrientation (); //getting the orientation from accelerometer
wojt86 21:53426ae5b7b1 50
wojt86 21:53426ae5b7b1 51
wojt86 21:53426ae5b7b1 52 if (Switch4){
wojt86 21:53426ae5b7b1 53
wojt86 21:53426ae5b7b1 54 Usbkeyboard.printf (" "); //spacebar
wojt86 21:53426ae5b7b1 55
wojt86 21:53426ae5b7b1 56 }
wojt86 21:53426ae5b7b1 57
wojt86 21:53426ae5b7b1 58 if (Switch3){
wojt86 21:53426ae5b7b1 59
wojt86 21:53426ae5b7b1 60 Usbkeyboard.keyCode(0x28, 0); //enter will be HERE
wojt86 21:53426ae5b7b1 61
wojt86 21:53426ae5b7b1 62 }
wojt86 21:53426ae5b7b1 63
wojt86 21:53426ae5b7b1 64 if (Switch1){ //if the switch is on
wojt86 21:53426ae5b7b1 65
wojt86 21:53426ae5b7b1 66 if (myOrientation == MMA7660::Up){ //if the orientation is up
wojt86 21:53426ae5b7b1 67
wojt86 21:53426ae5b7b1 68 LCD.printf("Left"); //print "left" on LCD (due to orientation of the accelerometer on the limb, the directions are changed)
wojt86 21:53426ae5b7b1 69 Usbkeyboard.keyCode (LEFT_ARROW); //device simulates pressing "left arrow key" on the keyboard
wojt86 21:53426ae5b7b1 70 led2=0; //led off
wojt86 21:53426ae5b7b1 71 led1=0; //led off
wojt86 21:53426ae5b7b1 72 led3=0; //led off
wojt86 21:53426ae5b7b1 73 led4=1; //led on
wojt86 21:53426ae5b7b1 74 }
wojt86 21:53426ae5b7b1 75 else if (myOrientation == MMA7660::Down){
wojt86 21:53426ae5b7b1 76
wojt86 21:53426ae5b7b1 77 LCD.printf("Right");
wojt86 21:53426ae5b7b1 78 Usbkeyboard.keyCode (RIGHT_ARROW);
wojt86 21:53426ae5b7b1 79 led3=0;
wojt86 21:53426ae5b7b1 80 led1=0;
wojt86 21:53426ae5b7b1 81 led2=1;
wojt86 21:53426ae5b7b1 82 led4=0;
wojt86 21:53426ae5b7b1 83 }
wojt86 21:53426ae5b7b1 84 else if (myOrientation == MMA7660::Left){
wojt86 21:53426ae5b7b1 85
wojt86 21:53426ae5b7b1 86 LCD.printf("UP");
wojt86 21:53426ae5b7b1 87 Usbkeyboard.keyCode (UP_ARROW);
wojt86 21:53426ae5b7b1 88 led1=1;
wojt86 21:53426ae5b7b1 89 led3=0;
wojt86 21:53426ae5b7b1 90 led2=0;
wojt86 21:53426ae5b7b1 91 led4=0;
wojt86 21:53426ae5b7b1 92 }
wojt86 21:53426ae5b7b1 93 else if (myOrientation == MMA7660::Right){
wojt86 21:53426ae5b7b1 94
wojt86 21:53426ae5b7b1 95 LCD.printf("DOWN");
wojt86 21:53426ae5b7b1 96 Usbkeyboard.keyCode (DOWN_ARROW);
wojt86 21:53426ae5b7b1 97 led4=0;
wojt86 21:53426ae5b7b1 98 led1=0;
wojt86 21:53426ae5b7b1 99 led3=1;
wojt86 21:53426ae5b7b1 100 led2=0;
wojt86 21:53426ae5b7b1 101
wojt86 21:53426ae5b7b1 102
wojt86 21:53426ae5b7b1 103 }
wojt86 21:53426ae5b7b1 104 else if (myOrientation == MMA7660::Unknown){
wojt86 21:53426ae5b7b1 105
wojt86 21:53426ae5b7b1 106 LCD.printf("Don't Know");
wojt86 21:53426ae5b7b1 107
wojt86 21:53426ae5b7b1 108 }
wojt86 21:53426ae5b7b1 109 }
wojt86 21:53426ae5b7b1 110
wojt86 21:53426ae5b7b1 111 else { //if the switch is off than
wojt86 21:53426ae5b7b1 112
wojt86 21:53426ae5b7b1 113 if (myOrientation == MMA7660::Up){
wojt86 21:53426ae5b7b1 114
wojt86 21:53426ae5b7b1 115 LCD.printf("LEFT");
wojt86 21:53426ae5b7b1 116 Usbkeyboard.printf ("a\0"); //instead of simulating pressing of the "left arrow", simulates pressing "a key"
wojt86 21:53426ae5b7b1 117 led2=0;
wojt86 21:53426ae5b7b1 118 led1=0;
wojt86 21:53426ae5b7b1 119 led3=0;
wojt86 21:53426ae5b7b1 120 led4=1;
wojt86 21:53426ae5b7b1 121 }
wojt86 21:53426ae5b7b1 122 else if (myOrientation == MMA7660::Down){
wojt86 21:53426ae5b7b1 123
wojt86 21:53426ae5b7b1 124 LCD.printf("right");
wojt86 21:53426ae5b7b1 125 Usbkeyboard.printf ("d\0");
wojt86 21:53426ae5b7b1 126 led3=0;
wojt86 21:53426ae5b7b1 127 led1=0;
wojt86 21:53426ae5b7b1 128 led2=1;
wojt86 21:53426ae5b7b1 129 led4=0;
wojt86 21:53426ae5b7b1 130 }
wojt86 21:53426ae5b7b1 131 else if (myOrientation == MMA7660::Left){
wojt86 21:53426ae5b7b1 132
wojt86 21:53426ae5b7b1 133 LCD.printf("Up");
wojt86 21:53426ae5b7b1 134 Usbkeyboard.printf ("w\0");
wojt86 21:53426ae5b7b1 135 led1=1;
wojt86 21:53426ae5b7b1 136 led3=0;
wojt86 21:53426ae5b7b1 137 led2=0;
wojt86 21:53426ae5b7b1 138 led4=0;
wojt86 21:53426ae5b7b1 139 }
wojt86 21:53426ae5b7b1 140 else if (myOrientation == MMA7660::Right){
wojt86 21:53426ae5b7b1 141
wojt86 21:53426ae5b7b1 142 LCD.printf("Down");
wojt86 21:53426ae5b7b1 143 Usbkeyboard.printf ("s\0");
wojt86 21:53426ae5b7b1 144 led4=0;
wojt86 21:53426ae5b7b1 145 led1=0;
wojt86 21:53426ae5b7b1 146 led3=1;
wojt86 21:53426ae5b7b1 147 led2=0;
wojt86 21:53426ae5b7b1 148
wojt86 21:53426ae5b7b1 149
wojt86 21:53426ae5b7b1 150
wojt86 21:53426ae5b7b1 151 }
wojt86 21:53426ae5b7b1 152 else if (myOrientation == MMA7660::Unknown){
wojt86 21:53426ae5b7b1 153
wojt86 21:53426ae5b7b1 154 LCD.printf("Don't Know");
wojt86 21:53426ae5b7b1 155
wojt86 21:53426ae5b7b1 156 }
wojt86 21:53426ae5b7b1 157
wojt86 21:53426ae5b7b1 158 }
wojt86 21:53426ae5b7b1 159
knasp 10:150f8d03f18d 160
wojt86 21:53426ae5b7b1 161 }
wojt86 21:53426ae5b7b1 162 return false;
wojt86 21:53426ae5b7b1 163 }
wojt86 21:53426ae5b7b1 164