Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Display
MCU
VPotDisplay.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <AH/STL/cmath>
4
#include <AH/STL/utility>
// std::forward
5
#include <
Display/DisplayElement.hpp
>
6
#include <
Display/DisplayInterface.hpp
>
7
#include <
MIDI_Inputs/InterfaceMIDIInputElements.hpp
>
8
9
BEGIN_CS_NAMESPACE
10
11
namespace
MCU
{
12
17
template
<
class
VPot_t = Interfaces::MCU::IVPot &>
18
class
VPotDisplay
:
public
DisplayElement
{
19
20
public
:
21
VPotDisplay
(
DisplayInterface
&
display
, VPot_t &&
vpot
,
PixelLocation
loc,
22
uint16_t
radius
, uint16_t
innerRadius
, uint16_t
color
)
23
:
DisplayElement
(
display
),
vpot
(std::forward<VPot_t>(
vpot
)),
24
x
(loc.
x
+
radius
),
y
(loc.
y
+
radius
),
radius
(
radius
),
25
innerRadius
(
innerRadius
),
color
(
color
) {}
26
27
void
draw
()
override
{
28
display
.drawCircle(
x
,
y
,
radius
,
color
);
29
if
(
vpot
.getCenterLed())
30
display
.fillCircle(
x
,
y
,
innerRadius
/ 4,
color
);
31
else
32
display
.drawCircle(
x
,
y
,
innerRadius
/ 4,
color
);
33
uint8_t startOn =
vpot
.getStartOn();
34
uint8_t startOff =
vpot
.getStartOff();
35
for
(uint8_t segment = startOn; segment < startOff; segment++)
36
drawVPotSegment
(segment);
37
vpot
.clearDirty();
38
}
39
40
bool
getDirty
()
const override
{
return
vpot
.getDirty(); }
41
42
void
setAngleSpacing
(
float
spacing) { this->
angleSpacing
= spacing; }
43
float
getAngleSpacing
()
const
{
return
this->
angleSpacing
; }
44
45
private
:
46
VPot_t
vpot
;
47
48
int16_t
x
,
y
;
49
uint16_t
radius
,
innerRadius
,
color
;
50
51
float
angleSpacing
= 0.4887;
// 28°
52
53
protected
:
54
void
drawVPotSegment
(uint8_t segment) {
55
// Segment 5 (i.e. the sixth segment) = 0° (i.e. 12 o'clock, the middle)
56
float
angle =
angleSpacing
* (segment - 5);
57
58
uint16_t x_start =
x
+ std::round((
float
)
innerRadius
* sin(angle) / 2);
59
uint16_t y_start =
y
- std::round((
float
)
innerRadius
* cos(angle) / 2);
60
61
uint16_t x_end =
x
+ std::round((
float
)
innerRadius
* sin(angle));
62
uint16_t y_end =
y
- std::round((
float
)
innerRadius
* cos(angle));
63
64
display
.drawLine(x_start, y_start, x_end, y_end,
color
);
65
}
66
};
67
68
}
// namespace MCU
69
70
END_CS_NAMESPACE
DisplayElement.hpp
DisplayInterface.hpp
InterfaceMIDIInputElements.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
DisplayElement::DisplayElement
DisplayElement(DisplayInterface &display)
Create a new DisplayElement.
Definition
DisplayElement.hpp:18
DisplayElement::display
DisplayInterface & display
Definition
DisplayElement.hpp:103
DisplayInterface
An interface for displays.
Definition
DisplayInterface.hpp:16
MCU::VPotDisplay::getDirty
bool getDirty() const override
Check if this DisplayElement has to be re-drawn.
Definition
VPotDisplay.hpp:40
MCU::VPotDisplay::color
uint16_t color
Definition
VPotDisplay.hpp:49
MCU::VPotDisplay::vpot
VPot_t vpot
Definition
VPotDisplay.hpp:46
MCU::VPotDisplay::VPotDisplay
VPotDisplay(DisplayInterface &display, VPot_t &&vpot, PixelLocation loc, uint16_t radius, uint16_t innerRadius, uint16_t color)
Definition
VPotDisplay.hpp:21
MCU::VPotDisplay::radius
uint16_t radius
Definition
VPotDisplay.hpp:49
MCU::VPotDisplay::setAngleSpacing
void setAngleSpacing(float spacing)
Definition
VPotDisplay.hpp:42
MCU::VPotDisplay::getAngleSpacing
float getAngleSpacing() const
Definition
VPotDisplay.hpp:43
MCU::VPotDisplay::angleSpacing
float angleSpacing
Definition
VPotDisplay.hpp:51
MCU::VPotDisplay::innerRadius
uint16_t innerRadius
Definition
VPotDisplay.hpp:49
MCU::VPotDisplay::drawVPotSegment
void drawVPotSegment(uint8_t segment)
Definition
VPotDisplay.hpp:54
MCU::VPotDisplay::x
int16_t x
Definition
VPotDisplay.hpp:48
MCU::VPotDisplay::y
int16_t y
Definition
VPotDisplay.hpp:48
MCU::VPotDisplay::draw
void draw() override
Draw this DisplayElement to the display buffer.
Definition
VPotDisplay.hpp:27
MCU
Definition
LCDDisplay.hpp:10
PixelLocation
A simple struct representing a pixel with integer coordinates.
Definition
Def.hpp:64
Generated by
1.17.0