copy

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
brainliang
Date:
Wed Nov 20 12:27:02 2019 +0000
Parent:
1:8b32bcbc712a
Commit message:
copy

Changed in this revision

SYN6288.cpp Show annotated file Show diff for this revision Revisions of this file
SYN6288.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SYN6288.cpp	Wed Nov 20 12:27:02 2019 +0000
@@ -0,0 +1,46 @@
+#include "SYN6288.h"
+void voice_play(std::string value, Serial* ser)
+{
+	voice_play(value.c_str(), ser);
+}
+void voice_play(char* value, Serial* ser) {
+    int size = strlen(value);
+    int data_length = 1+2+1+1+size;
+    int* data = (int*)malloc(sizeof(int)*(data_length+1));
+    
+    int start = 0xfd;
+    int length = size + 3;
+    int length_h = length / 256;
+    int length_l = length % 256;
+    int command = 0x01;
+    int param = 0x01;
+    
+    data[0] = start;
+    data[1] = length_h;
+    data[2] = length_l;
+    data[3] = command;
+    data[4] = param;
+ 
+    for (int i=5; i<5+size; i++) {
+        data[i] = value[i-5];
+    }
+ 
+    // calculate check bit
+    int check_bit = data[0];
+    for (int i=1; i<data_length; i++) {
+        check_bit ^= data[i];
+    }   
+    data[data_length] = check_bit;
+ 
+    for (int i=0; i<=data_length; i++) {
+        ser->putc(data[i]);
+    }
+    
+    free(data);
+    
+    //int recv = ser->getc();
+    //PC.printf("%c", recv);
+    //int done = ser->getc();
+    //PC.printf("%c", done);   
+}
+
--- a/SYN6288.h	Wed Nov 13 11:40:28 2019 +0000
+++ b/SYN6288.h	Wed Nov 20 12:27:02 2019 +0000
@@ -1,45 +1,9 @@
+#ifndef SYN6288_MODULE_
+#define SYN6288_MODULE_
+#include "mbed.h"
+#include "string.h"
 #include <string>
-typedef bool boolean;
-typedef std::string String;
+void voice_play(char* value, Serial* ser);
+void voice_play(std::string value, Serial* ser);
+#endif
 
-void voice_play(String value_, Serial* ser) {
-    const char* value = value_.c_str();
-    int size = strlen(value);
-    int data_length = 1+2+1+1+size;
-    int* data = (int*)malloc(sizeof(int)*(data_length+1));
-    
-    int start = 0xfd;
-    int length = size + 3;
-    int length_h = length / 256;
-    int length_l = length % 256;
-    int command = 0x01;
-    int param = 0x01;
-    
-    data[0] = start;
-    data[1] = length_h;
-    data[2] = length_l;
-    data[3] = command;
-    data[4] = param;
- 
-    for (int i=5; i<5+size; i++) {
-        data[i] = value[i-5];
-    }
- 
-    // calculate check bit
-    int check_bit = data[0];
-    for (int i=1; i<data_length; i++) {
-        check_bit ^= data[i];
-    }   
-    data[data_length] = check_bit;
- 
-    for (int i=0; i<=data_length; i++) {
-        ser->putc(data[i]);
-    }
-    
-    free(data);
-    
-    //int recv = ser->getc();
-    //PC.printf("%c", recv);
-    //int done = ser->getc();
-    //PC.printf("%c", done);   
-}
\ No newline at end of file
--- a/main.cpp	Wed Nov 13 11:40:28 2019 +0000
+++ b/main.cpp	Wed Nov 20 12:27:02 2019 +0000
@@ -8,7 +8,7 @@
 
 String str;
 
-Serial syn6288_Serial_2(PA_2,PA_3);
+Serial syn6288_Serial_2(PA_9,PA_10);
 
 int main() {