Bayley Wang
/
pyroflex_AND
control the laser with the MBED
Diff: main.cpp
- Revision:
- 1:d42ef49f54df
- Parent:
- 0:5d2320fc9350
--- a/main.cpp Mon Nov 11 02:53:52 2019 +0000 +++ b/main.cpp Mon Nov 11 03:38:40 2019 +0000 @@ -1,4 +1,9 @@ #include "mbed.h" +#include "CommandProcessor.h" +#include "prefs.h" + +float __float_reg[64]; +int __int_reg[64]; DigitalOut led(LED1); InterruptIn in(PA_10); @@ -6,8 +11,38 @@ Serial pc(USBTX, USBRX); +char linebuf[128]; +int index = 0; +void rxCallback() { + while (pc.readable()) { + char c = pc.getc(); + if (c != 127 && c != 8 && c != '\r' && c != '\t') { + linebuf[index] = c; + if (index < 127) index++; + if (c < 128) pc.putc(c); + } else if (c == 127 || c == 8) { + if (index > 0) { + index--; + //BS (8) should delete previous char + pc.putc(127); + } + } else if (c == '\r') { + linebuf[index] = 0; + if (index > 0) { + pc.putc(c); + processCmd(&pc, linebuf); + pc.putc('>'); + } else { + pc.putc(c); + pc.putc('>'); + } + index = 0; + } + } +} + void turn_on() { - out.pulsewidth_us(2); + out.pulsewidth_us(_PULSE_WIDTH); led = 1; } @@ -17,9 +52,15 @@ } int main() { + pc.baud(115200); + pc.attach(rxCallback); pc.printf("PYROFLEX\n"); + cmd_clear(&pc); + cmd_defaults(&pc); + pc.printf(">"); + out.period_us(10); - out.pulsewidth_us(2); + out.pulsewidth_us(_PULSE_WIDTH); in.rise(turn_on); in.fall(turn_off);