Maxim Integrated / Mbed OS MAX1473_RF_Receiver_Demo

Dependencies:   max32630fthr USBDevice

Revision:
10:aec2b8ba06a0
Parent:
9:02c5adb483c8
Child:
11:72363a906638
--- a/main.cpp	Fri Sep 27 21:02:41 2019 +0000
+++ b/main.cpp	Fri Aug 14 19:18:42 2020 +0000
@@ -33,41 +33,101 @@
 #include "mbed.h"
 #include "max32630fthr.h"
 #include "USBSerial.h"
+#include "MAX30208.h"
+#include "ForwardErrCorr.h"
 
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
 
 // Hardware serial port over DAPLink
 Serial daplink(USBTX, USBRX);          // Use USB debug probe for serial link
 Serial uart(P2_1, P2_0);
+RawSerial uart2(P3_1,P3_0);//tx,rx
+
+I2C i2c(P3_4, P3_5);  //sda,scl
+
+MAX30208 TempSensor(i2c, 0x50); //Constructor takes 7-bit slave adrs
+char  TransTable[] = {0x1F,0x18,0x06,0x01};
+Translator transRx(uart2, TransTable);
 
 // Virtual serial port over USB
 USBSerial microUSB; 
 DigitalOut rLED(LED1);
-DigitalOut gLED(LED2);
+DigitalOut gLED(LED2); 
 DigitalOut bLED(LED3);
+DigitalIn TakeData(P5_6);
+DigitalIn TakeData2(P5_5);
+DigitalIn sw1(SW1);
+
+void buildArray(int j, char *input,char *output){
+    int i = j+1;
+    int k = 0;
+    while(input[i] != 'c'){
+        output[k] = input[i];
+        i++;
+        k++;
+    }
+}
+char dataIn[50];
+
+void SerialCallback(){
+    //Timer timer;
+    //timer.start();
+    wait_ms(1);
+    int i = strlen(dataIn);
+    if (i >= 50){
+        i = 0;
+    }
+    while(uart2.readable()){
+        dataIn[i] = uart2.getc();
+        i++;
+    }
+    //wait_ms(10);
+}
 
 // main() runs in its own thread in the OS
 // (note the calls to Thread::wait below for delays)
 int main()
 {
-    int c;
-
-    daplink.printf("daplink serial port\r\n");
-    microUSB.printf("micro USB serial port\r\n");
     rLED = LED_ON;
     gLED = LED_ON;
     bLED = LED_OFF;
-
+    uart2.baud(9600);
+    uart2.attach(&SerialCallback);
     rLED = LED_OFF;
-
+    char dataOut[50];
+    uint16_t output[10];
     while(1) {
-//        c = microUSB.getc();
-//        microUSB.putc(c);
-//        daplink.putc(c);
-        daplink.printf("daplink serial port\r\n");
-        microUSB.printf("micro USB serial port\r\n");
-        bLED =  !bLED;
-        wait(2);
+        if (strlen(dataIn) >= 12){
+            int j = 0;
+            while(dataIn[j] != 'b' && j < 30){
+                j++;
+            }
+            if (dataIn[j] == 'b'){
+                microUSB.printf("\r\n\r\n\r\n\r\n");
+                buildArray(j,dataIn,dataOut);
+                microUSB.printf("\r\n");
+                if (transRx.Reconstruct(dataOut,output) == 1){
+                    microUSB.printf("Error reconstructing\r\n");
+                }
+                
+                //Print out the Device Type, ID, and Temperature
+                microUSB.printf("Device Type: %c\r\n", dataIn[j+1]);
+                microUSB.printf("Device ID: %c\r\n", dataIn[j+2]);
+                
+                //uint16_t temp1 = (output[0]<<8);
+                //uint16_t delivery = (temp1 + output[1]);
+                //float clesius = TempSensor.toCelsius(output[0]);
+                //float fare = TempSensor.toFahrenheit(clesius);
+                microUSB.printf("Data read %u\r\n",output[0]);
+                for (int i = 0;i<sizeof(dataIn);i++){
+                    dataIn[i] = 0;
+                }
+            }
+            else{
+                for (int i = 0;i<sizeof(dataIn);i++){
+                    dataIn[i] = 0;
+                }
+            }
+        }
     }
 }
-