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 SerialInputReactionHandler AMPulseTrain SwArr16MOSFET StrCommandHandler KajiLabES
Diff: SerialCom/sigbind.cpp
- Revision:
- 1:b97639dad576
- Parent:
- 0:19a67422961f
--- a/SerialCom/sigbind.cpp Tue Oct 23 15:11:18 2018 +0000
+++ b/SerialCom/sigbind.cpp Wed Oct 23 20:08:31 2019 +0000
@@ -5,6 +5,103 @@
enum Lock {UNLOCK, LOCK};
Lock aktk_keylock = UNLOCK;
+//private functions
+template<typename T>
+int scanValue(T* arg_val);
+void waitUnpress();
+void setPulseParam();
+void ArrowKeyBind(const char arg_c);
+//void printStimType();
+void printStatus(void);
+void keyBind()
+{
+ //stimulator.DAAD(0);
+ char sig = pc.getc();
+ if (aktk_keylock == UNLOCK) {
+ aktk_keylock = LOCK;
+ switch(sig) {
+ case 'w':
+ spacing = WIDE_CONDITION;
+ pc.printf("Wide condition\n");
+ waitUnpress();
+ break;
+ case 'n':
+ spacing = NARROW_CONDITION;
+ pc.printf("Narrow condition\n");
+ waitUnpress();
+ break;
+ case 'm':
+ switch(pc.getc()) {
+ case 'b':
+ smode = BIPOLAR;
+ pc.printf("BIPOLAR Stimulation\n");
+ break;
+ case 'a':
+ smode = ANODIC;
+ pc.printf("ANODIC Stimulation\n");
+ break;
+ case 'c':
+ smode = CATHODIC;
+ pc.printf("CATHODIC Stimulation\n");
+ break;
+ }
+ waitUnpress();
+ break;
+ case 'p':
+ printStatus();
+ waitUnpress();
+ break;
+ case 'v':
+ setPulseParam();
+ waitUnpress();
+ break;
+ case 'a': //switch mbed-pc communication on/off
+ if (pstate == MAIN_ROUTINE) {
+ pstate = WAIT_A_CERTAIN_KEY;
+ pc.printf("stop\n");
+ } else if (pstate == WAIT_A_CERTAIN_KEY) {
+ pstate = MAIN_ROUTINE;
+ //printStimType();
+ pc.printf("start\n");
+ }
+ waitUnpress();
+ break;
+ case 'E':
+ pstate = TERMINATED;
+ pc.printf("TERMINATED");
+ waitUnpress();
+ break;
+ case 'S':// start
+ if (pstate == WAIT_A_CERTAIN_KEY) {
+ pstate = MAIN_ROUTINE;
+ //printStimType();
+ pc.printf("start\n");
+ }
+ waitUnpress();
+ break;
+ case 'P':// pause
+ pstate = WAIT_A_CERTAIN_KEY;
+ pc.printf("stop\n");
+ waitUnpress();
+ break;
+ case 0x1b:
+ if(pc.getc() == 0x5b) {
+ ArrowKeyBind(pc.getc());
+ pc.printf("Hight:%d\n",ph);//sc.getPH());
+ }
+ waitUnpress();
+ break;
+ default:
+ printKBManual();
+ pc.printf("Sent data was: %d(%c)\n", sig, sig);
+ waitUnpress();
+ break;
+ }
+ //aktk_keylock = UNLOCK;
+ } else if (sig == 0x1B) //esc
+ aktk_keylock = UNLOCK;
+}
+
void waitUnpress()
{
while (1) {
@@ -14,6 +111,7 @@
}
}
}
+
template<typename T>
int scanValue(T* arg_val)
{
@@ -85,143 +183,72 @@
//int scanValue<double>(double*);
//int scanValue<unsigned short>(unsigned short*);
-void keyBind()
+void setPulseParam()
{
- char sig = pc.getc();
- if (aktk_keylock == UNLOCK) {
- aktk_keylock = LOCK;
- switch(sig) {
- case 'p':
- printStatus();
- waitUnpress();
- break;
- case 'v': {
- int sv_state;
- int lph, lpp, lpw;
+ int lph, lpp, lpw;
+
+ lph = ph;//sc.getPH();
+ lpp = pp;//sc.getPP();
+ lpw = pw;//sc.getPW();
- //printStimType();
- lph = ph;//sc.getPH();
- lpp = pp;//sc.getPP();
- lpw = pw;//sc.getPW();
- for (int i = 0; i < 3; i++) {
- switch (i) {
- case 0:
- pc.printf("set pulse Height:");
- sv_state = scanValue<int>(&lph);
- if(sv_state)goto BreakV;
- break;
- case 1:
- pc.printf("set pulse period:");
- sv_state = scanValue<int>(&lpp);
- if(sv_state)goto BreakV;
- break;
- case 2:
- pc.printf("set pulse width :");
- sv_state = scanValue<int>(&lpw);
- if(sv_state)goto BreakV;
- break;
- }
- }
- //sc.setWaveParam(lph,lpp,lpw);
- ph = lph;
- pp = lpp;
- pw = lpw;
+ // read values
+ pc.printf("set pulse Height:");
+ if( scanValue<int>(&lph) ) goto BreakV;
+ pc.printf("set pulse period:");
+ if( scanValue<int>(&lpp) ) goto BreakV;
+ pc.printf("set pulse width :");
+ if( scanValue<int>(&lpw) ) goto BreakV;
+
+ // set values
+ ph = lph;
+ pp = lpp;
+ pw = lpw;
BreakV:
- waitUnpress();
- break;
- }
-
-
- case 'a': //switch mbed-pc communication on/off
- //pstate = OnOff(!pstate);
- if (pstate == MAIN_ROUTINE) {
- pstate = WAIT_A_CERTAIN_KEY;
- pc.printf("stop\n");
- } else if (pstate == WAIT_A_CERTAIN_KEY) {
- pstate = MAIN_ROUTINE;
- //printStimType();
- pc.printf("start\n");
- }
- waitUnpress();
- break;
- case 'E':
- pstate = TERMINATED;
- pc.printf("TERMINATED");
- break;
+ waitUnpress();
+}
- case 'S':// start
- if (pstate == WAIT_A_CERTAIN_KEY) {
- pstate = MAIN_ROUTINE;
- //printStimType();
- pc.printf("start\n");
- }
- waitUnpress();
- break;
-
- case 'P':// pause
- pstate = WAIT_A_CERTAIN_KEY;
- pc.printf("stop\n");
- waitUnpress();
- break;
-
+void ArrowKeyBind(const char arg_c)
+{
+ switch(arg_c) {
+ case 0x41 : {
+ if(ph <= 4090) //if(sc.getPH()<4000)
+ ph = ph + 5;//sc.setWaveParam(sc.getPH() + 5, sc.getPP(),sc.getPW());
+ else
+ ph = 4095;
+ pc.printf("up\n");
+ break;
+ }
+ case 0x42 : {
+ if(5 <= ph) //if(5<sc.getPH())
+ ph = ph - 5;//sc.setWaveParam(sc.getPH() - 5, sc.getPP(),sc.getPW());
+ else
+ ph = 0;//sc.setWaveParam(0, sc.getPP(),sc.getPW());
+ pc.printf("down\n");
+ break;
+ }
+ case 0x43 : {
+ if(ph <= 4045)//if(sc.getPH()<4000)
+ ph = ph + 50;//sc.setWaveParam(sc.getPH() + 50, sc.getPP(),sc.getPW());
+ else
+ ph = 4095;
+ pc.printf("shift up\n");
+ break;
+ }
+ case 0x44 : {
+ if(50 <= ph)//if(50<sc.getPH())
+ ph = ph - 50;//sc.setWaveParam(sc.getPH() - 50, sc.getPP(),sc.getPW());
+ else
+ ph = 0;//sc.setWaveParam(0, sc.getPP(),sc.getPW());
+ pc.printf("shift down\n");
+ break;
+ }
+ default: {
+ //pc.printf("default\n");
+ break;
+ }
+ }
+}
- case 0x1b: {
- if(pc.getc() == 0x5b) {
- switch(pc.getc()) {
- case 0x41 : {
- if(ph < 4095) //if(sc.getPH()<4000)
- ph = ph + 5;//sc.setWaveParam(sc.getPH() + 5, sc.getPP(),sc.getPW());
- else
- ph = 4095;
- pc.printf("up\n");
- break;
- }
- case 0x42 : {
- if(5 < ph) //if(5<sc.getPH())
- ph = ph - 5;//sc.setWaveParam(sc.getPH() - 5, sc.getPP(),sc.getPW());
- else
- ph = 0;//sc.setWaveParam(0, sc.getPP(),sc.getPW());
- pc.printf("down\n");
- break;
- }
- case 0x43 : {
- if(ph < 4095)//if(sc.getPH()<4000)
- ph = ph + 50;//sc.setWaveParam(sc.getPH() + 50, sc.getPP(),sc.getPW());
- else
- ph = 4095;
- pc.printf("shift up\n");
- break;
- }
- case 0x44 : {
- if(50 < ph)//if(50<sc.getPH())
- ph = ph - 50;//sc.setWaveParam(sc.getPH() - 50, sc.getPP(),sc.getPW());
- else
- ph = 0;//sc.setWaveParam(0, sc.getPP(),sc.getPW());
- pc.printf("shift down\n");
- break;
- }
- default: {
- //pc.printf("default\n");
- break;
- }
- }
- }
- pc.printf("Hight:%d\n",ph);//sc.getPH());
- waitUnpress();
- break;
- }
-
- default:
- printKBManual();
- pc.printf("Sent data was: %d(%c)\n", sig, sig);
-
- waitUnpress();
- break;
- }
-
- } else if (sig == 0x1B) //esc
- aktk_keylock = UNLOCK;
-}
void printKBManual(void)
{
pc.printf( "\n"
@@ -234,6 +261,13 @@
" right: pulse hight +50\n"
" left: pulse hight -50\n"
" ---\n"
+ " w: Wide condition\n"
+ " n: Narrow condition\n"
+ " ---\n"
+ " mb: Bipolar stimulation\n"
+ " ma: Anodic Stimulation\n"
+ " mc: Cathodic Stimulation\n"
+ " ---\n"
" p: print wave parameter\n"
" ---\n"
" a: Start or Pause main loop\n"