From da67c32fdb81068a854c5adcc3f9cfeffe14be2c Mon Sep 17 00:00:00 2001 From: Will Wentink Date: Sun, 5 Oct 2025 14:11:27 -0500 Subject: [PATCH 1/4] Initial working pointer commit --- include/pointer.h | 25 ++++++++++++++++++++ src/main.cpp | 17 ++++++++++++++ src/pointer.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 include/pointer.h create mode 100644 src/pointer.cpp diff --git a/include/pointer.h b/include/pointer.h new file mode 100644 index 0000000..1f8f065 --- /dev/null +++ b/include/pointer.h @@ -0,0 +1,25 @@ +#ifndef POINTER_H +#define POINTER_H + +#include +#include + +// Max/min value for integer input (0 = 0 degrees, 100 = 180 degrees) +#define MAX_VALUE 100 +#define MIN_VALUE 0 + +// Pointer color and length +#define POINTER_COLOR TFT_RED +#define POINTER_LENGTH 60 + +#define BG_COLOR TFT_BLACK // background color + +extern TFT_eSPI tft; + +void begin(); + +void updatePointerAngle(double theta); + +void updatePointer(int value); + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3747802..fece7b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include "display.h" +#include "pointer.h" void setup() { Serial.begin(115200); @@ -17,4 +18,20 @@ void loop() { // drawSdJpeg("/test.jpg", 0, 0); // HeapAnim(); + + // pointer loop + // if (Serial.available()) { + // String input = Serial.readStringUntil('\n'); + // input.trim(); + + // if (input.startsWith("a")) { // ex: use a10 to set to 10 degrees + // double angle = input.substring(1).toDouble(); + // updatePointerAngle(angle); + // Serial.printf("set to angle: %.2f deg\n", angle); + // } else { + // int value = input.toInt(); // otherwise use integer method + // updatePointer(value); + // Serial.printf("set to value: %d\n", value); + // } + // } } diff --git a/src/pointer.cpp b/src/pointer.cpp new file mode 100644 index 0000000..7dfdfc2 --- /dev/null +++ b/src/pointer.cpp @@ -0,0 +1,60 @@ +#include "pointer.h" +#include +#include + +TFT_eSPI tft = TFT_eSPI(); + +static int pivotX = 0; // x coord of pivot point +static int pivotY = 0; // y coord of pivot point +static int length = POINTER_LENGTH; // length of pointer +static double currentTheta = 0.0; // current angle in degrees + +// erases pointer by painting background colored line over old line +static void erasePointer() { + int oldX = pivotX + length * cos(currentTheta * DEG_TO_RAD); + int oldY = pivotY + length * sin(currentTheta * DEG_TO_RAD); + tft.drawLine(pivotX, pivotY, oldX, oldY, BG_COLOR); +} + +// initializes and sets up pointer +void begin() { + tft.init(); + tft.setRotation(1); // needed for some reason (see display.cpp initDisplay) + tft.fillScreen(BG_COLOR); // fills screen with background color + + // pulls screen width and height + int screenW = tft.width(); + int screenH = tft.height(); + + // sets pivot point at middle of screen + pivotX = screenW / 2; + pivotY = screenH / 2; + + // sets pointer to 0 degrees + currentTheta = 0.0; + updatePointerAngle(0.0); + + Serial.println("begin"); +} + +// updates pointer given an angle in degrees +void updatePointerAngle(double theta) { + erasePointer(); // erases old point + currentTheta = theta; // sets new degree to input + + int newX = pivotX + length * cos(theta * DEG_TO_RAD); // calculates new x endpoint + int newY = pivotY + length * sin(theta * DEG_TO_RAD); // calculates new y endpoint + + tft.drawLine(pivotX, pivotY, newX, newY, POINTER_COLOR); // draws new line +} + +// updates pointer given a integer value defined in pointer.h +void updatePointer(int value) { + // checks that value is between min and max values + if (value < MIN_VALUE) value = MIN_VALUE; + if (value > MAX_VALUE) value = MAX_VALUE; + + // converts to degrees and calls angle method + double theta = 180.0 * value / MAX_VALUE; + updatePointerAngle(theta); +} \ No newline at end of file From 0678922dc76d3ba3346a363997d9f68cb82a920b Mon Sep 17 00:00:00 2001 From: Will Wentink Date: Mon, 20 Oct 2025 18:23:31 -0500 Subject: [PATCH 2/4] Changed updatePointer param to "speed" from "value", put pointer in bottom left of screen instead of middle --- include/pointer.h | 6 +++--- src/pointer.cpp | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/pointer.h b/include/pointer.h index 1f8f065..90a749b 100644 --- a/include/pointer.h +++ b/include/pointer.h @@ -5,8 +5,8 @@ #include // Max/min value for integer input (0 = 0 degrees, 100 = 180 degrees) -#define MAX_VALUE 100 -#define MIN_VALUE 0 +#define MAX_SPEED 100 +#define MIN_SPEED 0 // Pointer color and length #define POINTER_COLOR TFT_RED @@ -20,6 +20,6 @@ void begin(); void updatePointerAngle(double theta); -void updatePointer(int value); +void updatePointer(int speed); #endif \ No newline at end of file diff --git a/src/pointer.cpp b/src/pointer.cpp index 7dfdfc2..4c36a10 100644 --- a/src/pointer.cpp +++ b/src/pointer.cpp @@ -26,9 +26,9 @@ void begin() { int screenW = tft.width(); int screenH = tft.height(); - // sets pivot point at middle of screen - pivotX = screenW / 2; - pivotY = screenH / 2; + // sets pivot point at bottom left of screen + pivotX = screenW / 4; + pivotY = screenH / 4; // sets pointer to 0 degrees currentTheta = 0.0; @@ -49,12 +49,12 @@ void updatePointerAngle(double theta) { } // updates pointer given a integer value defined in pointer.h -void updatePointer(int value) { +void updatePointer(int speed) { // checks that value is between min and max values - if (value < MIN_VALUE) value = MIN_VALUE; - if (value > MAX_VALUE) value = MAX_VALUE; + if (speed < MIN_SPEED) speed = MIN_SPEED; + if (speed > MAX_SPEED) speed = MAX_SPEED; // converts to degrees and calls angle method - double theta = 180.0 * value / MAX_VALUE; + double theta = 180.0 * speed / MAX_SPEED; updatePointerAngle(theta); } \ No newline at end of file From 4a50b436ccee7397fe7fc4fd367c3afe6e6c894c Mon Sep 17 00:00:00 2001 From: Gorniferous Date: Thu, 30 Oct 2025 19:10:07 -0500 Subject: [PATCH 3/4] checkpoint drawing speedometer arc --- include/speedometer.h | 17 +++++++++++++++++ src/main.cpp | 5 ++++- src/pointer.cpp | 2 +- src/speedometer.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 include/speedometer.h create mode 100644 src/speedometer.cpp diff --git a/include/speedometer.h b/include/speedometer.h new file mode 100644 index 0000000..8385495 --- /dev/null +++ b/include/speedometer.h @@ -0,0 +1,17 @@ +#ifndef SPEED_ARC_H +#define SPEED_ARC_H + +#include +#include + +// Speedometer arc color and radius +#define SPEED_ARC_COLOR TFT_WHITE +#define SPEED_ARC_RADIUS 80 + +#define BG_COLOR TFT_BLACK // background color + +extern TFT_eSPI tft; + +void initSpeedometer(); + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fece7b5..56453f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include "display.h" #include "pointer.h" +#include "speedometer.h" void setup() { Serial.begin(115200); @@ -10,10 +11,12 @@ void setup() { // drawSdJpeg("/bsr/Jonathan.jpeg", 130, 0); // HeapAnim(); Serial.println("Setup done."); + begin(); + initSpeedometer(); } void loop() { - rotateColors(); + // rotateColors(); // delay(42); // drawSdJpeg("/test.jpg", 0, 0); diff --git a/src/pointer.cpp b/src/pointer.cpp index 7dfdfc2..a1d40be 100644 --- a/src/pointer.cpp +++ b/src/pointer.cpp @@ -2,7 +2,7 @@ #include #include -TFT_eSPI tft = TFT_eSPI(); +//TFT_eSPI tft = TFT_eSPI(); static int pivotX = 0; // x coord of pivot point static int pivotY = 0; // y coord of pivot point diff --git a/src/speedometer.cpp b/src/speedometer.cpp new file mode 100644 index 0000000..d8ae667 --- /dev/null +++ b/src/speedometer.cpp @@ -0,0 +1,40 @@ +#include "pointer.h" +#include "speedometer.h" +#include +#include + +int lowAngle = MIN_VALUE + 270; +int highAngle = MAX_VALUE - 10; +// Starts up the spedometer arc +void initSpeedometer() { + // Initializes the pointer for the speedometer + + //TFT_eSPI tft = TFT_eSPI(); + int sar = SPEED_ARC_RADIUS; + int sx = tft.width() / 2; + int sy = tft.height() / 2; + // Serial.printf("sx: %d\n ", sx); + // Serial.printf("sy: %d\n ", sy); + + tft.drawSmoothArc(sx, sy, sar, sar, lowAngle, highAngle, SPEED_ARC_COLOR, BG_COLOR, false); + + // Adds a tick mark every 20 degrees, 15 pixels long + // Also adds one in between each 20 degree segment, 10 pixels long + for (int i = 0; i <= 180; i += 20) { + float radian = radians(i); + tft.drawLine(sx + sar * cos(radian), + sy + sar * sin(radian), + sx + (sar - 15) * cos(radian), + sy + (sar - 15) * sin(radian), + SPEED_ARC_COLOR); + radian = radians(i + 10); + if (i >= 180){ + break; + } + tft.drawLine(sx + sar * cos(radian), + sy + sar * sin(radian), + sx + (sar - 10) * cos(radian), + sy + (sar - 10) * sin(radian), + SPEED_ARC_COLOR); + } +} From 8a2bae5f7ce364f830b2e71a7017d4a6c45bfd18 Mon Sep 17 00:00:00 2001 From: Aditya YV Date: Sun, 16 Nov 2025 14:06:39 -0600 Subject: [PATCH 4/4] fixed variable name --- embedded-pio | 2 +- src/speedometer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/embedded-pio b/embedded-pio index 9e8f34c..3640a3e 160000 --- a/embedded-pio +++ b/embedded-pio @@ -1 +1 @@ -Subproject commit 9e8f34cb83b9d1232a50e24863bb080c85eb7a45 +Subproject commit 3640a3e564919c655f7a2507262b2cbed4261e8b diff --git a/src/speedometer.cpp b/src/speedometer.cpp index d8ae667..db1fe18 100644 --- a/src/speedometer.cpp +++ b/src/speedometer.cpp @@ -3,8 +3,8 @@ #include #include -int lowAngle = MIN_VALUE + 270; -int highAngle = MAX_VALUE - 10; +int lowAngle = MIN_SPEED + 270; +int highAngle = MAX_SPEED - 10; // Starts up the spedometer arc void initSpeedometer() { // Initializes the pointer for the speedometer