
Interference current stimulation program with kaji-lab ES device.
Dependencies: mbed SerialInputReactionHandler AMPulseTrain SwArr16MOSFET StrCommandHandler KajiLabES
Revision 1:b97639dad576, committed 2019-10-23
- Comitter:
- aktk
- Date:
- Wed Oct 23 20:08:31 2019 +0000
- Parent:
- 0:19a67422961f
- Child:
- 2:5cb68cc8ecaa
- Commit message:
- used at VRSJ24 DEMO
Changed in this revision
--- a/KajiLabES.lib Tue Oct 23 15:11:18 2018 +0000 +++ b/KajiLabES.lib Wed Oct 23 20:08:31 2019 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/aktk/code/KajiLabES/#9b21e855a577 +https://developer.mbed.org/users/aktk/code/KajiLabES/#ade25cdffd15
--- a/PMRC16ch.lib Tue Oct 23 15:11:18 2018 +0000 +++ b/PMRC16ch.lib Wed Oct 23 20:08:31 2019 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/aktk/code/PMRC4ch/#fa067e2a30f2 +https://os.mbed.com/users/aktk/code/PMRC16ch/#03e875137433
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialCom/CommandHandler.h Wed Oct 23 20:08:31 2019 +0000 @@ -0,0 +1,25 @@ +#ifndef COMMAND_HANDLER_H +#define COMMAND_HANDLER_H +#include "mbed.h" +#include <string> +#include <unsorted_map> + +class CommandAnalyzer +{ +public: + CommandAnalyzer( + int num_of_command = 10, + char response_mode = 0 + ); + int analyzeCommand( + const char* const command + ); + int mapCommand( + const char* const command + int (*fanction)(void) + ); +private: + char (*m_command_name)[20]; + int (**m_function)(void); +} +#endif \ No newline at end of file
--- 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"
--- a/SerialCom/sigbind.h Tue Oct 23 15:11:18 2018 +0000 +++ b/SerialCom/sigbind.h Wed Oct 23 20:08:31 2019 +0000 @@ -8,8 +8,6 @@ // prototype void keyBind(); void printKBManual(void); -//void printStimType(); -void printStatus(void); } extern uint32_t pw, pp, ph; @@ -21,4 +19,12 @@ enum ProcessState {WAIT_A_CERTAIN_KEY, MAIN_ROUTINE, TERMINATED}; extern ProcessState pstate; +enum ElectrodeSpacing {WIDE_CONDITION, NARROW_CONDITION}; +extern ElectrodeSpacing spacing; + +enum StimulationMode {BIPOLAR, ANODIC, CATHODIC}; +extern StimulationMode smode; + +#include "KajiLabES.h" +extern KajiLabES stimulator; #endif \ No newline at end of file
--- a/main.cpp Tue Oct 23 15:11:18 2018 +0000 +++ b/main.cpp Wed Oct 23 20:08:31 2019 +0000 @@ -4,7 +4,9 @@ #include "sigbind.h" #include <iostream> #include <bitset> -ProcessState pstate; +ProcessState pstate = WAIT_A_CERTAIN_KEY; +ElectrodeSpacing spacing = WIDE_CONDITION; +StimulationMode smode = BIPOLAR; Serial pc(USBTX, USBRX); // tx, rx DigitalOut myled1(LED1); @@ -19,7 +21,7 @@ int main() { - stimulator.DAADinit(); + stimulator.init(); myled1 = 1; pmrc.allHiZ(); myled2 = 1; @@ -41,9 +43,29 @@ myled3 = 1; pmrc.setPol(PMRC16ch::Cathodic); while (pstate == MAIN_ROUTINE) { + + for (int i = 0; i < 2; i++) { + switch(smode){ + case BIPOLAR: pmrc.setPol((PMRC16ch::Polarity)i); break; + case CATHODIC: pmrc.setPol(PMRC16ch::Cathodic); break; + case ANODIC: pmrc.setPol(PMRC16ch::Anodic); break; + } + if(spacing == WIDE_CONDITION) + //pmrc.setTrio(3,1,5); + pmrc.setTwin(1, 2); + else + //pmrc.setTrio(3,2,4); + pmrc.setTwin(1, 3); + wait_us(pp-pw); + stimulator.DAAD(ph); + wait_us(pw); + stimulator.DAAD(0); + } + /* for(int i = 0; i < 2; i++) { - //pmrc.setTwin(i+1, (i+4)%8+1); pmrc.setTwin(i+1, (i+1)%8+1); + //pmrc.setTwin(i+1, (i+1)%8+1); + //pmrc.setTwin(i+1, (i+1)%8+1); //pmrc.setOvsO(i+1); wait_us(pp-pw); stimulator.DAAD(ph); @@ -52,6 +74,7 @@ //pmrc.allHiZ(); //wait_us(pw); } + */ if (pstate == TERMINATED) break; } }