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: ExoController MODSERIAL SDFileSystem_HelloWorld UI-Honka mbed
Fork of Data Management by
Revision 0:cbb61997e231, committed 2014-10-15
- Comitter:
- perr1940
- Date:
- Wed Oct 15 18:44:04 2014 +0000
- Child:
- 1:78452728a306
- Commit message:
- Not working, but close. Going to through in a while loop and see if that's better.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Wed Oct 15 18:44:04 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/UI/UI.cpp Wed Oct 15 18:44:04 2014 +0000
@@ -0,0 +1,94 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "initDatabed.h"
+#include "UI.h"
+
+// UI button variables
+int buttonA = 1; // state of remote button
+int buttonA_prev = 1;
+
+// push hold vars
+float tHold = .6; // hold time for sit/stand
+float tIdle = 2; // time out to confirm sit or stance (s)
+int SSconfirm = 0; // sit/stand variable for confirmation process
+float tRelease = .3; // time since last transmission to determine button release
+
+
+// various timers
+Timer time_StateChange;
+Timer time_pressA;
+Timer time_pressB;
+
+int buttonB = 1; // state of remote button
+int buttonB_prev = 1;
+char xbeeBuffer[250];
+int dataCnt=0;
+int UI=0;
+
+float time_sinceA, time_sinceB; //time since the button was first pressed
+void readBuffer()
+{
+ while (xbeeUI.readable() && dataCnt<250) {
+ xbeeBuffer[dataCnt] = xbeeUI.getc();
+ dataCnt++;
+ }
+}
+
+void checkUI_XBee()
+{
+
+ buttonA_prev = buttonA;
+ buttonB_prev = buttonB;
+ if(dataCnt>=22) {
+ char * index=strchr(xbeeBuffer,0x7e);
+ buttonA = (xbeeBuffer[index-xbeeBuffer+21]>>1) & 1; // on DIO1
+ buttonB = (xbeeBuffer[index-xbeeBuffer+21]>>2) & 1; // on DIO2
+ 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;
+}
+
+void initializeUI()
+{
+ xbeeUI.baud(115200);
+ mainPower=0;
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/UI.h Wed Oct 15 18:44:04 2014 +0000 @@ -0,0 +1,20 @@ +#ifndef UI_H +#define UI_H + +/** +* Copyright (c) 2014 +* All rights reserved. +* + * + * by: Bradley Perry + * +*/ + +#include "mbed.h" +#include "MODSERIAL.h" +#include "initDatabed.h" +extern int UI; +#endif + +extern void checkUI_XBee(); +extern void readBuffer(); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/initDatabed/initDatabed.cpp Wed Oct 15 18:44:04 2014 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+
+MODSERIAL xbeeUI(p28, p27); //XBee UI crutch communication
+
+Serial pc(USBTX, USBRX);
+SPISlave comm(p5, p6, p7, p8); // mosi, miso, sclk, ssel
+
+// amplifier power on
+DigitalOut mainPower(p26); // power to board/motors etc
+
+// various LEDs
+DigitalOut statusLed(p15);
+DigitalOut boardLed1(LED1);
+DigitalOut boardLed2(LED2);
+DigitalOut boardLed3(LED3);
+DigitalOut boardLed4(LED4);
+
+void initializeDatabed() {
+ xbeeUI.baud(115200);
+ pc.baud(921600);
+
+ comm.frequency(12000000);
+
+ wait(1);
+ pc.printf("Starting databed...\r\n");
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/initDatabed/initDatabed.h Wed Oct 15 18:44:04 2014 +0000 @@ -0,0 +1,25 @@ +#ifndef INIT_H +#define INIT_H + +#include "mbed.h" +#include "MODSERIAL.h" + +extern MODSERIAL xbeeUI; // left xbee + +extern Serial pc; +extern SPISlave comm; // mosi, miso, sclk, ssel + +// amplifier power on +extern DigitalOut mainPower; // power to board/motors etc + +// various LEDs +extern DigitalOut statusLed; +extern DigitalOut boardLed1; +extern DigitalOut boardLed2; +extern DigitalOut boardLed3; +extern DigitalOut boardLed4; + + +#endif + +extern void initializeDatabed(); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Oct 15 18:44:04 2014 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "initDatabed.h"
+#include "UI.h"
+
+Timer t_debug;
+
+int main()
+{
+ int dataIn[2], dataOut[2];
+ dataOut[0]=1;
+ dataOut[1]=2;
+ mainPower=0;//Don't turn on for initial testing
+ initializeDatabed();
+ comm.reply(dataOut[0]);//make this the first message
+ pc.printf("DataBed On!\r\n");
+ int counter=0;
+ //float blah=1;
+ //t_debug.start();
+ while (1) { //Run these functions as fast as possible
+ if(comm.receive()) {
+ //t_debug.reset();
+ dataIn[0] = comm.read();//Read the SPI buffer
+ if(dataIn[0]==75) {
+ comm.reply(dataOut[1]);// Make this the next reply
+ dataIn[1]=comm.read();//Read the SPI buffer
+ //pc.printf("T");
+ }
+ if(counter>=100) {
+ UI=0;//set the UI to 0 unless it's changed in checkUI_Xbee()
+ readBuffer();
+ checkUI_XBee(); //check UI from Xbee
+ counter=0;
+ }
+ //dataOut[0]=UI;
+ comm.reply(dataOut[0]);//Set the communication for the next round
+ pc.printf("Data: %d, %d,\r\n", dataIn[0], dataIn[1]);
+ counter++;
+ //blah=t_debug.read_us();
+ //pc.printf("UI: %d\r\n", UI);
+ //pc.printf("T: %f \r\n ", blah);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 15 18:44:04 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
