*the rocket lands; a purple lobster with brown spots exits*
This commit is contained in:
parent
0eef3f80fd
commit
185809113e
1 changed files with 174 additions and 20 deletions
|
@ -3,14 +3,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xatom.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
#include <X11/extensions/Xdbe.h>
|
|
||||||
|
|
||||||
#include <cairo.h>
|
|
||||||
#include <cairo-xlib.h>
|
|
||||||
|
|
||||||
#include <hexagram/can.h>
|
#include <hexagram/can.h>
|
||||||
#include <hexagram/window.h>
|
#include <hexagram/window.h>
|
||||||
|
|
||||||
|
@ -116,16 +108,110 @@ static void draw_speedometer(cairo_t *cr,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
double r) {
|
double r) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cairo_select_font_face(cr, "Helvetica",
|
||||||
|
CAIRO_FONT_SLANT_NORMAL,
|
||||||
|
CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
|
|
||||||
|
cairo_set_font_size(cr, r * 0.125);
|
||||||
|
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
||||||
cairo_stroke(cr);
|
cairo_stroke(cr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw face numbers
|
||||||
|
*/
|
||||||
|
for (i=0; i<=180; i+=20) {
|
||||||
|
char text[5];
|
||||||
|
|
||||||
|
snprintf(text, 4, "%02d", i);
|
||||||
|
|
||||||
|
draw_face_number(cr, x, y,
|
||||||
|
0.85 * r,
|
||||||
|
232 * (M_PI/180),
|
||||||
|
488 * (M_PI/180),
|
||||||
|
i / 180.0,
|
||||||
|
text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_speedometer_needle(cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double kph) {
|
||||||
|
if (kph > 290) {
|
||||||
|
kph = 290;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw a tiny boi circle
|
||||||
|
*/
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
|
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
|
||||||
|
cairo_fill(cr);
|
||||||
|
|
||||||
|
draw_needle(cr, x, y, 0.77 * r,
|
||||||
|
232 * (M_PI/180),
|
||||||
|
488 * (M_PI/180),
|
||||||
|
kph / 290);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_thermometer(cairo_t *cr,
|
static void draw_thermometer(cairo_t *cr,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
double r) {
|
double r) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cairo_select_font_face(cr, "Helvetica",
|
||||||
|
CAIRO_FONT_SLANT_NORMAL,
|
||||||
|
CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
|
|
||||||
|
cairo_set_font_size(cr, r * 0.15);
|
||||||
|
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
||||||
cairo_stroke(cr);
|
cairo_stroke(cr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw face numbers
|
||||||
|
*/
|
||||||
|
for (i=120; i<=260; i+=70) {
|
||||||
|
char text[5];
|
||||||
|
|
||||||
|
snprintf(text, 4, "%02d", i);
|
||||||
|
|
||||||
|
draw_face_number(cr, x, y,
|
||||||
|
0.75 * r,
|
||||||
|
300 * (M_PI/180),
|
||||||
|
420 * (M_PI/180),
|
||||||
|
(i - 120.0) / 140.0,
|
||||||
|
text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_thermometer_needle(cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double temp) {
|
||||||
|
if (temp > 260) {
|
||||||
|
temp = 260;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw a tiny boi circle
|
||||||
|
*/
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
|
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
|
||||||
|
cairo_fill(cr);
|
||||||
|
|
||||||
|
draw_needle(cr, x, y, 0.77 * r,
|
||||||
|
300 * (M_PI/180),
|
||||||
|
420 * (M_PI/180),
|
||||||
|
temp / 260);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_fuel_gauge(cairo_t *cr,
|
static void draw_fuel_gauge(cairo_t *cr,
|
||||||
|
@ -136,6 +222,28 @@ static void draw_fuel_gauge(cairo_t *cr,
|
||||||
cairo_stroke(cr);
|
cairo_stroke(cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void draw_fuel_gauge_needle(cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double level) {
|
||||||
|
if (level > 1.0) {
|
||||||
|
level = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw a tiny boi circle
|
||||||
|
*/
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
|
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
|
||||||
|
cairo_fill(cr);
|
||||||
|
|
||||||
|
draw_needle(cr, x, y, 0.77 * r,
|
||||||
|
300 * (M_PI/180),
|
||||||
|
420 * (M_PI/180),
|
||||||
|
level / 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
static void draw_mfd(cairo_t *cr,
|
static void draw_mfd(cairo_t *cr,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
|
@ -200,21 +308,62 @@ static void update_gauge_cluster(cairo_t *cr,
|
||||||
double y,
|
double y,
|
||||||
double width,
|
double width,
|
||||||
double height) {
|
double height) {
|
||||||
|
static double rpm = 0;
|
||||||
|
static double kph = 0;
|
||||||
|
static double temp = 0;
|
||||||
|
static double level = 0;
|
||||||
|
|
||||||
switch (frame->can_id) {
|
switch (frame->can_id) {
|
||||||
case 0x280: {
|
case 0x280: {
|
||||||
static double rpm = 0;
|
|
||||||
|
|
||||||
rpm = 0.25 * (double)(frame->data[2] | (frame->data[3] << 8));
|
rpm = 0.25 * (double)(frame->data[2] | (frame->data[3] << 8));
|
||||||
|
|
||||||
draw_tachometer_needle(cr,
|
break;
|
||||||
x + width * 0.2,
|
}
|
||||||
y + height * 0.5,
|
|
||||||
height * 0.4,
|
case 0x288: {
|
||||||
rpm);
|
temp = (double)(frame->data[1] - 48 * 0.75);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 0x320: {
|
||||||
|
level = (double)(frame->data[2]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 0x5a0: {
|
||||||
|
double rps = 0.001 * (double)((frame->data[1] >> 1)
|
||||||
|
| (frame->data[2] << 8));
|
||||||
|
|
||||||
|
kph = (2.032 * rps * 3600) / 1000.0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_tachometer_needle(cr, x + width * 0.2,
|
||||||
|
y + height * 0.5,
|
||||||
|
height * 0.4,
|
||||||
|
rpm);
|
||||||
|
|
||||||
|
draw_speedometer_needle(cr,
|
||||||
|
width * 0.8,
|
||||||
|
height * 0.5,
|
||||||
|
height * 0.4,
|
||||||
|
kph);
|
||||||
|
|
||||||
|
draw_thermometer_needle(cr,
|
||||||
|
width * 0.43,
|
||||||
|
height * 0.76,
|
||||||
|
height * 0.11,
|
||||||
|
temp);
|
||||||
|
|
||||||
|
draw_fuel_gauge_needle(cr,
|
||||||
|
width * 0.57,
|
||||||
|
height * 0.76,
|
||||||
|
height * 0.11,
|
||||||
|
0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
@ -226,7 +375,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
int fd, fd2,
|
int fd, fd2,
|
||||||
width = 1024,
|
width = 1024,
|
||||||
height = 480;
|
height = 480;
|
||||||
|
|
||||||
cairo_t *fg, *bg;
|
cairo_t *fg, *bg;
|
||||||
|
|
||||||
|
@ -296,12 +445,17 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
hexagram_can_if_read(can_if, &frame);
|
hexagram_can_if_read(can_if, &frame);
|
||||||
|
|
||||||
if (frame.can_id == 0x280) {
|
switch (frame.can_id) {
|
||||||
hexagram_window_refresh_bg(window);
|
case 0x280:
|
||||||
|
case 0x288:
|
||||||
|
case 0x320:
|
||||||
|
case 0x5a0: {
|
||||||
|
hexagram_window_refresh_bg(window);
|
||||||
|
|
||||||
update_gauge_cluster(fg, &frame, 0, 0, width, height);
|
update_gauge_cluster(fg, &frame, 0, 0, width, height);
|
||||||
|
|
||||||
hexagram_window_swap_buffer(window);
|
hexagram_window_swap_buffer(window);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue