summaryrefslogtreecommitdiff
path: root/megalogger
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-11-25 22:58:32 +1100
committerStanley Huang <stanleyhuangyc@gmail.com>2015-11-25 22:58:32 +1100
commite12fc5e3f0bec08274794f954fa114323c874e09 (patch)
tree954117daa0b414ba3c693d87cf425b89c0bd0a8a /megalogger
parent2db79aea59b9dca6c811eeb6f564b950befb8e53 (diff)
download2021-arduino-obd-e12fc5e3f0bec08274794f954fa114323c874e09.tar.gz
2021-arduino-obd-e12fc5e3f0bec08274794f954fa114323c874e09.tar.bz2
2021-arduino-obd-e12fc5e3f0bec08274794f954fa114323c874e09.zip
Add touch screen support
Diffstat (limited to 'megalogger')
-rw-r--r--megalogger/config.h1
-rw-r--r--megalogger/datalogger.h2
-rw-r--r--megalogger/megalogger.ino30
-rw-r--r--megalogger/touch.h127
4 files changed, 147 insertions, 13 deletions
diff --git a/megalogger/config.h b/megalogger/config.h
index 903387c..a8d85ff 100644
--- a/megalogger/config.h
+++ b/megalogger/config.h
@@ -62,7 +62,6 @@
**************************************/
#define OBD_MIN_INTERVAL 20 /* ms */
#define ACC_DATA_INTERVAL 200 /* ms */
-#define GUI_PID_LIST_DURATION 5 /* sec */
/**************************************
* LCD module (uncomment only one)
diff --git a/megalogger/datalogger.h b/megalogger/datalogger.h
index e6f0709..6649a2b 100644
--- a/megalogger/datalogger.h
+++ b/megalogger/datalogger.h
@@ -1,5 +1,5 @@
/*************************************************************************
-* Arduino Data Logger Class
+* Freematics Data Logger Class
* Distributed under GPL v2.0
* Written by Stanley Huang <stanleyhuangyc@gmail.com>
* Visit http://freematics.com for more information
diff --git a/megalogger/megalogger.ino b/megalogger/megalogger.ino
index fe27f04..34da1ab 100644
--- a/megalogger/megalogger.ino
+++ b/megalogger/megalogger.ino
@@ -24,6 +24,7 @@
#include <SoftwareSerial.h>
#endif
#include "datalogger.h"
+#include "touch.h"
// logger states
#define STATE_SD_READY 0x1
@@ -543,7 +544,7 @@ void processAccelerometer()
void logOBDData(byte pid)
{
- char buffer[OBD_RECV_BUF_SIZE];
+ char buffer[64];
uint32_t start = millis();
int value;
@@ -587,14 +588,15 @@ void logOBDData(byte pid)
}
#if ENABLE_DATA_LOG
// flush SD data every 1KB
- if ((logger.dataSize >> 10) != lastFileSize) {
+ byte dataSizeKB = logger.dataSize >> 10;
+ if (dataSizeKB != lastFileSize) {
logger.flushFile();
+ lastFileSize = dataSizeKB;
// display logged data size
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.setCursor(242, 28);
lcd.print((unsigned int)(logger.dataSize >> 10));
lcd.print("KB");
- lastFileSize = logger.dataSize >> 10;
}
#endif
@@ -624,8 +626,9 @@ void showECUCap()
}
int values[sizeof(pidlist)];
bool scanned = false;
- for (uint32_t t = millis(); millis() - t < GUI_PID_LIST_DURATION * 1000; ) {
- for (byte i = 0, n = 4; i < sizeof(pidlist) / sizeof(pidlist[0]); i++) {
+ for (;;) {
+ bool touched = false;
+ for (byte i = 0, n = 4; i < sizeof(pidlist) / sizeof(pidlist[0]) && !(touched = touch.available()); i++) {
byte pid = pgm_read_byte(pidlist + i);
if (obd.isValidPID(pid)) {
int value;
@@ -646,6 +649,7 @@ void showECUCap()
}
}
}
+ if (touched) break;
scanned = true;
}
}
@@ -709,7 +713,7 @@ void showStates()
void testOut()
{
static const char PROGMEM cmds[][6] = {"ATZ\r", "ATL1\r", "ATRV\r", "0100\r", "010C\r", "0902\r"};
- char buf[OBD_RECV_BUF_SIZE];
+ char buf[128];
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.setCursor(0, 11);
@@ -720,7 +724,7 @@ void testOut()
lcd.print("Sending ");
lcd.println(cmd);
lcd.setColor(RGB16_CYAN);
- if (obd.sendCommand(cmd, buf)) {
+ if (obd.sendCommand(cmd, buf, sizeof(buf))) {
char *p = strstr(buf, cmd);
if (p)
p += strlen(cmd);
@@ -801,8 +805,8 @@ void setup()
state |= STATE_OBD_READY;
- char buf[OBD_RECV_BUF_SIZE];
- if (obd.getVIN(buf)) {
+ char buf[64];
+ if (obd.getVIN(buf, sizeof(buf))) {
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.setColor(RGB16_WHITE);
lcd.print("VIN:");
@@ -810,12 +814,16 @@ void setup()
lcd.println(buf);
}
+ lcd.setCursor(0, 28);
lcd.setColor(RGB16_GREEN);
lcd.setFontSize(FONT_SIZE_MEDIUM);
- lcd.println("READY!");
+ lcd.print("Tap on LCD to continue");
showECUCap();
- delay(3000);
+ lcd.setCursor(0, 28);
+ lcd.setColor(RGB16_YELLOW);
+ lcd.setFontSize(FONT_SIZE_MEDIUM);
+ lcd.print("HERE WE GO! ");
fadeOutScreen();
initScreen();
diff --git a/megalogger/touch.h b/megalogger/touch.h
new file mode 100644
index 0000000..93ba740
--- /dev/null
+++ b/megalogger/touch.h
@@ -0,0 +1,127 @@
+#define T_CLK 6
+#define T_CS 5
+#define T_DIN 4
+#define T_DOUT 3
+#define T_IRQ 2
+
+#define X_CONST 240
+#define Y_CONST 320
+
+#define PREC_TOUCH_CONST 10
+
+#define PixSizeX 13.78
+#define PixOffsX 411
+
+#define PixSizeY 11.01
+#define PixOffsY 378
+
+class CTouch {
+public:
+ void init(void)
+ {
+ pinMode(T_CLK, OUTPUT);
+ pinMode(T_CS, OUTPUT);
+ pinMode(T_DIN, OUTPUT);
+ pinMode(T_DOUT, INPUT);
+ pinMode(T_IRQ, INPUT);
+
+ digitalWrite(T_CS, HIGH);
+ digitalWrite(T_CLK, HIGH);
+ digitalWrite(T_DIN, HIGH);
+ digitalWrite(T_CLK, HIGH);
+ }
+
+ void writeData(unsigned char data)
+ {
+ unsigned char temp;
+ unsigned char nop;
+ unsigned char count;
+
+ temp=data;
+ digitalWrite(T_CLK,LOW);
+
+ for(count=0; count<8; count++)
+ {
+ if(temp & 0x80)
+ digitalWrite(T_DIN, HIGH);
+ else
+ digitalWrite(T_DIN, LOW);
+ temp = temp << 1;
+ digitalWrite(T_CLK, LOW);
+ nop++;
+ digitalWrite(T_CLK, HIGH);
+ nop++;
+ }
+ }
+
+ unsigned int readData()
+ {
+ unsigned char nop;
+ unsigned int data = 0;
+ unsigned char count;
+ for(count=0; count<12; count++)
+ {
+ data <<= 1;
+ digitalWrite(T_CLK, HIGH);
+ nop++;
+ digitalWrite(T_CLK, LOW);
+ nop++;
+ if (digitalRead(T_DOUT))
+ data++;
+ }
+ return(data);
+ }
+
+ void read()
+ {
+ unsigned long tx=0;
+ unsigned long ty=0;
+
+ digitalWrite(T_CS,LOW);
+
+ for (int i=0; i<PREC_TOUCH_CONST; i++)
+ {
+ writeData(0x90);
+ digitalWrite(T_CLK,HIGH);
+ digitalWrite(T_CLK,LOW);
+ ty+=readData();
+
+ writeData(0xD0);
+ digitalWrite(T_CLK,HIGH);
+ digitalWrite(T_CLK,LOW);
+ tx+=readData();
+ }
+
+ digitalWrite(T_CS,HIGH);
+
+ TP_X=tx/PREC_TOUCH_CONST;
+ TP_Y=ty/PREC_TOUCH_CONST;
+ }
+
+ bool available()
+ {
+ return digitalRead(T_IRQ) == 0;
+ }
+
+ int getX()
+ {
+ int value;
+ value = ((TP_X-PixOffsX)/PixSizeX);
+ if (value < 0)
+ value = 0;
+ return value;
+ }
+
+ int getY()
+ {
+ int value;
+ value = ((TP_Y-PixOffsY)/PixSizeY);
+ if (value < 0)
+ value = 0;
+ return value;
+ }
+private:
+ int TP_X,TP_Y;
+};
+
+CTouch touch;