summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-02-03 16:37:51 -0500
committerSolomon Peachy <pizza@shaftnet.org>2019-02-03 17:32:46 -0500
commit34dadfb0dd1a06d8eda86b8e6b644f800df71005 (patch)
tree743f61bb1166eb8cb7208c809a37736f83b9da2f
parent3d07cdeb230601a4cb65ca3d9a48eafa1c470f0c (diff)
downloadaldl_pi-34dadfb0dd1a06d8eda86b8e6b644f800df71005.tar.gz
aldl_pi-34dadfb0dd1a06d8eda86b8e6b644f800df71005.tar.bz2
aldl_pi-34dadfb0dd1a06d8eda86b8e6b644f800df71005.zip
Bug fixes. Data coming in but timing isn't right.
...WiringPi may not be up for the accuracy / latency we need.
-rw-r--r--aldl.c19
-rw-r--r--aldl_pi.c8
-rw-r--r--sdldash.c20
3 files changed, 24 insertions, 23 deletions
diff --git a/aldl.c b/aldl.c
index 5435de2..537cbd7 100644
--- a/aldl.c
+++ b/aldl.c
@@ -50,7 +50,6 @@ struct stream_common decoded = { 0 };
void (*aldl_callback)(uint8_t *data, int datalen) = NULL;
-
/* Datalogging */
void datalog_init(char *fname)
{
@@ -84,20 +83,18 @@ static void aldl_datalog(uint8_t *data, int datalen)
void isrfn(void)
{
int val;
- delayfn(1); // To handle both variations, minimum of 0.5, max of 1.8
+ delayfn(2000); // To handle both variations, minimum of 0.5, max of 1.8ms
val = readbit();
ALDLSR <<= 1;
ALDLSR |= (val & 1);
- /* Wait for initial sync. */
- if (!gotsync) {
- if ((ALDLSR & SYNC_WORD) == SYNC_WORD) {
- gotsync = 1;
- }
- return; /* No sync, drop everything */
- }
-
if ((ALDLSR & SYNC_WORD) == SYNC_WORD) {
+ ALDLSR = 0;
+ if (!gotsync) {
+ gotsync = 1;
+ return; /* First one, we don't do anything */
+ }
+ printf(" - %d\n", datalen);
/* New sync word, we've finished a sequence */
if (aldl_callback)
aldl_callback(data, datalen);
@@ -106,8 +103,10 @@ void isrfn(void)
bits = 0;
datalen = 0;
} else if (++bits == 9) {
+ printf(" %02x", ALDLSR & 0xFF);
/* Just latch in the word */
data[datalen++] = ALDLSR & 0xff;
bits = 0;
+ ALDLSR = 0;
}
}
diff --git a/aldl_pi.c b/aldl_pi.c
index bcf98a8..85cd71b 100644
--- a/aldl_pi.c
+++ b/aldl_pi.c
@@ -44,9 +44,9 @@ int readbit(void)
{
return !digitalRead(ALDL_PIN_IN); /* Logic low is ALDL '1' */
}
-void delayfn(int ms)
+void delayfn(int us)
{
- delay(1);
+ delayMicroseconds(us);
}
/* Main */
@@ -54,6 +54,9 @@ int main (int argc, char **argv)
{
int run = 1;
+ /* Set up callback for our type */
+ aldl_callback = aldl_a179_callback;
+
wiringPiSetup();
/* Set highest possible priority */
@@ -62,7 +65,6 @@ int main (int argc, char **argv)
/* Set up RPi GPIO */
pinMode(ALDL_PIN_IN, INPUT);
pullUpDnControl(ALDL_PIN_IN, PUD_DOWN);
-
wiringPiISR (ALDL_PIN_IN, INT_EDGE_FALLING, &isrfn);
datalog_init(datalog_fname);
diff --git a/sdldash.c b/sdldash.c
index 3d5036b..c2dc013 100644
--- a/sdldash.c
+++ b/sdldash.c
@@ -182,28 +182,28 @@ int render_dash(void) {
RENDER_TEXT_1ARG(i, 10, 110, textcolor, "%03u%% TP", decoded.tp);
if (decoded.idling) {
- RENDER_TEXT_1ARG(i, 200, 10, textcolor, "IDLE @ %04d", decoded.idle_tgt);
+ RENDER_TEXT_1ARG(i, 200, 30, textcolor, "IDLE @ %04d", decoded.idle_tgt);
if (decoded.closed_loop_idle)
- RENDER_TEXT_NOARG(i, 200, 30, textcolor, "CLOSED LOOP");
+ RENDER_TEXT_NOARG(i, 200, 50, textcolor, "CLOSED LOOP");
else
- RENDER_TEXT_NOARG(i, 200, 30, textcolor, "OPEN LOOP");
+ RENDER_TEXT_NOARG(i, 200, 50, textcolor, "OPEN LOOP");
} else {
if (decoded.closed_loop)
- RENDER_TEXT_NOARG(i, 200, 30, textcolor, "CLOSED LOOP");
+ RENDER_TEXT_NOARG(i, 200, 50, textcolor, "CLOSED LOOP");
else
- RENDER_TEXT_NOARG(i, 200, 30, textcolor, "OPEN LOOP");
+ RENDER_TEXT_NOARG(i, 200, 50, textcolor, "OPEN LOOP");
}
if (decoded.ac_request)
- RENDER_TEXT_NOARG(i, 200, 50, textcolor, "AC REQ");
+ RENDER_TEXT_NOARG(i, 200, 70, textcolor, "AC REQ");
if (decoded.shift_req)
- RENDER_TEXT_NOARG(i, 200, 70, textcolor, "SHIFT REQ");
+ RENDER_TEXT_NOARG(i, 200, 90, textcolor, "SHIFT REQ");
else if (decoded.top_gear)
- RENDER_TEXT_NOARG(i, 200, 70, textcolor, "TOP GEAR");
+ RENDER_TEXT_NOARG(i, 200, 90, textcolor, "TOP GEAR");
else if (decoded.neutral)
- RENDER_TEXT_NOARG(i, 200, 70, textcolor, "NEUTRAL");
+ RENDER_TEXT_NOARG(i, 200, 90, textcolor, "NEUTRAL");
- RENDER_TEXT_1ARG(i, 200, 90, textcolor, "BAT %02.01f v", decoded.battery_v);
+ RENDER_TEXT_1ARG(i, 200, 110, textcolor, "BAT %02.01f v", decoded.battery_v);
RENDER_TEXT_1ARG(i, 310, 225, textcolor, "%c", decoded.heartbeat ? '^' : '*');