Swimate V2 without RTOS code

Dependencies:   Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL

Files at this revision

API Documentation at this revision

Comitter:
ellingjp
Date:
Sun Jun 08 04:08:41 2014 +0000
Parent:
22:9350752f5414
Child:
24:f2503d1256ad
Commit message:
Working with new oled using hacks

Changed in this revision

log_data.cpp 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
main.h Show annotated file Show diff for this revision Revisions of this file
sync.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/log_data.cpp	Sat Jun 07 07:46:38 2014 +0000
+++ b/log_data.cpp	Sun Jun 08 04:08:41 2014 +0000
@@ -3,14 +3,11 @@
 #include "SDFileSystem.h"
 #include "helper_3dmath.h"
 #include "debug.h"
-<<<<<<< local
 #include "SystemTime.h"
-=======
->>>>>>> other
 #include "pins.h"
 
 // SD Card
-SDFileSystem sd(P0_21, P0_22, P1_15, P1_19, "sd"); // MOSI, MISO, SCLK, SSEL SPI1
+SDFileSystem sd(P0_9, P0_8, P0_10, P1_19, "sd"); // MOSI, MISO, SCLK, SSEL SPI1
 
 // DS3231 rtc(I2C_SDA, I2C_SCL);
 
--- a/main.cpp	Sat Jun 07 07:46:38 2014 +0000
+++ b/main.cpp	Sun Jun 08 04:08:41 2014 +0000
@@ -1,7 +1,10 @@
+#define NDEBUG
+#define USE_OLED
+
 #include "main.h"
 #include "mbed.h"
 #include "PinDetect.h"
-#include "USBSerial.h"
+//#include "USBSerial.h"
 #include "Adafruit_SSD1306.h"
 #include "SDFileSystem.h"
 #include "receive_data.h"
@@ -11,18 +14,22 @@
 #include "SystemTime.h"
 #include "sync.h"
 #include "pins.h"
-//#include "DS3231.h"
+#include "DS3231.h"
+
+#define X_POS(x) (32 + x%64)
+#define Y_POS(y) (16 + y%48)
 
 // Capture button stuff
 #define PIN_DETECT_SAMPLE_PERIOD_uS 20000   // 20 ms sample period
 #define SYNC_HELD_SAMPLES   (SYNC_HOLD_TIME_MS * 1000 / PIN_DETECT_SAMPLE_PERIOD_uS)
 
+
 #ifdef USE_OLED
-    SPI spi0(P0_9, NC, P0_10); // mosi, miso, sclk
+    SPI spi0(P0_9, P0_8, P0_10); // mosi, miso, sclk
     Adafruit_SSD1306 oled(spi0, P0_11, P0_12, P0_13); // DC, RST, CS
 #endif
 
-// DS3231 rtc(I2C_SDA, I2C_SCL);
+DS3231 rtc(I2C_SDA, I2C_SCL);
 
 // Mode button
 PinDetect captureButton(P0_16, PullUp);
@@ -76,44 +83,48 @@
     while (true) {
         if (State == IDLE){
             OLED_CLEAR();
-            OLED_PRINTP("Idling...", 0, 0);
+            OLED_PRINTP("Idling...", X_POS(0), Y_POS(20));
             PC_PRINTLN("Idling...");
+                
         } else if (State == CAPTURE) {
-            OLED_PRINTP("Starting capture...", 0, 0);
-            OLED_PRINTP("Init SD card...", 0, 10);
-            log_init();
-            OLED_PRINTP("Init peak detect...", 0, 10);
-            process_init();
-            OLED_PRINTP("Init data receipt...", 0, 10);
-            receive_init();           
-            OLED_CLEAR();
-            OLED_PRINTP("Capturing data...", 0, 0);
+            OLED_PRINTP("Starting capture...", X_POS(0), Y_POS(20));
+//            OLED_PRINTP("Init SD card...", 0, 10);
+//            log_init();
+//            OLED_PRINTP("Init peak detect...", 0, 10);
+//            process_init();
+//            OLED_PRINTP("Init data receipt...", 0, 10);
+//            receive_init();           
+//            OLED_CLEAR();
+//            OLED_PRINTP("Capturing data...", 0, 0);
             
             captureTimer.start();
             while (State == CAPTURE) {
                 data = receive_data();
-                log_data(captureTimer.read_ms(), data);
+                PC_PRINTF("x: %d ", data->x);
+                PC_PRINTF("y: %d ", data->y);
+                PC_PRINTF("z: %d ", data->z);
+//                log_data(captureTimer.read_ms(), data);
 
                 int split;
                 if (process_data((int) (data->x), (int) (data->y), &split)) {
                     PC_PRINTLNF("Peak time: %d", split);
                     
-                    int min = split / 60000;
-                    int sec = (split / 1000) % 60;
-                    int hund = (split / 10) % 100;
+                    int min = 47; //split / 60000;
+                    int sec = 32; //(split / 1000) % 60;
+                    int hund = 9; //(split / 10) % 100;
                     
-//                    OLED_PRINTPF("%1d", min, 0, 40);
-//                    OLED_PRINTPF("%02d", sec, 5, 40);
-//                    OLED_DRAWPIXEL(14, 44, 0x1);
-//                    OLED_PRINTPF("%02d", hund, 15, 40);
-                    log_data(captureTimer.read_ms(), split);
+                    OLED_PRINTPF("%1d", min, 0, 40);
+                    OLED_PRINTPF("%02d", sec, 5, 40);
+                    OLED_DRAWPIXEL(14, 44, 0x1);
+                    OLED_PRINTPF("%02d", hund, 15, 40);
+//                    log_data(captureTimer.read_ms(), split);
                 }
             }
             captureTimer.stop();
             captureTimer.reset();
             receive_close();
             process_close();
-            log_close();
+//            log_close();
         } else if (State == SYNC) {
             OLED_PRINTP("Ready to sync...", 0, 0);
             sync_init();
--- a/main.h	Sat Jun 07 07:46:38 2014 +0000
+++ b/main.h	Sun Jun 08 04:08:41 2014 +0000
@@ -6,14 +6,14 @@
 
 #include "Adafruit_SSD1306.h"
 
-// #define USE_OLED
+#define USE_OLED
 #ifdef USE_OLED
 
     extern SPI spi0; // mosi, miso, sclk
     extern Adafruit_SSD1306 oled; // DC, RST, CS
 
     #define OLED_SETCURS(xpos,ypos) oled.setCursor(xpos,ypos);
-    #define OLED_CLEAR() oled.clearDisplay();
+    #define OLED_CLEAR() oled.clearDisplay(); oled.display();
     
     #define OLED_DRAWPIXEL(x,y,color) oled.drawPixel(x, y, color);
     
--- a/sync.cpp	Sat Jun 07 07:46:38 2014 +0000
+++ b/sync.cpp	Sun Jun 08 04:08:41 2014 +0000
@@ -115,8 +115,6 @@
     }
 
     delete res;
-
-    uint8_t *d = new uint8_t[PACKET_MAX_DATA];
     
     PC_PRINTLN("sendFile: created buffer");
     int len;
@@ -268,7 +266,7 @@
             PC_PRINTLN("Received bad packet :(");
             continue;
         }
-
+#ifdef DEBUG
         PC_PRINTLNF("cmd: %x", p->cmd);
         PC_PRINTLNF("pnum: %x", p->packetNumber);
         PC_PRINTLNF("len: %x", p->dataLength);
@@ -277,6 +275,7 @@
             PC_PRINTLNF("%x", p->data[i]);
         }
         PC_PRINTLNF("check: %x", p->checkSum);
+#endif
 
         switch(p->cmd) {
             case CMD_SYNCOLDEST:
@@ -299,11 +298,11 @@
 //                case CMD_DELETESESSION:
 //                    deleteSession();
 //                    break;
-//                case CMD_DONE:
-//                    bt.putc(CMD_DONE);
-//                    //sendResponse(CMD_DONE, ACK);
-//                    State = IDLE;
-//                    break;
+                case CMD_DONE:
+                    Packet *p = Packet::create(ACK, 0, 0, NULL);
+                    btComm.sendPacket(p);
+                    State = IDLE;
+                    break;
 //                default: break;
         }