Implement hexagram_cluster_update()
Implement hexagram_cluster_update() to act as a central point to decode CAN frames relevant to the gauge cluster
This commit is contained in:
parent
961af0ce50
commit
0083200cfa
3 changed files with 40 additions and 30 deletions
|
@ -45,37 +45,9 @@ static void cluster_update(hexagram_cluster *cluster,
|
|||
struct timeval *last) {
|
||||
struct timeval now;
|
||||
|
||||
switch (frame->can_id) {
|
||||
case 0x280: {
|
||||
cluster->state.rpm = 0.25 *
|
||||
(double)(frame->data[2] | (frame->data[3] << 8));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x288: {
|
||||
cluster->state.temp = (double)(frame->data[1] - 48 * 0.75);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x320: {
|
||||
cluster->state.fuel = (double)(frame->data[2] & 0xf) / 16.0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x5a0: {
|
||||
cluster->state.rps = 0.001 * (double)(frame->data[1]
|
||||
| (frame->data[2] << 8));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
if (!hexagram_cluster_update(cluster, frame)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef _HEXAGRAM_CLUSTER_H
|
||||
#define _HEXAGRAM_CLUSTER_H
|
||||
|
||||
#include <linux/can.h>
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
#include <hexagram/tacho.h>
|
||||
|
@ -35,6 +37,9 @@ void hexagram_cluster_init(hexagram_cluster *cluster,
|
|||
hexagram_cluster *hexagram_cluster_new(double width,
|
||||
double height);
|
||||
|
||||
int hexagram_cluster_update(hexagram_cluster *cluster,
|
||||
struct can_frame *frame);
|
||||
|
||||
void hexagram_cluster_draw_bg(hexagram_cluster *cluster,
|
||||
cairo_t *cr);
|
||||
|
||||
|
|
|
@ -71,6 +71,39 @@ error_malloc_cluster:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int hexagram_cluster_update(hexagram_cluster *cluster,
|
||||
struct can_frame *frame) {
|
||||
switch (frame->can_id) {
|
||||
case 0x280: {
|
||||
cluster->state.rpm = 0.25 *
|
||||
(double)(frame->data[2] | (frame->data[3] << 8));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
case 0x288: {
|
||||
cluster->state.temp = (double)(frame->data[1] - 48 * 0.75);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
case 0x320: {
|
||||
cluster->state.fuel = (double)(frame->data[2] & 0xf) / 16.0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
case 0x5a0: {
|
||||
cluster->state.rps = 0.001 * (double)(frame->data[1]
|
||||
| (frame->data[2] << 8));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hexagram_cluster_draw_bg(hexagram_cluster *cluster,
|
||||
cairo_t *cr) {
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue