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: Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL
Diff: main.cpp
- Revision:
- 23:80083138d609
- Parent:
- 22:9350752f5414
- Child:
- 24:f2503d1256ad
diff -r 9350752f5414 -r 80083138d609 main.cpp
--- 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();