This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
VPotDisplay.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 #include <math.h>
7 
9 
10 namespace MCU {
11 
12 class VPotDisplay : public DisplayElement {
13 
14  public:
16  uint16_t radius, uint16_t innerRadius, uint16_t color)
17  : DisplayElement(display), vpot(vpot), x(loc.x + radius),
19  color(color) {}
20  void draw() override {
22  if (vpot.getCenterLed())
24  else
26  uint8_t startOn = vpot.getStartOn();
27  uint8_t startOff = vpot.getStartOff();
28  for (uint8_t segment = startOn; segment < startOff; segment++)
29  drawVPotSegment(segment);
30  }
31 
32  private:
34 
35  int16_t x, y;
36  uint16_t radius, innerRadius, color;
37 
38  const static float angleSpacing;
39 
40  protected:
41  void drawVPotSegment(uint8_t segment) {
42  // segment 5 (i.e. the sixth segment) = 0° (i.e. 12 o'clock)
43  float angle = angleSpacing * (segment - 5);
44 
45  // TODO: use Bresenham directly
46 
47  uint16_t x_start = x + round((float)innerRadius * sin(angle) / 2);
48  uint16_t y_start = y - round((float)innerRadius * cos(angle) / 2);
49 
50  uint16_t x_end = x + round((float)innerRadius * sin(angle));
51  uint16_t y_end = y - round((float)innerRadius * cos(angle));
52 
53  display.drawLine(x_start, y_start, x_end, y_end, color);
54  }
55 };
56 
57 } // namespace MCU
58 
MCU::VPotDisplay::innerRadius
uint16_t innerRadius
Definition: VPotDisplay.hpp:36
MCU::IVPotRing
Definition: VPotRing.hpp:26
DisplayElement
An interface for elements that draw to a display.
Definition: DisplayElement.hpp:11
DisplayInterface::fillCircle
virtual void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a disk (filled circle).
Definition: DisplayInterface.cpp:42
MCU::VPotDisplay
Definition: VPotDisplay.hpp:12
DisplayInterface
An interface for displays.
Definition: DisplayInterface.hpp:14
MCU
Names and note and controller numbers for the Mackie Control Universal (MCU) protocol.
Definition: LCDDisplay.hpp:10
MCU::VPotDisplay::color
uint16_t color
Definition: VPotDisplay.hpp:36
MCU::VPotDisplay::x
int16_t x
Definition: VPotDisplay.hpp:35
DisplayInterface.hpp
MCU::IVPotRing::getStartOn
uint8_t getStartOn() const
Get the first segment that should be on.
Definition: VPotRing.hpp:40
MCU::VPotDisplay::VPotDisplay
VPotDisplay(DisplayInterface &display, IVPotRing &vpot, PixelLocation loc, uint16_t radius, uint16_t innerRadius, uint16_t color)
Definition: VPotDisplay.hpp:15
PixelLocation
A simple struct representing a pixel with integer coordinates.
Definition: Def.hpp:74
DisplayInterface::drawLine
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.
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
DisplayElement.hpp
MCU::IVPotRing::getCenterLed
bool getCenterLed() const
Return the status of the center LED of the V-Pot ring.
Definition: VPotRing.hpp:34
VPotRing.hpp
MCU::VPotDisplay::draw
void draw() override
Draw this DisplayElement to the display buffer.
Definition: VPotDisplay.hpp:20
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
DisplayInterface::drawCircle
virtual void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle.
Definition: DisplayInterface.cpp:19
DisplayElement::display
DisplayInterface & display
Definition: DisplayElement.hpp:44
MCU::VPotDisplay::vpot
IVPotRing & vpot
Definition: VPotDisplay.hpp:33
MCU::VPotDisplay::radius
uint16_t radius
Definition: VPotDisplay.hpp:36
MCU::VPotDisplay::angleSpacing
const static float angleSpacing
Definition: VPotDisplay.hpp:38
MCU::IVPotRing::getStartOff
uint8_t getStartOff() const
Get the first segment that should be off.
Definition: VPotRing.hpp:56
MCU::VPotDisplay::y
int16_t y
Definition: VPotDisplay.hpp:35
MCU::VPotDisplay::drawVPotSegment
void drawVPotSegment(uint8_t segment)
Definition: VPotDisplay.hpp:41