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.
Dependencies: mbed
Fork of RCControlOOP by
WirelessMousr.cpp@0:78e2af20cbf3, 2014-09-08 (annotated)
- Committer:
- mfillinois
- Date:
- Mon Sep 08 11:32:04 2014 +0000
- Revision:
- 0:78e2af20cbf3
- Child:
- 1:e694ee3b4a7f
RC OOP code for mini-shield mouse. Only basic RC function at this time.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfillinois | 0:78e2af20cbf3 | 1 | #include "WirelessMousr.h" |
mfillinois | 0:78e2af20cbf3 | 2 | |
mfillinois | 0:78e2af20cbf3 | 3 | WirelessMousr::WirelessMousr() : Mousr(), pc(p28, p27) {} |
mfillinois | 0:78e2af20cbf3 | 4 | |
mfillinois | 0:78e2af20cbf3 | 5 | int WirelessMousr::init() |
mfillinois | 0:78e2af20cbf3 | 6 | { |
mfillinois | 0:78e2af20cbf3 | 7 | pc.attach(this,&WirelessMousr::rxCallback); |
mfillinois | 0:78e2af20cbf3 | 8 | wait(0.1); |
mfillinois | 0:78e2af20cbf3 | 9 | return 0; |
mfillinois | 0:78e2af20cbf3 | 10 | } |
mfillinois | 0:78e2af20cbf3 | 11 | |
mfillinois | 0:78e2af20cbf3 | 12 | void WirelessMousr::rxCallback() |
mfillinois | 0:78e2af20cbf3 | 13 | { |
mfillinois | 0:78e2af20cbf3 | 14 | char state = this->pc.getc(); // read RX character, clearing interrupt |
mfillinois | 0:78e2af20cbf3 | 15 | pc.putc(state); // loopback |
mfillinois | 0:78e2af20cbf3 | 16 | pc.putc(10); |
mfillinois | 0:78e2af20cbf3 | 17 | |
mfillinois | 0:78e2af20cbf3 | 18 | // state machine |
mfillinois | 0:78e2af20cbf3 | 19 | switch(state) { |
mfillinois | 0:78e2af20cbf3 | 20 | case 's': |
mfillinois | 0:78e2af20cbf3 | 21 | this->stop(); break; |
mfillinois | 0:78e2af20cbf3 | 22 | case 'w': |
mfillinois | 0:78e2af20cbf3 | 23 | this->straight(getStraightSpeed()); break; |
mfillinois | 0:78e2af20cbf3 | 24 | case 'a': |
mfillinois | 0:78e2af20cbf3 | 25 | this->left(getRotateSpeed()); wait(0.25); stop(); break; |
mfillinois | 0:78e2af20cbf3 | 26 | case 'd': |
mfillinois | 0:78e2af20cbf3 | 27 | this->right(getRotateSpeed()); wait(0.25); stop(); break; |
mfillinois | 0:78e2af20cbf3 | 28 | case 'x': |
mfillinois | 0:78e2af20cbf3 | 29 | this->backwards(getStraightSpeed()); break; |
mfillinois | 0:78e2af20cbf3 | 30 | case 'q': |
mfillinois | 0:78e2af20cbf3 | 31 | this->left(getRotateFastSpeed()); break; |
mfillinois | 0:78e2af20cbf3 | 32 | case 'e': |
mfillinois | 0:78e2af20cbf3 | 33 | this->right(getRotateFastSpeed()); break; |
mfillinois | 0:78e2af20cbf3 | 34 | case 'z': |
mfillinois | 0:78e2af20cbf3 | 35 | this->left(getRotateSlowSpeed()); break; |
mfillinois | 0:78e2af20cbf3 | 36 | case 'c': |
mfillinois | 0:78e2af20cbf3 | 37 | this->right(getRotateSlowSpeed()); break; |
mfillinois | 0:78e2af20cbf3 | 38 | } |
mfillinois | 0:78e2af20cbf3 | 39 | } |