PES 4 - Smart Medication Dispenser / PES4_ProgrammeforDesignReview2

Dependencies:   SDFileSystem mbed

Fork of PES4_Programme by PES 4 - Smart Medication Dispenser

Revision:
69:ec1cfc0cd161
Parent:
61:086bcd5ca968
Parent:
63:be13158bb4dd
Child:
70:cc7ed2325202
--- a/source/main.cpp	Thu Apr 05 20:35:23 2018 +0000
+++ b/source/main.cpp	Fri Apr 06 06:25:36 2018 +0000
@@ -3,6 +3,7 @@
 #define     DEMOTIME    5
 
 int state = 44;
+
 int oldState;
 
 Serial pc(USBTX, USBRX); // tx, rx
@@ -13,6 +14,32 @@
 DigitalIn   glasDetection(PA_10);
 PwmOut      summer(PC_8);
 
+// Circular buffers for serial TX and RX data - used by interrupt routines
+const int buffer_size = 255;
+// might need to increase buffer size for high baud rates
+char tx_buffer[buffer_size+1];
+char rx_buffer[buffer_size+1];
+// Circular buffer pointers
+// volatile makes read-modify-write atomic
+volatile int tx_in=0;
+volatile int tx_out=0;
+volatile int rx_in=0;
+volatile int rx_out=0;
+// Line buffers for sprintf and sscanf
+char tx_line[80];
+char rx_line[80];
+
+int i=0;
+int rx_i=0;
+/*
+// Setup a serial interrupt function to receive data
+pc.attach(&Rx_interrupt, Serial::RxIrq);
+// Setup a serial interrupt function to transmit data
+pc.attach(&Tx_interrupt, Serial::TxIrq);
+*/
+
+
+
 /* PWM Test Tool */
 int channel;
 int dutyCycle;
@@ -56,9 +83,43 @@
                 break;
             case 3:
                 break;
-
+/*
             case 10:
+                // Formatted IO test using send and receive serial interrupts
+                // with sprintf and sscanf
+                while (1) {
+                    // Loop to generate different test values - send value in hex, decimal, and octal and  then read back
+                    for (i=0; i<0xFFFF; i++) {
+                        // Print ASCII number to tx line buffer in hex
+                        sprintf(tx_line,"%x\r\n",i);
+                        // Copy tx line buffer to large tx buffer for tx interrupt routine
+                        send_line();
+                        // Print ASCII number to tx line buffer in decimal
+                        sprintf(tx_line,"%d\r\n",i);
+                        // Copy tx line buffer to large tx buffer for tx interrupt routine
+                        send_line();
+                        // Print ASCII number to tx line buffer in octal
+                        sprintf(tx_line,"%o\r\n",i);
+                        // Copy tx line buffer to large tx buffer for tx interrupt routine
+                        send_line();
+
+                        // Read a line from the large rx buffer from rx interrupt routine
+                        read_line();
+                        // Read ASCII number from rx line buffer
+                        sscanf(rx_line,"%x",&rx_i);
+                        // Read a line from the large rx buffer from rx interrupt routine
+                        read_line();
+                        // Read ASCII number from rx line buffer
+                        sscanf(rx_line,"%d",&rx_i);
+                        // Read a line from the large rx buffer from rx interrupt routine
+                        read_line();
+                        // Read ASCII number from rx line buffer
+                        sscanf(rx_line,"%o",&rx_i);
+                    }
+                }
                 break;
+                
+                */
             case 11:
                 break;