Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SpaceBall.cpp@0:f67a8fffd94a, 2012-12-01 (annotated)
- Committer:
- jocis
- Date:
- Sat Dec 01 05:30:34 2012 +0000
- Revision:
- 0:f67a8fffd94a
- Child:
- 1:e6282b645d9b
.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jocis | 0:f67a8fffd94a | 1 | #include "SpaceBall.h" |
| jocis | 0:f67a8fffd94a | 2 | |
| jocis | 0:f67a8fffd94a | 3 | #define Sleep(x) wait_ms(x*10) |
| jocis | 0:f67a8fffd94a | 4 | |
| jocis | 0:f67a8fffd94a | 5 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 6 | |
| jocis | 0:f67a8fffd94a | 7 | SpaceBall::SpaceBall ( PinName tx, PinName rx, bool bSpaceOrb ) : _serial ( tx, rx ) |
| jocis | 0:f67a8fffd94a | 8 | { |
| jocis | 0:f67a8fffd94a | 9 | _bSpaceOrb = bSpaceOrb; |
| jocis | 0:f67a8fffd94a | 10 | _serial.baud ( 9600 ); |
| jocis | 0:f67a8fffd94a | 11 | |
| jocis | 0:f67a8fffd94a | 12 | _fScale = 1.0f; |
| jocis | 0:f67a8fffd94a | 13 | |
| jocis | 0:f67a8fffd94a | 14 | m_axis[0] = 0; /* last translational data received */ |
| jocis | 0:f67a8fffd94a | 15 | m_axis[1] = 0; |
| jocis | 0:f67a8fffd94a | 16 | m_axis[2] = 0; |
| jocis | 0:f67a8fffd94a | 17 | m_axis[3] = 0; /* last rotational data received */ |
| jocis | 0:f67a8fffd94a | 18 | m_axis[4] = 0; |
| jocis | 0:f67a8fffd94a | 19 | m_axis[5] = 0; |
| jocis | 0:f67a8fffd94a | 20 | m_buttons = 0; /* current button status */ |
| jocis | 0:f67a8fffd94a | 21 | |
| jocis | 0:f67a8fffd94a | 22 | m_buf[0] = 0; |
| jocis | 0:f67a8fffd94a | 23 | m_resetstring[0]= 0; |
| jocis | 0:f67a8fffd94a | 24 | m_bufpos = 0; /* current char position in packet buffer */ |
| jocis | 0:f67a8fffd94a | 25 | m_packtype = 0; /* what kind of packet is it */ |
| jocis | 0:f67a8fffd94a | 26 | m_packlen = 0; /* how many bytes do we ultimately expect? */ |
| jocis | 0:f67a8fffd94a | 27 | m_escapedchar = 0; /* if set, we're processing an escape sequence */ |
| jocis | 0:f67a8fffd94a | 28 | m_erroroccured = 0; /* if set, we've received an error packet or packets */ |
| jocis | 0:f67a8fffd94a | 29 | m_resetoccured = 0; /* if set, ball was reset, so have to reinitialize it */ |
| jocis | 0:f67a8fffd94a | 30 | m_spaceball4000 = 0; /* if set, its a Spaceball 4000 */ |
| jocis | 0:f67a8fffd94a | 31 | m_leftymode4000 = 0; /* if set, Spaceball 4000 in "lefty" orientation */ |
| jocis | 0:f67a8fffd94a | 32 | m_timer = 0; /* time since last packet was received */ |
| jocis | 0:f67a8fffd94a | 33 | |
| jocis | 0:f67a8fffd94a | 34 | _serial.attach ( this, &SpaceBall::SerialISR ); |
| jocis | 0:f67a8fffd94a | 35 | |
| jocis | 0:f67a8fffd94a | 36 | Init(); |
| jocis | 0:f67a8fffd94a | 37 | |
| jocis | 0:f67a8fffd94a | 38 | }; |
| jocis | 0:f67a8fffd94a | 39 | |
| jocis | 0:f67a8fffd94a | 40 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 41 | |
| jocis | 0:f67a8fffd94a | 42 | void SpaceBall::Init() |
| jocis | 0:f67a8fffd94a | 43 | { |
| jocis | 0:f67a8fffd94a | 44 | m_packlen=1; |
| jocis | 0:f67a8fffd94a | 45 | m_resetoccured=0; |
| jocis | 0:f67a8fffd94a | 46 | |
| jocis | 0:f67a8fffd94a | 47 | m_spaceball4000 = 0; /* re-determine which type it is */ |
| jocis | 0:f67a8fffd94a | 48 | m_leftymode4000 = 0; /* re-determine if its in lefty mode */ |
| jocis | 0:f67a8fffd94a | 49 | |
| jocis | 0:f67a8fffd94a | 50 | if (!m_resetoccured) { |
| jocis | 0:f67a8fffd94a | 51 | #if defined(DEBUG) |
| jocis | 0:f67a8fffd94a | 52 | printf("Sending reset command to spaceball...\n"); |
| jocis | 0:f67a8fffd94a | 53 | #endif |
| jocis | 0:f67a8fffd94a | 54 | m_resetoccured=1; |
| jocis | 0:f67a8fffd94a | 55 | _serial.printf ( "@\r" ); /* force reset */ |
| jocis | 0:f67a8fffd94a | 56 | } |
| jocis | 0:f67a8fffd94a | 57 | |
| jocis | 0:f67a8fffd94a | 58 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 59 | |
| jocis | 0:f67a8fffd94a | 60 | #if defined(DEBUG) |
| jocis | 0:f67a8fffd94a | 61 | printf("Sending initialization sequence to spaceball...\n"); |
| jocis | 0:f67a8fffd94a | 62 | #endif |
| jocis | 0:f67a8fffd94a | 63 | |
| jocis | 0:f67a8fffd94a | 64 | _serial.printf ( "CB\r" ); |
| jocis | 0:f67a8fffd94a | 65 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 66 | _serial.printf ( "NT\r" ); |
| jocis | 0:f67a8fffd94a | 67 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 68 | _serial.printf ( "FTp\r" ); |
| jocis | 0:f67a8fffd94a | 69 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 70 | _serial.printf ( "FRp\r" ); |
| jocis | 0:f67a8fffd94a | 71 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 72 | _serial.printf ( "P@r@r\r" ); |
| jocis | 0:f67a8fffd94a | 73 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 74 | _serial.printf ( "MSSV\r" ); |
| jocis | 0:f67a8fffd94a | 75 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 76 | _serial.printf ( "Z\r" ); |
| jocis | 0:f67a8fffd94a | 77 | Sleep(10); |
| jocis | 0:f67a8fffd94a | 78 | _serial.printf ( "BcCcC\r" ); |
| jocis | 0:f67a8fffd94a | 79 | } |
| jocis | 0:f67a8fffd94a | 80 | |
| jocis | 0:f67a8fffd94a | 81 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 82 | |
| jocis | 0:f67a8fffd94a | 83 | void SpaceBall::SerialISR(void) |
| jocis | 0:f67a8fffd94a | 84 | { |
| jocis | 0:f67a8fffd94a | 85 | char c; |
| jocis | 0:f67a8fffd94a | 86 | |
| jocis | 0:f67a8fffd94a | 87 | while ( _serial.readable() ) |
| jocis | 0:f67a8fffd94a | 88 | { |
| jocis | 0:f67a8fffd94a | 89 | c = _serial.getc(); |
| jocis | 0:f67a8fffd94a | 90 | |
| jocis | 0:f67a8fffd94a | 91 | //printf("%c", c); |
| jocis | 0:f67a8fffd94a | 92 | |
| jocis | 0:f67a8fffd94a | 93 | Process ( c ); |
| jocis | 0:f67a8fffd94a | 94 | } |
| jocis | 0:f67a8fffd94a | 95 | } |
| jocis | 0:f67a8fffd94a | 96 | |
| jocis | 0:f67a8fffd94a | 97 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 98 | |
| jocis | 0:f67a8fffd94a | 99 | void SpaceBall::Process ( char c ) |
| jocis | 0:f67a8fffd94a | 100 | { |
| jocis | 0:f67a8fffd94a | 101 | if ( _bSpaceOrb ) |
| jocis | 0:f67a8fffd94a | 102 | ProcessSO ( c ); |
| jocis | 0:f67a8fffd94a | 103 | else |
| jocis | 0:f67a8fffd94a | 104 | ProcessSB ( c ); |
| jocis | 0:f67a8fffd94a | 105 | } |
| jocis | 0:f67a8fffd94a | 106 | |
| jocis | 0:f67a8fffd94a | 107 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 108 | |
| jocis | 0:f67a8fffd94a | 109 | void SpaceBall::ProcessSB ( char c ) |
| jocis | 0:f67a8fffd94a | 110 | { |
| jocis | 0:f67a8fffd94a | 111 | int i, num, packs; |
| jocis | 0:f67a8fffd94a | 112 | bool bChanged = false; |
| jocis | 0:f67a8fffd94a | 113 | |
| jocis | 0:f67a8fffd94a | 114 | packs = 0; /* no packs received yet */ |
| jocis | 0:f67a8fffd94a | 115 | |
| jocis | 0:f67a8fffd94a | 116 | /* process potentially occuring escaped character sequences */ |
| jocis | 0:f67a8fffd94a | 117 | if (c == '^') |
| jocis | 0:f67a8fffd94a | 118 | { |
| jocis | 0:f67a8fffd94a | 119 | if (!m_escapedchar) |
| jocis | 0:f67a8fffd94a | 120 | { |
| jocis | 0:f67a8fffd94a | 121 | m_escapedchar = 1; |
| jocis | 0:f67a8fffd94a | 122 | return; /* eat the escape character from buffer */ |
| jocis | 0:f67a8fffd94a | 123 | } |
| jocis | 0:f67a8fffd94a | 124 | } |
| jocis | 0:f67a8fffd94a | 125 | |
| jocis | 0:f67a8fffd94a | 126 | if (m_escapedchar) |
| jocis | 0:f67a8fffd94a | 127 | { |
| jocis | 0:f67a8fffd94a | 128 | m_escapedchar = 0; |
| jocis | 0:f67a8fffd94a | 129 | |
| jocis | 0:f67a8fffd94a | 130 | switch (c) |
| jocis | 0:f67a8fffd94a | 131 | { |
| jocis | 0:f67a8fffd94a | 132 | case '^': /* leave char in buffer unchanged */ |
| jocis | 0:f67a8fffd94a | 133 | break; |
| jocis | 0:f67a8fffd94a | 134 | |
| jocis | 0:f67a8fffd94a | 135 | case 'Q': |
| jocis | 0:f67a8fffd94a | 136 | case 'S': |
| jocis | 0:f67a8fffd94a | 137 | case 'M': |
| jocis | 0:f67a8fffd94a | 138 | c &= 0x1F; /* convert character to unescaped form */ |
| jocis | 0:f67a8fffd94a | 139 | break; |
| jocis | 0:f67a8fffd94a | 140 | |
| jocis | 0:f67a8fffd94a | 141 | default: |
| jocis | 0:f67a8fffd94a | 142 | break; |
| jocis | 0:f67a8fffd94a | 143 | } |
| jocis | 0:f67a8fffd94a | 144 | } |
| jocis | 0:f67a8fffd94a | 145 | |
| jocis | 0:f67a8fffd94a | 146 | |
| jocis | 0:f67a8fffd94a | 147 | /* figure out what kind of packet we received */ |
| jocis | 0:f67a8fffd94a | 148 | if (m_bufpos == 0) |
| jocis | 0:f67a8fffd94a | 149 | { |
| jocis | 0:f67a8fffd94a | 150 | switch(c) |
| jocis | 0:f67a8fffd94a | 151 | { |
| jocis | 0:f67a8fffd94a | 152 | case 'D': /* Displacement packet */ |
| jocis | 0:f67a8fffd94a | 153 | m_packtype = 'D'; |
| jocis | 0:f67a8fffd94a | 154 | m_packlen = 16; /* D packets are 15 bytes long */ |
| jocis | 0:f67a8fffd94a | 155 | break; |
| jocis | 0:f67a8fffd94a | 156 | |
| jocis | 0:f67a8fffd94a | 157 | case 'K': /* Button/Key packet */ |
| jocis | 0:f67a8fffd94a | 158 | m_packtype = 'K'; |
| jocis | 0:f67a8fffd94a | 159 | m_packlen = 4; /* K packets are 3 bytes long */ |
| jocis | 0:f67a8fffd94a | 160 | break; |
| jocis | 0:f67a8fffd94a | 161 | |
| jocis | 0:f67a8fffd94a | 162 | case '.': /* Spaceball 4000 FLX "advanced" button press event */ |
| jocis | 0:f67a8fffd94a | 163 | m_packtype = '.'; |
| jocis | 0:f67a8fffd94a | 164 | m_packlen = 4; /* . packets are 3 bytes long */ |
| jocis | 0:f67a8fffd94a | 165 | break; |
| jocis | 0:f67a8fffd94a | 166 | |
| jocis | 0:f67a8fffd94a | 167 | case 'C': /* Communications mode packet */ |
| jocis | 0:f67a8fffd94a | 168 | m_packtype = 'C'; |
| jocis | 0:f67a8fffd94a | 169 | m_packlen = 4; |
| jocis | 0:f67a8fffd94a | 170 | break; |
| jocis | 0:f67a8fffd94a | 171 | |
| jocis | 0:f67a8fffd94a | 172 | case 'F': /* Spaceball sensitization mode packet */ |
| jocis | 0:f67a8fffd94a | 173 | m_packtype = 'F'; |
| jocis | 0:f67a8fffd94a | 174 | m_packlen = 4; |
| jocis | 0:f67a8fffd94a | 175 | break; |
| jocis | 0:f67a8fffd94a | 176 | |
| jocis | 0:f67a8fffd94a | 177 | case 'M': /* Movement mode packet */ |
| jocis | 0:f67a8fffd94a | 178 | m_packtype = 'M'; |
| jocis | 0:f67a8fffd94a | 179 | m_packlen = 5; |
| jocis | 0:f67a8fffd94a | 180 | break; |
| jocis | 0:f67a8fffd94a | 181 | |
| jocis | 0:f67a8fffd94a | 182 | case 'N': /* Null region packet */ |
| jocis | 0:f67a8fffd94a | 183 | m_packtype = 'N'; |
| jocis | 0:f67a8fffd94a | 184 | m_packlen = 3; |
| jocis | 0:f67a8fffd94a | 185 | break; |
| jocis | 0:f67a8fffd94a | 186 | |
| jocis | 0:f67a8fffd94a | 187 | case 'P': /* Update rate packet */ |
| jocis | 0:f67a8fffd94a | 188 | m_packtype = 'P'; |
| jocis | 0:f67a8fffd94a | 189 | m_packlen = 6; |
| jocis | 0:f67a8fffd94a | 190 | break; |
| jocis | 0:f67a8fffd94a | 191 | |
| jocis | 0:f67a8fffd94a | 192 | case '\v': /* XON at poweron */ |
| jocis | 0:f67a8fffd94a | 193 | m_packtype = '\v'; |
| jocis | 0:f67a8fffd94a | 194 | m_packlen = 1; |
| jocis | 0:f67a8fffd94a | 195 | break; |
| jocis | 0:f67a8fffd94a | 196 | |
| jocis | 0:f67a8fffd94a | 197 | case '\n': /* carriage return at poweron */ |
| jocis | 0:f67a8fffd94a | 198 | case '\r': /* carriage return at poweron */ |
| jocis | 0:f67a8fffd94a | 199 | m_packtype = '\r'; |
| jocis | 0:f67a8fffd94a | 200 | m_packlen = 1; |
| jocis | 0:f67a8fffd94a | 201 | break; |
| jocis | 0:f67a8fffd94a | 202 | |
| jocis | 0:f67a8fffd94a | 203 | case '@': /* Spaceball Hard/Soft Reset packet */ |
| jocis | 0:f67a8fffd94a | 204 | m_resetoccured=1; |
| jocis | 0:f67a8fffd94a | 205 | m_packtype = '@'; |
| jocis | 0:f67a8fffd94a | 206 | m_packlen = 62; /* Resets aren't longer than 62 chars */ |
| jocis | 0:f67a8fffd94a | 207 | break; |
| jocis | 0:f67a8fffd94a | 208 | |
| jocis | 0:f67a8fffd94a | 209 | case 'E': /* Error packet */ |
| jocis | 0:f67a8fffd94a | 210 | m_packtype = 'E'; |
| jocis | 0:f67a8fffd94a | 211 | m_packlen = 8; /* E packets are up to 7 bytes long */ |
| jocis | 0:f67a8fffd94a | 212 | break; |
| jocis | 0:f67a8fffd94a | 213 | |
| jocis | 0:f67a8fffd94a | 214 | case 'Z': /* Zero packet (Spaceball 2003/3003/4000 FLX) */ |
| jocis | 0:f67a8fffd94a | 215 | m_packtype = 'Z'; |
| jocis | 0:f67a8fffd94a | 216 | m_packlen = 14; /* Z packets are hardware dependent */ |
| jocis | 0:f67a8fffd94a | 217 | break; |
| jocis | 0:f67a8fffd94a | 218 | |
| jocis | 0:f67a8fffd94a | 219 | default: /* Unknown packet! */ |
| jocis | 0:f67a8fffd94a | 220 | return; |
| jocis | 0:f67a8fffd94a | 221 | } |
| jocis | 0:f67a8fffd94a | 222 | } |
| jocis | 0:f67a8fffd94a | 223 | |
| jocis | 0:f67a8fffd94a | 224 | |
| jocis | 0:f67a8fffd94a | 225 | m_buf[m_bufpos] = c; |
| jocis | 0:f67a8fffd94a | 226 | m_bufpos++; |
| jocis | 0:f67a8fffd94a | 227 | |
| jocis | 0:f67a8fffd94a | 228 | /* Reset packet processing */ |
| jocis | 0:f67a8fffd94a | 229 | if (m_packtype == '@') |
| jocis | 0:f67a8fffd94a | 230 | { |
| jocis | 0:f67a8fffd94a | 231 | if (c != '\r') |
| jocis | 0:f67a8fffd94a | 232 | return; |
| jocis | 0:f67a8fffd94a | 233 | else |
| jocis | 0:f67a8fffd94a | 234 | m_packlen = m_bufpos; |
| jocis | 0:f67a8fffd94a | 235 | } |
| jocis | 0:f67a8fffd94a | 236 | |
| jocis | 0:f67a8fffd94a | 237 | /* Error packet processing */ |
| jocis | 0:f67a8fffd94a | 238 | if (m_packtype == 'E') |
| jocis | 0:f67a8fffd94a | 239 | { |
| jocis | 0:f67a8fffd94a | 240 | if (c != '\r') |
| jocis | 0:f67a8fffd94a | 241 | return; |
| jocis | 0:f67a8fffd94a | 242 | else |
| jocis | 0:f67a8fffd94a | 243 | m_packlen = m_bufpos; |
| jocis | 0:f67a8fffd94a | 244 | } |
| jocis | 0:f67a8fffd94a | 245 | else if (m_bufpos != m_packlen) |
| jocis | 0:f67a8fffd94a | 246 | return; |
| jocis | 0:f67a8fffd94a | 247 | |
| jocis | 0:f67a8fffd94a | 248 | switch (m_packtype) |
| jocis | 0:f67a8fffd94a | 249 | { |
| jocis | 0:f67a8fffd94a | 250 | case 'D': /* ball displacement event */ |
| jocis | 0:f67a8fffd94a | 251 | { |
| jocis | 0:f67a8fffd94a | 252 | unsigned int tx, ty, tz, rx, ry, rz; |
| jocis | 0:f67a8fffd94a | 253 | |
| jocis | 0:f67a8fffd94a | 254 | /* number of 1/16ths of milliseconds since last */ |
| jocis | 0:f67a8fffd94a | 255 | /* ball displacement packet */ |
| jocis | 0:f67a8fffd94a | 256 | m_timer = ((m_buf[1]) << 8) | (m_buf[2]); |
| jocis | 0:f67a8fffd94a | 257 | |
| jocis | 0:f67a8fffd94a | 258 | tx = ((m_buf[ 3]) << 8) | ((m_buf[ 4])); |
| jocis | 0:f67a8fffd94a | 259 | tz = ((m_buf[ 5]) << 8) | ((m_buf[ 6])); |
| jocis | 0:f67a8fffd94a | 260 | ty = ((m_buf[ 7]) << 8) | ((m_buf[ 8])); |
| jocis | 0:f67a8fffd94a | 261 | rx = ((m_buf[ 9]) << 8) | ((m_buf[10])); |
| jocis | 0:f67a8fffd94a | 262 | rz = ((m_buf[11]) << 8) | ((m_buf[12])); |
| jocis | 0:f67a8fffd94a | 263 | ry = ((m_buf[13]) << 8) | ((m_buf[14])); |
| jocis | 0:f67a8fffd94a | 264 | |
| jocis | 0:f67a8fffd94a | 265 | m_axis[0] = (((int) tx) << 16) >> 16; |
| jocis | 0:f67a8fffd94a | 266 | m_axis[1] = (((int) ty) << 16) >> 16; |
| jocis | 0:f67a8fffd94a | 267 | m_axis[2] = (((int) tz) << 16) >> 16; |
| jocis | 0:f67a8fffd94a | 268 | m_axis[3] = -(((int) rx) << 16) >> 16; |
| jocis | 0:f67a8fffd94a | 269 | m_axis[4] = -(((int) ry) << 16) >> 16; |
| jocis | 0:f67a8fffd94a | 270 | m_axis[5] = -(((int) rz) << 16) >> 16; |
| jocis | 0:f67a8fffd94a | 271 | |
| jocis | 0:f67a8fffd94a | 272 | bChanged = true; |
| jocis | 0:f67a8fffd94a | 273 | DoChangedAxis(); |
| jocis | 0:f67a8fffd94a | 274 | } |
| jocis | 0:f67a8fffd94a | 275 | break; |
| jocis | 0:f67a8fffd94a | 276 | |
| jocis | 0:f67a8fffd94a | 277 | case 'K': /* button press event */ |
| jocis | 0:f67a8fffd94a | 278 | /* Spaceball 2003A, 2003B, 2003 FLX, 3003 FLX, 4000 FLX */ |
| jocis | 0:f67a8fffd94a | 279 | /* button packet. (4000 only for backwards compatibility) */ |
| jocis | 0:f67a8fffd94a | 280 | /* The lowest 5 bits of the first byte are buttons 5-9 */ |
| jocis | 0:f67a8fffd94a | 281 | /* Button '8' on a Spaceball 2003 is the rezero button */ |
| jocis | 0:f67a8fffd94a | 282 | /* The lowest 4 bits of the second byte are buttons 1-4 */ |
| jocis | 0:f67a8fffd94a | 283 | /* For Spaceball 2003, we'll map the buttons 1-7 normally */ |
| jocis | 0:f67a8fffd94a | 284 | /* skip 8, as its a hardware "rezero button" on that device */ |
| jocis | 0:f67a8fffd94a | 285 | /* and call the "pick" button "8". */ |
| jocis | 0:f67a8fffd94a | 286 | /* On the Spaceball 3003, the "right" button also triggers */ |
| jocis | 0:f67a8fffd94a | 287 | /* the "pick" bit. We OR the 2003/3003 rezero bits together */ |
| jocis | 0:f67a8fffd94a | 288 | |
| jocis | 0:f67a8fffd94a | 289 | /* if we have found a Spaceball 4000, then we ignore the 'K' */ |
| jocis | 0:f67a8fffd94a | 290 | /* packets entirely, and only use the '.' packets. */ |
| jocis | 0:f67a8fffd94a | 291 | if (m_spaceball4000) |
| jocis | 0:f67a8fffd94a | 292 | break; |
| jocis | 0:f67a8fffd94a | 293 | |
| jocis | 0:f67a8fffd94a | 294 | m_buttons = |
| jocis | 0:f67a8fffd94a | 295 | ((m_buf[1] & 0x10) << 8) | /* 2003 pick button is ??? */ |
| jocis | 0:f67a8fffd94a | 296 | ((m_buf[1] & 0x20) << 9) | /* 3003 rezero button */ |
| jocis | 0:f67a8fffd94a | 297 | ((m_buf[1] & 0x08) << 11) | /* 2003 rezero button */ |
| jocis | 0:f67a8fffd94a | 298 | ((m_buf[1] & 0x07) << 4) | /* 5,6,7 (2003/4000) */ |
| jocis | 0:f67a8fffd94a | 299 | ((m_buf[2] & 0x30) << 8) | /* 3003 Left/Right buttons */ |
| jocis | 0:f67a8fffd94a | 300 | ((m_buf[2] & 0x0F)); /* 1,2,3,4 (2003/4000) */ |
| jocis | 0:f67a8fffd94a | 301 | |
| jocis | 0:f67a8fffd94a | 302 | bChanged = true; |
| jocis | 0:f67a8fffd94a | 303 | DoChangedButtons(); |
| jocis | 0:f67a8fffd94a | 304 | break; |
| jocis | 0:f67a8fffd94a | 305 | |
| jocis | 0:f67a8fffd94a | 306 | case '.': /* button press event (4000) */ |
| jocis | 0:f67a8fffd94a | 307 | /* Spaceball 4000 FLX "expanded" button packet, with 12 buttons */ |
| jocis | 0:f67a8fffd94a | 308 | |
| jocis | 0:f67a8fffd94a | 309 | /* extra packet validity check, since we use this packet type */ |
| jocis | 0:f67a8fffd94a | 310 | /* to override the 'K' button packets, and determine if its a */ |
| jocis | 0:f67a8fffd94a | 311 | /* Spaceball 4000 or not... */ |
| jocis | 0:f67a8fffd94a | 312 | if (m_buf[3] != '\r') { |
| jocis | 0:f67a8fffd94a | 313 | break; /* if not terminated with a '\r', probably garbage */ |
| jocis | 0:f67a8fffd94a | 314 | } |
| jocis | 0:f67a8fffd94a | 315 | |
| jocis | 0:f67a8fffd94a | 316 | /* if we got a valid '.' packet, this must be a Spaceball 4000 */ |
| jocis | 0:f67a8fffd94a | 317 | m_spaceball4000 = 1; /* Must be talking to a Spaceball 4000 */ |
| jocis | 0:f67a8fffd94a | 318 | |
| jocis | 0:f67a8fffd94a | 319 | /* Spaceball 4000 series "expanded" button press event */ |
| jocis | 0:f67a8fffd94a | 320 | /* includes data for 12 buttons, and left/right orientation */ |
| jocis | 0:f67a8fffd94a | 321 | m_buttons = |
| jocis | 0:f67a8fffd94a | 322 | (((~m_buf[1]) & 0x20) << 10) | /* "left handed" mode */ |
| jocis | 0:f67a8fffd94a | 323 | ((m_buf[1] & 0x1F) << 7) | /* 8,9,10,11,12 */ |
| jocis | 0:f67a8fffd94a | 324 | ((m_buf[2] & 0x3F) ) | /* 1,2,3,4,5,6 (4000) */ |
| jocis | 0:f67a8fffd94a | 325 | ((m_buf[2] & 0x80) >> 1); /* 7 (4000) */ |
| jocis | 0:f67a8fffd94a | 326 | |
| jocis | 0:f67a8fffd94a | 327 | /* set "lefty" orientation mode if "lefty bit" is _clear_ */ |
| jocis | 0:f67a8fffd94a | 328 | if ((m_buf[1] & 0x20) == 0) |
| jocis | 0:f67a8fffd94a | 329 | m_leftymode4000 = 1; /* left handed mode */ |
| jocis | 0:f67a8fffd94a | 330 | else |
| jocis | 0:f67a8fffd94a | 331 | m_leftymode4000 = 0; /* right handed mode */ |
| jocis | 0:f67a8fffd94a | 332 | |
| jocis | 0:f67a8fffd94a | 333 | bChanged = true; |
| jocis | 0:f67a8fffd94a | 334 | DoChangedButtons(); |
| jocis | 0:f67a8fffd94a | 335 | break; |
| jocis | 0:f67a8fffd94a | 336 | |
| jocis | 0:f67a8fffd94a | 337 | case 'C': /* Communications mode packet */ |
| jocis | 0:f67a8fffd94a | 338 | case 'F': /* Spaceball sensitization packet */ |
| jocis | 0:f67a8fffd94a | 339 | case 'P': /* Spaceball update rate packet */ |
| jocis | 0:f67a8fffd94a | 340 | case 'M': /* Spaceball movement mode packet */ |
| jocis | 0:f67a8fffd94a | 341 | case 'N': /* Null region packet */ |
| jocis | 0:f67a8fffd94a | 342 | case '\r': /* carriage return at poweron */ |
| jocis | 0:f67a8fffd94a | 343 | case '\v': /* XON at poweron */ |
| jocis | 0:f67a8fffd94a | 344 | /* eat and ignore these packets */ |
| jocis | 0:f67a8fffd94a | 345 | break; |
| jocis | 0:f67a8fffd94a | 346 | |
| jocis | 0:f67a8fffd94a | 347 | case '@': /* Reset packet */ |
| jocis | 0:f67a8fffd94a | 348 | /* if we get a reset packet, we have to re-initialize */ |
| jocis | 0:f67a8fffd94a | 349 | /* the device, and assume that its completely schizophrenic */ |
| jocis | 0:f67a8fffd94a | 350 | /* at this moment, we must reset it again at this point */ |
| jocis | 0:f67a8fffd94a | 351 | m_resetoccured=1; |
| jocis | 0:f67a8fffd94a | 352 | //JKReset(); |
| jocis | 0:f67a8fffd94a | 353 | Init(); |
| jocis | 0:f67a8fffd94a | 354 | break; |
| jocis | 0:f67a8fffd94a | 355 | |
| jocis | 0:f67a8fffd94a | 356 | |
| jocis | 0:f67a8fffd94a | 357 | case 'E': /* Error packet, hardware/software problem */ |
| jocis | 0:f67a8fffd94a | 358 | m_erroroccured++; |
| jocis | 0:f67a8fffd94a | 359 | break; |
| jocis | 0:f67a8fffd94a | 360 | |
| jocis | 0:f67a8fffd94a | 361 | case 'Z': /* Zero packet (Spaceball 2003/3003/4000 FLX) */ |
| jocis | 0:f67a8fffd94a | 362 | /* We just ignore these... */ |
| jocis | 0:f67a8fffd94a | 363 | break; |
| jocis | 0:f67a8fffd94a | 364 | |
| jocis | 0:f67a8fffd94a | 365 | default: |
| jocis | 0:f67a8fffd94a | 366 | break; |
| jocis | 0:f67a8fffd94a | 367 | } |
| jocis | 0:f67a8fffd94a | 368 | |
| jocis | 0:f67a8fffd94a | 369 | /* reset */ |
| jocis | 0:f67a8fffd94a | 370 | m_bufpos = 0; |
| jocis | 0:f67a8fffd94a | 371 | m_packtype = 0; |
| jocis | 0:f67a8fffd94a | 372 | m_packlen = 1; |
| jocis | 0:f67a8fffd94a | 373 | packs++; |
| jocis | 0:f67a8fffd94a | 374 | |
| jocis | 0:f67a8fffd94a | 375 | } |
| jocis | 0:f67a8fffd94a | 376 | |
| jocis | 0:f67a8fffd94a | 377 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 378 | |
| jocis | 0:f67a8fffd94a | 379 | void SpaceBall::ProcessSO ( char c ) |
| jocis | 0:f67a8fffd94a | 380 | { |
| jocis | 0:f67a8fffd94a | 381 | } |
| jocis | 0:f67a8fffd94a | 382 | |
| jocis | 0:f67a8fffd94a | 383 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 384 | /////////////////////////////////////////////////////////////////////////////// |
| jocis | 0:f67a8fffd94a | 385 | /////////////////////////////////////////////////////////////////////////////// |