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.
Diff: Picaso_4DGL-32PTU_main.cpp
- Revision:
- 5:890ddd974624
- Parent:
- 4:50511ed54ab4
- Child:
- 6:a1a85f2bc04b
--- a/Picaso_4DGL-32PTU_main.cpp Fri Sep 09 12:45:28 2016 +0000
+++ b/Picaso_4DGL-32PTU_main.cpp Mon Sep 12 10:15:54 2016 +0000
@@ -24,9 +24,11 @@
//******************************************************************************************************
PICASO_4DGL :: PICASO_4DGL(PinName tx, PinName rx, PinName rst) : pc(USBTX, USBRX), _cmd(tx, rx), _rst(rst) { // Constructor
- rxBuf[bufLen]; // create buffer
-
- responseBuild(10);
+ rxBuf[RXBUFLEN] = 0; // create buffer
+ index = 0;
+ //trig = 0;
+ _cmd.attach(this, &PICASO_4DGL::rxCallback, Serial::RxIrq); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //responseBuild(10);
#if DEBUGMODE
pc.baud(115200);
@@ -69,10 +71,19 @@
}
//******************************************************************************************************
-void PICASO_4DGL :: responseBuild(int size) {
+void PICASO_4DGL :: rxCallback() {
- response[size] = 0;
- respLen = 0;
+ while(1) {
+ if(_cmd.readable()) {
+ //pc.printf("\n\n\r CALLBACK %02X\n\n\r", _cmd.getc());
+ //ack = 1;
+ //pc.printf("\n\r INDEX = %i\n\r", index);
+ rxBuf[index++] = _cmd.getc();
+ //trig = 1;
+ break;
+ }
+ pc.printf("\n\r...PSC...\n\r");
+ }
}
//******************************************************************************************************
@@ -105,8 +116,6 @@
freeBUFFER();
for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port
-
- getResponse();
}
//**************************************************************************
@@ -229,29 +238,22 @@
for (i = 0; i <4; i++) writeBYTE(command[i]); // send command to serial port
_cmd.baud(speed); // set mbed to same speed
- getResponse();
+ getResponse(1);
}
//**************************************************************************
-void PICASO_4DGL :: getResponse() {
+void PICASO_4DGL :: getResponse(int count) {
+
+ pc.printf("\n\r Wait for answer...");
+ while (index < count) wait_ms(100); // wait for screen answer
- //clearResponse();
- int k = 0, temp = 0, resp = 0;
- char response[1] = "";
-
- while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
-
- while (_cmd.readable()) {
- // temp = ;
- response[resp++] = _cmd.getc();
+ pc.printf("\n\r INDEX = %i\n\r", index);
+ pc.printf("\n\r Answer = ");
+ for (int i = 0; i < index; i++) {
+ pc.printf("%02X ", rxBuf[i]);
}
-
- pc.printf("\n\r RESP = %d\n\r", resp);
- while (k < resp) {// print everything
- pc.printf(" Response: %02X ", response[k++]);
- }
pc.printf("\n\r");
-
+ index = 0;
}
//**************************************************************************
@@ -284,10 +286,5 @@
}
writeCOMMAND(command, 4);
+ getResponse(3);
}
-
-//**************************************************************************
-void PICASO_4DGL :: clearResponse() {
- for (int i = 0; i < 10; i++)
- response[i] = '0';
-}
\ No newline at end of file