Control Surface pin-t-adl
MIDI Control Surface library for Arduino
VPotDisplay.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <AH/STL/utility> // std::forward
7#include <math.h>
8
10
11namespace MCU {
12
13template <class VPot_t = Interfaces::MCU::IVPot &>
15
16 public:
18 uint16_t radius, uint16_t innerRadius, uint16_t color)
19 : DisplayElement(display), vpot(std::forward<VPot_t>(vpot)),
20 x(loc.x + radius), y(loc.y + radius), radius(radius),
22
23 void draw() override {
25 if (vpot.getCenterLed())
27 else
29 uint8_t startOn = vpot.getStartOn();
30 uint8_t startOff = vpot.getStartOff();
31 for (uint8_t segment = startOn; segment < startOff; segment++)
32 drawVPotSegment(segment);
33 vpot.clearDirty();
34 }
35
36 bool getDirty() const override { return vpot.getDirty(); }
37
38 void setAngleSpacing(float spacing) { this->angleSpacing = spacing; }
39 float getAngleSpacing() const { return this->angleSpacing; }
40
41 private:
42 VPot_t vpot;
43
44 int16_t x, y;
46
47 float angleSpacing = 0.4887; // 28°
48
49 protected:
50 void drawVPotSegment(uint8_t segment) {
51 // Segment 5 (i.e. the sixth segment) = 0° (i.e. 12 o'clock, the middle)
52 float angle = angleSpacing * (segment - 5);
53
54 uint16_t x_start = x + round((float)innerRadius * sin(angle) / 2);
55 uint16_t y_start = y - round((float)innerRadius * cos(angle) / 2);
56
57 uint16_t x_end = x + round((float)innerRadius * sin(angle));
58 uint16_t y_end = y - round((float)innerRadius * cos(angle));
59
60 display.drawLine(x_start, y_start, x_end, y_end, color);
61 }
62};
63
64} // namespace MCU
65
A simple struct representing a pixel with integer coordinates.
Definition: Def.hpp:64
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
An interface for elements that draw to a display.
DisplayInterface & display
An interface for displays.
virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a disk (filled circle).
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)=0
Draw a line between two points.
virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle.
bool getDirty() const override
Check if this DisplayElement has to be re-drawn.
Definition: VPotDisplay.hpp:36
VPotDisplay(DisplayInterface &display, VPot_t &&vpot, PixelLocation loc, uint16_t radius, uint16_t innerRadius, uint16_t color)
Definition: VPotDisplay.hpp:17
void setAngleSpacing(float spacing)
Definition: VPotDisplay.hpp:38
float getAngleSpacing() const
Definition: VPotDisplay.hpp:39
uint16_t innerRadius
Definition: VPotDisplay.hpp:45
void drawVPotSegment(uint8_t segment)
Definition: VPotDisplay.hpp:50
void draw() override
Draw this DisplayElement to the display buffer.
Definition: VPotDisplay.hpp:23