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.
Fork of UI by
Revision 2:d6595294497c, committed 2015-02-25
- Comitter:
- perr1940
- Date:
- Wed Feb 25 01:41:17 2015 +0000
- Parent:
- 1:7795fb7ee3f3
- Child:
- 3:19c08e8a552a
- Commit message:
- UI that works
Changed in this revision
| UserInterface.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/UserInterface.cpp Sat Feb 14 00:36:19 2015 +0000
+++ b/UserInterface.cpp Wed Feb 25 01:41:17 2015 +0000
@@ -27,7 +27,8 @@
//float _time_sinceA, _time_sinceB; //time since the button was first pressed
-UserInterface::UserInterface(void): _buttonA(1), _buttonA_prev(1), _tHold(.6), _tIdle(2), _SSconfirm(0), _tRelease(.3), _buttonB(1), _buttonB_prev(1), _dataCnt(0) {
+UserInterface::UserInterface(void): _buttonA(1), _buttonA_prev(1), _tHold(.6), _tIdle(2), _SSconfirm(0), _tRelease(.3), _buttonB(1), _buttonB_prev(1), _dataCnt(0)
+{
}
void UserInterface::readBuffer()
@@ -111,7 +112,7 @@
if (checksum != calcsum) {
return false;
}
- return true;
+ return true;
}
void UserInterface::checkUI_XBee()
@@ -121,14 +122,16 @@
_buttonB_prev = _buttonB;
char * idx = strchr(_xbeeBuffer,0x7e);
if (idx != NULL) {
+ _buttonA = (_xbeeBuffer[idx-_xbeeBuffer+21]>>1) & 1; // on DIO1
+ _buttonB = (_xbeeBuffer[idx-_xbeeBuffer+21]>>2) & 1; // on DIO2
int size[3];
find_length(idx, size);
printf("Size: %d, Datacount: %d\r\n", size[1], _dataCnt);
if(_dataCnt >= size[1]) {
-
- _buttonA = (_xbeeBuffer[idx-_xbeeBuffer+21]>>1) & 1; // on DIO1
- _buttonB = (_xbeeBuffer[idx-_xbeeBuffer+21]>>2) & 1; // on DIO2
-
+
+ //_buttonA = (_xbeeBuffer[idx-_xbeeBuffer+21]>>1) & 1; // on DIO1
+ //_buttonB = (_xbeeBuffer[idx-_xbeeBuffer+21]>>2) & 1; // on DIO2
+
if (checksum_check(idx+size[2], size[0])) {
printf("Checksums match\r\n");
} else {
@@ -136,115 +139,51 @@
}
_dataCnt = 0;
}
- if(sum == 0x79c) {
- if (_buttonA == 0 && _buttonA_prev == 1) {//buton was just pressed
- _time_pressA.reset();
- _time_pressA.start();
- _time_sinceA = 0;
- }
+ if (_buttonA == 0 && _buttonA_prev == 1) {//buton was just pressed
+ _time_pressA.reset();
+ _time_pressA.start();
+ _time_sinceA = 0;
+ }
- else if(_buttonA == 0) {
- _time_sinceA = _time_pressA; //button is still pressed
- }
-
- if (_buttonB == 0 && _buttonB_prev == 1) {//button was just pressed
- _time_pressB.reset();
- _time_pressB.start();
- _time_sinceB = 0;
- } else if(_buttonB == 0) {
- _time_sinceB = _time_pressB; //button is still pressed
- }
+ else if(_buttonA == 0) {
+ printf("!\r\n");
+ _time_sinceA = _time_pressA; //button is still pressed
}
- if((_time_pressA-_time_sinceA) >= _tRelease) { //button was released
- if(_time_pressA-_tRelease >= _tHold) { //if the button was held before released
- UI = 3; //UI command is a held A button
- } else {
- UI = 1; //UI command is a pressed A button
- }
- _buttonA = 1; //button A is released
- _time_pressA.stop(); //reset the button A timer
- _time_pressA.reset();
- }
- if(_time_pressB-_time_sinceB >= _tRelease) { //button was released
- if(_time_pressB-_tRelease >= _tHold) { //if the button was held before released
- UI = 4; //UI command is a held B button
- } else {
- UI = 2; //UI command is a pressed B button
- }
- _buttonB = 1; //button B is released
- _time_pressB.stop(); //reset the button B timer
+ if (_buttonB == 0 && _buttonB_prev == 1) {//button was just pressed
_time_pressB.reset();
+ _time_pressB.start();
+ _time_sinceB = 0;
+ } else if(_buttonB == 0) {
+ _time_sinceB = _time_pressB; //button is still pressed
}
}
+
+ if((_time_pressA-_time_sinceA) >= _tRelease) { //button was released
+ if(_time_pressA-_tRelease >= _tHold) { //if the button was held before released
+ UI = 3; //UI command is a held A button
+ } else {
+ UI = 1; //UI command is a pressed A button
+ }
+ _buttonA = 1; //button A is released
+ _time_pressA.stop(); //reset the button A timer
+ _time_pressA.reset();
+ }
+ if(_time_pressB-_time_sinceB >= _tRelease) { //button was released
+ if(_time_pressB-_tRelease >= _tHold) { //if the button was held before released
+ UI = 4; //UI command is a held B button
+ } else {
+ UI = 2; //UI command is a pressed B button
+ }
+ _buttonB = 1; //button B is released
+ _time_pressB.stop(); //reset the button B timer
+ _time_pressB.reset();
+ }
+
memset(_xbeeBuffer,0xFF,250);
_dataCnt = 0;
}
-/*void checkUI_XBee()
-{
-
- _buttonA_prev = _buttonA;
- buttonB_prev = buttonB;
- while (xbeeUI.readable() && _dataCnt<250) {
- __xbeeBuffer[_dataCnt] = xbeeUI.getc();
- _dataCnt++;
- if (__xbeeBuffer[_dataCnt]==0x7e) {
- for(int i=0; i<22; i++) {
- if(xbeeUI.readable() {
- __xbeeBuffer[_dataCnt] = xbeeUI.getc();
- _dataCnt++;
- }
- }
- }
- char * idx=strchr(__xbeeBuffer,0x7e);
- _buttonA = (_xbeeBuffer[idx-_xbeeBuffer+21]>>1) & 1; // on DIO1
- buttonB = (_xbeeBuffer[idx-_xbeeBuffer+21]>>2) & 1; // on DIO2
- pc.printf("%x\r\n", *(idx+2));
- _dataCnt=0;
- if (buttonA == 0 && buttonA_prev==1) {//buton was just pressed
- time_pressA.reset();
- time_pressA.start();
- _time_sinceA=0;
- }
-
- else if(buttonA==0) {
- _time_sinceA=time_pressA; //button is still pressed
- }
-
- if (buttonB == 0 && buttonB_prev==1) {//button was just pressed
- time_pressB.reset();
- time_pressB.start();
- _time_sinceB=0;
- } else if(buttonB==0) {
- _time_sinceB=time_pressB; //button is still pressed
- }
- }
- if((time_pressA-_time_sinceA)>=tRelease) { //button was released
- if(time_pressA-tRelease>=tHold) { //if the button was held before released
- UI=3; //UI command is a held A button
- } else {
- UI=1; //UI command is a pressed A button
- }
- buttonA=1; //button A is released
- time_pressA.stop(); //reset the button A timer
- time_pressA.reset();
- }
- if(time_pressB-_time_sinceB>=tRelease) { //button was released
- if(time_pressB-tRelease>=tHold) { //if the button was held before released
- UI=4; //UI command is a held B button
- } else {
- UI=2; //UI command is a pressed B button
- }
- buttonB=1; //button B is released
- time_pressB.stop(); //reset the button B timer
- time_pressB.reset();
- }
-
- _dataCnt=0;
- memset(__xbeeBuffer,0xF,250);
-}*/
-
void UserInterface::initializeUI()
{
xbeeUI.baud(115200);
