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.
Dependencies: LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile
Diff: main.cpp
- Revision:
- 7:09354ea16403
- Parent:
- 6:005ff6a49217
- Child:
- 8:057ff6060e39
diff -r 005ff6a49217 -r 09354ea16403 main.cpp
--- a/main.cpp Sat Dec 12 22:55:44 2015 +0000
+++ b/main.cpp Sat Dec 12 23:10:09 2015 +0000
@@ -73,7 +73,66 @@
//SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
SDFileSystem sd(PB_5, PB_4, PB_3, PC_11, "sd"); // mosi, miso, sclk, cs
-
+
+DigitalOut skywire_en(PA_6);
+//DigitalOut skywire_rts(PA_7);
+Serial skywire(PA_0,PA_1);
+
+volatile int rx_in=0;
+volatile int rx_out=0;
+const int buffer_size = 255;
+char rx_buffer[buffer_size+1];
+char rx_line[buffer_size];
+
+void read_line()
+{
+ int i;
+ i = 0;
+// Start Critical Section - don't interrupt while changing global buffer variables
+ __disable_irq();
+// Loop reading rx buffer characters until end of line character
+ while ((i==0) || ((rx_line[i-1] != '\r') && (rx_line[i-1] != '\n'))) {
+// Wait if buffer empty
+ if (rx_in == rx_out) {
+// End Critical Section - need to allow rx interrupt to get new characters for buffer
+ __enable_irq();
+ while (rx_in == rx_out) {
+ }
+// Start Critical Section - don't interrupt while changing global buffer variables
+ __disable_irq();
+ }
+ rx_line[i] = rx_buffer[rx_out];
+ i++;
+ rx_out = (rx_out + 1) % buffer_size;
+ }
+// End Critical Section
+ __enable_irq();
+ rx_line[i-1] = 0;
+ return;
+}
+
+int WaitForResponse(char* response)
+{
+ do {
+ do {
+ read_line();
+ } while ((unsigned char)rx_line[0] <= 32);
+// debug_pc.printf("Waiting for: %s, Received: %s\r\n", response, rx_line);
+ } while (strncmp(rx_line, response, strlen(response)));
+ return 0;
+}
+
+void Skywire_Rx_interrupt()
+{
+// Loop just in case more than one character is in UART's receive FIFO buffer
+// Stop if buffer full
+ while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
+ rx_buffer[rx_in] = skywire.getc();
+ rx_in = (rx_in + 1) % buffer_size;
+ }
+ return;
+}
+
int main()
{
/* int stage=0;
@@ -436,14 +495,61 @@
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(0,10);
TFT.foreground(White);
- for(int e=0; e<10; e++) {
- if ((mselog[e]>0) && (mselog[e]!= NULL)) {
- TFT.printf("%s MSE: %f\n\n", log[e], mselog[e]);
+
+
+ //Configure CRC, large frames, and write validation for SD Card
+ sd.crc(true);
+ sd.large_frames(true);
+ sd.write_validation(true);
+
+ //Try to mount the SD card
+ TFT.locate(10,50);
+ TFT.printf("Mounting SD card...");
+ TFT.locate(10,60);
+ int row = 50;
+ int col = 10;
+ TFT.locate(10,row); TFT.printf("Mounting SD card..."); row+=10;
+ if (sd.mount() != 0) {
+ TFT.printf("failed!");
+ TFT.locate(10,row); TFT.printf("failed!"); row+=10;
+ } else {
+ TFT.printf("mounted successfully!\r\n");
+ TFT.locate(10,row); TFT.printf("mounted successfully"); row+=10;
+
+ // write event to log
+ TFT.locate(10,70);
+ FILE *fp = fopen("/sd/event_log.txt", "a");
+ if (fp != NULL) {
+ fprintf(fp, "eureka!\r\n");
+ fclose(fp);
+ TFT.printf("success!\n");
+ TFT.locate(10,row); TFT.printf("success"); row+=10;
+ } else {
+ TFT.printf("failed!\n");
+ TFT.locate(10,row); TFT.printf("failed to write"); row+=10;
}
+ sd.unmount();
}
+
+ TFT.locate(10,row); TFT.printf("Configuring Skywire"); row+=10;
+ skywire.baud(115200);
+ skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq);
+
+ //Turn off echo
+ skywire.printf("ATE0\r\n");
+ WaitForResponse("OK");
+ TFT.locate(10,row); TFT.printf("Connecting to the Network"); row+=10;
+ // get IP address
+ skywire.printf("AT#SGACT=1,1\r\n"); // context activation (returns with IP address)
+ WaitForResponse("#SGACT");
+ WaitForResponse("OK");
+
+
+
TFT.locate(165,270);
printf("Return");
TFT.rect(150,265,220,285,Green);
+
ps = ain3.read();
if (ps==1) {
wait(0.5);