2019-06-09 13:55:54 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <hexagram/gauge.h>
|
|
|
|
#include <hexagram/speedo.h>
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
void hexagram_speedo_init(hexagram_speedo *speedo,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
double radius) {
|
|
|
|
hexagram_gauge_init(&speedo->gauge, x, y, radius,
|
|
|
|
232.0 * (M_PI / 180.0),
|
|
|
|
488.0 * (M_PI / 180.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void hexagram_speedo_draw_face(hexagram_speedo *speedo,
|
|
|
|
cairo_t *cr) {
|
2019-06-09 13:55:54 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
cairo_select_font_face(cr, "Helvetica",
|
2019-06-09 15:46:41 -05:00
|
|
|
CAIRO_FONT_SLANT_NORMAL,
|
|
|
|
CAIRO_FONT_WEIGHT_NORMAL);
|
2019-06-09 13:55:54 -05:00
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
cairo_set_font_size(cr, speedo->gauge.radius * 0.125);
|
2019-06-09 13:55:54 -05:00
|
|
|
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
2019-06-09 15:46:41 -05:00
|
|
|
|
|
|
|
cairo_arc(cr,
|
|
|
|
speedo->gauge.x,
|
|
|
|
speedo->gauge.y,
|
|
|
|
speedo->gauge.radius,
|
|
|
|
0,
|
|
|
|
2.0 * M_PI);
|
|
|
|
|
2019-06-09 13:55:54 -05:00
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Draw face numbers
|
|
|
|
*/
|
|
|
|
for (i=0; i<=180; i+=20) {
|
|
|
|
char text[5];
|
|
|
|
|
|
|
|
snprintf(text, 4, "%02d", i);
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_gauge_draw_number(&speedo->gauge,
|
|
|
|
cr,
|
|
|
|
0.85,
|
2019-06-09 13:55:54 -05:00
|
|
|
i / 180.0,
|
|
|
|
text);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<=180; i+=2) {
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_gauge_draw_mark(&speedo->gauge,
|
|
|
|
cr,
|
|
|
|
(i % 10)? 0.75: 0.7,
|
|
|
|
0.8,
|
2019-06-09 13:55:54 -05:00
|
|
|
i / 180.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
void hexagram_speedo_draw_needle(hexagram_speedo *speedo,
|
|
|
|
cairo_t *cr,
|
2019-06-14 01:11:08 -05:00
|
|
|
double rps) {
|
2023-12-17 15:50:25 -05:00
|
|
|
double kph = (2.00152 * rps * 3600) / 1000.0,
|
|
|
|
mph = kph * 0.621371;
|
2019-06-14 01:11:08 -05:00
|
|
|
|
2023-12-17 15:50:25 -05:00
|
|
|
if (mph < 0) {
|
|
|
|
mph = 0;
|
|
|
|
} else if (mph > HEXAGRAM_SPEEDO_MAX_MPH) {
|
|
|
|
mph = HEXAGRAM_SPEEDO_MAX_MPH;
|
2019-06-09 13:55:54 -05:00
|
|
|
}
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_gauge_draw_needle(&speedo->gauge,
|
|
|
|
cr,
|
|
|
|
0.8,
|
2023-12-17 15:50:25 -05:00
|
|
|
mph / HEXAGRAM_SPEEDO_MAX_MPH);
|
2019-06-09 13:55:54 -05:00
|
|
|
}
|