Suga koubou / MelInverter

Dependents:   MelInverter_sample

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Fri Sep 28 03:28:47 2012 +0000
Parent:
1:5963d2a1c30f
Commit message:
fix baud

Changed in this revision

MelInverter.cpp Show annotated file Show diff for this revision Revisions of this file
MelInverter.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5963d2a1c30f -r b1ef1c4d9c12 MelInverter.cpp
--- a/MelInverter.cpp	Tue Sep 18 14:30:22 2012 +0000
+++ b/MelInverter.cpp	Fri Sep 28 03:28:47 2012 +0000
@@ -16,8 +16,8 @@
 #include "mbed.h"
 #include "MelInverter.h"
 
-MelInverter::MelInverter (PinName p_tx, PinName p_rx) : _mel(p_tx, p_rx), _buf_data(40) {
-    _mel.baud(19200);
+MelInverter::MelInverter (PinName p_tx, PinName p_rx, int baud) : _mel(p_tx, p_rx), _buf_data(40) {
+    _mel.baud(baud);
     _mel.format(8, Serial::Even, 2);
     _mel.attach(this, &MelInverter::isr_mel, Serial::RxIrq);
 }
@@ -153,6 +153,8 @@
     char buf[40];
     Timer timer;
 
+    _mel_ok = 0;
+    _mel_failure = 0;
     _mel.putc(INVCTRL_ENQ);
     sprintf(buf, "%02X%02X%01X", iid, cmd, MELDELAY);
     strncat(buf, data, 20);
@@ -172,7 +174,8 @@
         }
     }
     timer.stop();
-    return (_mel_ok == 1);
+    DBG("ok\r\n");
+    return _mel_ok == 1 ? 0 : -1;
 }
 
 int MelInverter::recv (int iid, char *buf, int len) {
diff -r 5963d2a1c30f -r b1ef1c4d9c12 MelInverter.h
--- a/MelInverter.h	Tue Sep 18 14:30:22 2012 +0000
+++ b/MelInverter.h	Fri Sep 28 03:28:47 2012 +0000
@@ -17,6 +17,7 @@
 
 #define MELDELAY 0
 #define MELTIMEOUT 100
+#define MELBAUD 19200
 
 enum MELCMD {
     MELCMD_MODE_R = 0x7b,
@@ -59,7 +60,7 @@
     /**
      * Default constructor
      */
-    MelInverter (PinName p_tx, PinName p_rx);
+    MelInverter (PinName p_tx, PinName p_rx, int baud = MELBAUD);
 
     int send (int iid, MELCMD, char *data);
 
@@ -78,7 +79,7 @@
     MELMODE _mel_mode;
     RingBuffer _buf_data;
     Timeout _res;
-    int _iid;
+    volatile int _iid;
 
 };