Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma systemFile
00036
00037 #ifndef __MSHID_H__
00038 #define __MSHID_H__
00039
00040 #ifndef __COMMON_H__
00041 #include "common.h"
00042 #endif
00043
00044 #define MSHID_I2C_ADDR 0x04
00045 #define MSHID_CMD 0x41
00046 #define MSHID_KEYBMOD 0x42
00047 #define MSHID_KEYBDATA 0x43
00048
00049 #define MSHID_XMIT 0x54
00050 #define MSHID_ASCII 0x41
00051 #define MSHID_DDATA 0x44
00052
00053
00054 #define MSHID_MOD_NONE 0x00
00055 #define MSHID_MOD_LCTRL 0x01
00056 #define MSHID_MOD_LSHIFT 0x02
00057 #define MSHID_MOD_LALT 0x04
00058 #define MSHID_MOD_LGUI 0x08
00059 #define MSHID_MOD_RCTRL 0x10
00060 #define MSHID_MOD_RSHIFT 0x20
00061 #define MSHID_MOD_RALT 0x40
00062 #define MSHID_MOD_RGUI 0x80
00063
00064 bool MSHIDsendCommand(tSensors link, byte command, ubyte address = MSHID_I2C_ADDR);
00065 bool MSHIDsendKeyboardData(tSensors link, byte modifier, byte keybdata, ubyte address = MSHID_I2C_ADDR);
00066 bool MSHIDsendString(tSensors link, string data, ubyte address = MSHID_I2C_ADDR);
00067
00068 tByteArray MSHID_I2CRequest;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 bool MSHIDsendCommand(tSensors link, byte command, ubyte address) {
00079 memset(MSHID_I2CRequest, 0, sizeof(tByteArray));
00080 MSHID_I2CRequest[0] = 3;
00081 MSHID_I2CRequest[1] = address;
00082 MSHID_I2CRequest[2] = MSHID_CMD;
00083 MSHID_I2CRequest[3] = command;
00084
00085 return writeI2C(link, MSHID_I2CRequest);
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 bool MSHIDsendKeyboardData(tSensors link, byte modifier, byte keybdata, ubyte address) {
00099 memset(MSHID_I2CRequest, 0, sizeof(tByteArray));
00100 MSHID_I2CRequest[0] = 4;
00101 MSHID_I2CRequest[1] = address;
00102 MSHID_I2CRequest[2] = MSHID_KEYBMOD;
00103 MSHID_I2CRequest[3] = modifier;
00104 MSHID_I2CRequest[4] = keybdata;
00105
00106 return writeI2C(link, MSHID_I2CRequest);
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 bool MSHIDsendString(tSensors link, string data, ubyte address) {
00124 byte buffer[19];
00125 int len = strlen(data);
00126 if (len < 20) {
00127 memcpy(buffer, data, len);
00128 } else {
00129 return false;
00130 }
00131
00132 for (int i = 0; i < len; i++) {
00133 if (buffer[i] == 0x5C && i < (len - 1)) {
00134 switch (buffer[i+1]) {
00135 case 'r':
00136 if (!MSHIDsendKeyboardData(link, MSHID_MOD_NONE, 0x0A))
00137 return false;
00138 break;
00139 case 'n':
00140 if (!MSHIDsendKeyboardData(link, MSHID_MOD_NONE, 0x0D))
00141 return false;
00142 break;
00143 case 't':
00144 if (!MSHIDsendKeyboardData(link, MSHID_MOD_NONE, 0x09))
00145 return false;
00146 break;
00147 case 0x5C:
00148 if (!MSHIDsendKeyboardData(link, MSHID_MOD_NONE, 0x5C))
00149 return false;
00150 break;
00151 case 0x22:
00152 if (!MSHIDsendKeyboardData(link, MSHID_MOD_NONE, 0x22))
00153 return false;
00154 break;
00155 default:
00156 break;
00157 }
00158 i++;
00159 } else {
00160 if (!MSHIDsendKeyboardData(link, MSHID_MOD_NONE, buffer[i]))
00161 return false;
00162 }
00163 if (!MSHIDsendCommand(link, MSHID_XMIT))
00164 return false;
00165 wait1Msec(50);
00166 }
00167 return true;
00168 }
00169
00170 #endif // __MSHID_H__
00171
00172
00173
00174
00175
00176