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:
- 21:2fa676f214fe
- Parent:
- 15:002bac432234
- Child:
- 22:9350752f5414
diff -r 002bac432234 -r 2fa676f214fe main.cpp
--- a/main.cpp Thu Jun 05 19:03:42 2014 +0000
+++ b/main.cpp Sat Jun 07 07:12:25 2014 +0000
@@ -10,17 +10,20 @@
#include "debug.h"
#include "SystemTime.h"
#include "sync.h"
+#include "pins.h"
+//#include "DS3231.h"
// 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
-// Display
-SPI spi0(P0_9, NC, P0_10); // mosi, miso, sclk
-Adafruit_SSD1306 oled(spi0, P0_11, P0_12, P0_13); // DC, RST, CS
+ SPI spi0(P0_9, NC, 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);
+
// Mode button
PinDetect captureButton(P0_16, PullUp);
@@ -28,6 +31,8 @@
enum state {IDLE, CAPTURE, SYNC};
enum state State;
+Timer captureTimer;
+
// This is used to ensure the rising edge after a hold is ignored
bool ignore_edge = false;
void buttonHeld() {
@@ -84,34 +89,35 @@
OLED_CLEAR();
OLED_PRINTP("Capturing data...", 0, 0);
-
+ captureTimer.start();
while (State == CAPTURE) {
data = receive_data();
- log_data(data);
+ log_data(captureTimer.read_ms(), data);
+
int split;
- if (process_data(data->y, &split)) {
- PC_PRINTLNF("Split time: %d", 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;
- 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(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();
} else if (State == SYNC) {
OLED_PRINTP("Ready to sync...", 0, 0);
sync_init();
- while (State == SYNC)
- sync();
+ sync();
}
}
}