Skip to content

Commit

Permalink
Daniel/chromadeck/starting changes (#134)
Browse files Browse the repository at this point in the history
* starting work for chromadeck

* mainmenu files

* idk what im doing

* idk what im doing 2

* fixed leds

* chromadeck is starting to look good

* fixed tests
  • Loading branch information
Unreal-Dan authored Nov 14, 2023
1 parent fd69e27 commit e430b21
Show file tree
Hide file tree
Showing 233 changed files with 602,620 additions and 602,483 deletions.
15 changes: 15 additions & 0 deletions VortexEngine/VortexEngine.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <Arduino.h>

#include "src/VortexEngine.h"

void setup()
{
if (!VortexEngine::init()) {
// uhoh
}
}

void loop()
{
VortexEngine::tick();
}
2 changes: 2 additions & 0 deletions VortexEngine/VortexEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<ClCompile Include="src\Buttons\Buttons.cpp" />
<ClCompile Include="src\Colors\Colorset.cpp" />
<ClCompile Include="src\Colors\ColorTypes.cpp" />
<ClCompile Include="src\Menus\MainMenu.cpp" />
<ClCompile Include="src\Wireless\IRReceiver.cpp" />
<ClCompile Include="src\Wireless\IRSender.cpp" />
<ClCompile Include="src\Leds\Leds.cpp" />
Expand Down Expand Up @@ -219,6 +220,7 @@
<ClInclude Include="src\Colors\ColorConstants.h" />
<ClInclude Include="src\Colors\Colorset.h" />
<ClInclude Include="src\Colors\ColorTypes.h" />
<ClInclude Include="src\Menus\MainMenu.h" />
<ClInclude Include="src\Wireless\IRConfig.h" />
<ClInclude Include="src\Wireless\IRReceiver.h" />
<ClInclude Include="src\Wireless\IRSender.h" />
Expand Down
6 changes: 6 additions & 0 deletions VortexEngine/VortexEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@
<ClCompile Include="src\Wireless\VLSender.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\Menus\MainMenu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\VortexConfig.h">
Expand Down Expand Up @@ -554,5 +557,8 @@
<ClInclude Include="src\Colors\ColorConstants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Menus\MainMenu.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions VortexEngine/src/Buttons/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "VortexLib.h"
#endif

#ifdef VORTEX_EMBEDDED
#include <Arduino.h>
#endif

Button::Button() :
m_pinNum(0),
m_pressTime(0),
Expand Down Expand Up @@ -46,12 +50,19 @@ bool Button::init(uint8_t pin)
m_longClick = false;

m_pinNum = pin;
#ifdef VORTEX_EMBEDDED
pinMode(m_pinNum, INPUT_PULLUP);
#endif
return true;
}

bool Button::check()
{
#ifdef VORTEX_EMBEDDED
return digitalRead(m_pinNum) == LOW;
#else
return (Vortex::vcallbacks()->checkPinHook(m_pinNum) == 0);
#endif
}

void Button::update()
Expand Down
8 changes: 4 additions & 4 deletions VortexEngine/src/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Button Buttons::m_buttons[NUM_BUTTONS];

bool Buttons::init()
{
// initialize the button on pin 1
if (!m_buttons[0].init(1) ||
!m_buttons[1].init(2) ||
!m_buttons[2].init(3)) {
// initialize the button on pins 9/10/11
if (!m_buttons[0].init(9) ||
!m_buttons[1].init(10) ||
!m_buttons[2].init(11)) {
return false;
}
g_pButtonL = &m_buttons[0];
Expand Down
9 changes: 9 additions & 0 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ enum Pair : uint8_t
PAIR_3,
PAIR_4,

PAIR_5,
PAIR_6,
PAIR_7,
PAIR_8,
PAIR_9,

PAIR_COUNT,
PAIR_LAST = (PAIR_COUNT - 1),
};
Expand Down Expand Up @@ -155,6 +161,9 @@ inline LedPos mapGetNextLed(LedMap map, LedPos pos)
#define MAP_PAIR_EVENS (((1 << LED_COUNT) - 1) & 0x55555555)
#define MAP_PAIR_ODDS (((1 << LED_COUNT) - 1) & 0xAAAAAAAA)

#define MAP_OUTER_RING ((((1 << LED_COUNT) - 1) >> (LED_COUNT / 2)) << (LED_COUNT / 2))
#define MAP_INNER_RING ((((1 << LED_COUNT) - 1) << (LED_COUNT / 2)) >> (LED_COUNT / 2))

// Some preset bitmaps for pair groupings
#define MAP_PAIR_ODD_EVENS (MAP_PAIR_EVEN(PAIR_0) | MAP_PAIR_EVEN(PAIR_2) | MAP_PAIR_EVEN(PAIR_4))
#define MAP_PAIR_ODD_ODDS (MAP_PAIR_ODD(PAIR_0) | MAP_PAIR_ODD(PAIR_2) | MAP_PAIR_ODD(PAIR_4))
Expand Down
16 changes: 16 additions & 0 deletions VortexEngine/src/Leds/Leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@
#include "../../VortexLib/VortexLib.h"
#endif

#ifdef VORTEX_EMBEDDED
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#include <FastLED.h>
#define LED_PIN 4
#define MOSFET_PIN 18
#endif

// array of led color values
RGBColor Leds::m_ledColors[LED_COUNT] = { RGB_OFF };
// global brightness
uint8_t Leds::m_brightness = DEFAULT_BRIGHTNESS;

bool Leds::init()
{
#ifdef VORTEX_EMBEDDED
FastLED.addLeds<WS2812B, LED_PIN, GRB>((CRGB *)m_ledColors, LED_COUNT);
FastLED.setMaxRefreshRate(0);
pinMode(MOSFET_PIN, OUTPUT);
digitalWrite(MOSFET_PIN, HIGH);
#endif
#ifdef VORTEX_LIB
Vortex::vcallbacks()->ledsInit(m_ledColors, LED_COUNT);
#endif
Expand Down Expand Up @@ -248,6 +261,9 @@ void Leds::holdAll(RGBColor col)

void Leds::update()
{
#ifdef VORTEX_EMBEDDED
FastLED.show(m_brightness);
#endif
#ifdef VORTEX_LIB
Vortex::vcallbacks()->ledsShow();
#endif
Expand Down
20 changes: 10 additions & 10 deletions VortexEngine/src/Memory/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ uint32_t cur_memory_usage_total()
#ifndef VORTEX_LIB

// for C++11 need the following:
void *operator new (size_t size) { return vmalloc(size); }
void *operator new[](size_t size) { return vmalloc(size); }
void operator delete (void *ptr) { vfree(ptr); }
void operator delete[](void *ptr) { vfree(ptr); }
void *operator new (size_t size, void *ptr) noexcept { return ptr; }
void *operator new[](size_t size, void *ptr) noexcept { return ptr; }
void operator delete (void *ptr, size_t size) noexcept { vfree(ptr); }
void operator delete[](void *ptr, size_t size) noexcept { vfree(ptr); }
//void *operator new (size_t size) { return vmalloc(size); }
//void *operator new[](size_t size) { return vmalloc(size); }
//void operator delete (void *ptr) { vfree(ptr); }
//void operator delete[](void *ptr) { vfree(ptr); }
//void *operator new (size_t size, void *ptr) noexcept { return ptr; }
//void *operator new[](size_t size, void *ptr) noexcept { return ptr; }
//void operator delete (void *ptr, size_t size) noexcept { vfree(ptr); }
//void operator delete[](void *ptr, size_t size) noexcept { vfree(ptr); }
//void *operator new (size_t size, std::align_val_t al) { return vmalloc(size); }
//void *operator new[](size_t size, std::align_val_t al) { return vmalloc(size); }
//void operator delete (void *ptr, std::align_val_t al) noexcept { vfree(ptr); }
Expand All @@ -136,7 +136,7 @@ void operator delete[](void *ptr, size_t size) noexcept { vfree(ptr); }
//void operator delete[](void *ptr, size_t size, std::align_val_t al) noexcept { vfree(ptr); }

// needed for C++ virtual functions
extern "C" void __cxa_pure_virtual(void) {}
extern "C" void __cxa_deleted_virtual(void) {}
//extern "C" void __cxa_pure_virtual(void) {}
//extern "C" void __cxa_deleted_virtual(void) {}

#endif
16 changes: 8 additions & 8 deletions VortexEngine/src/Memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ uint32_t cur_memory_usage_total();
#endif

#ifndef VORTEX_LIB
void *operator new (size_t size);
void *operator new[](size_t size);
void operator delete (void *ptr);
void operator delete[](void *ptr);
void *operator new (size_t size, void *ptr) noexcept;
void *operator new[](size_t size, void *ptr) noexcept;
void operator delete (void *ptr, size_t size) noexcept;
void operator delete[](void *ptr, size_t size) noexcept;
//void *operator new (size_t size);
//void *operator new[](size_t size);
//void operator delete (void *ptr);
//void operator delete[](void *ptr);
//void *operator new (size_t size, void *ptr) noexcept;
//void *operator new[](size_t size, void *ptr) noexcept;
//void operator delete (void *ptr, size_t size) noexcept;
//void operator delete[](void *ptr, size_t size) noexcept;
//void *operator new (size_t size, std::align_val_t al);
//void *operator new[](size_t size, std::align_val_t al);
//void operator delete (void *ptr, std::align_val_t al) noexcept;
Expand Down
82 changes: 82 additions & 0 deletions VortexEngine/src/Menus/MainMenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "MainMenu.h"

#include "../Time/TimeControl.h"
#include "../Buttons/Buttons.h"
#include "../Leds/LedTypes.h"
#include "../Leds/Leds.h"

bool MainMenu::m_isOpen = false;
uint8_t MainMenu::m_curSelection = 0;

#define NUM_SELECTIONS (LED_COUNT / 2)

bool MainMenu::init()
{
// main menus start open
m_isOpen = true;
m_curSelection = 0;
return true;
}

bool MainMenu::run()
{
// if the main menus aren't open then nothing to do here
if (!m_isOpen) {
return false;
}

// press <
if (g_pButtonL->onShortClick()) {
pressLeft();
}
// press o
if (g_pButtonM->onShortClick()) {
select();
}
// press >
if (g_pButtonR->onShortClick()) {
pressRight();
}

// render
show();
return true;
}

void MainMenu::show()
{
Leds::clearAll();
// render the main menu
uint8_t hue = 0;
uint32_t now = Time::getCurtime();
MAP_FOREACH_LED(MAP_OUTER_RING) {
Leds::breathIndex(pos, hue, (now / 2), 8, 255, 180);
hue -= (255 / (LED_COUNT / 2));
}
hue = 0;
MAP_FOREACH_LED(MAP_INNER_RING) {
Leds::breathIndex(pos, hue, (now / 2), 8, 255, 180);
hue -= (255 / (LED_COUNT / 2));
}
Leds::blinkIndex((LedPos)m_curSelection);
Leds::blinkIndex((LedPos)(m_curSelection + 10));
}

void MainMenu::pressLeft()
{
m_curSelection = (m_curSelection + 1) % NUM_SELECTIONS;
}

void MainMenu::pressRight()
{
if (!m_curSelection) {
m_curSelection = NUM_SELECTIONS - 1;
} else {
m_curSelection--;
}
}

void MainMenu::select()
{
m_isOpen = false;
}
21 changes: 21 additions & 0 deletions VortexEngine/src/Menus/MainMenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef MAINMENU_H
#define MAINMENU_H

#include <inttypes.h>

class MainMenu
{
public:
static bool init();
static bool run();
static void show();
private:
static void pressLeft();
static void pressRight();
static void select();

static bool m_isOpen;
static uint8_t m_curSelection;
};

#endif
1 change: 1 addition & 0 deletions VortexEngine/src/Patterns/Patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ enum PatternID : int8_t
INTERNAL_PATTERNS_END, // <<< DON'T USE OR TOUCH THIS ONE
PATTERN_MULTI_LAST = (INTERNAL_PATTERNS_END - 1),
PATTERN_MULTI_COUNT = (PATTERN_MULTI_LAST - PATTERN_MULTI_FIRST) + 1,

PATTERN_LAST = PATTERN_MULTI_LAST,
PATTERN_COUNT = (PATTERN_LAST - PATTERN_FIRST) + 1, // total number of patterns
};
Expand Down
4 changes: 4 additions & 0 deletions VortexEngine/src/Serial/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <stdio.h>
#endif

#ifdef VORTEX_EMBEDDED
#include <Arduino.h>
#endif

bool SerialComs::m_serialConnected = false;
uint32_t SerialComs::m_lastCheck = 0;

Expand Down
4 changes: 4 additions & 0 deletions VortexEngine/src/Time/TimeControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ static LARGE_INTEGER tps;
static LARGE_INTEGER start;
#endif

#ifdef VORTEX_EMBEDDED
#include <Arduino.h>
#endif

// static members
#if VARIABLE_TICKRATE == 1
uint32_t Time::m_tickrate = DEFAULT_TICKRATE;
Expand Down
2 changes: 1 addition & 1 deletion VortexEngine/src/VortexConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
//
// The starting default global brightness if there is no savefile
// present The maximum value is 255
#define DEFAULT_BRIGHTNESS 185
#define DEFAULT_BRIGHTNESS 255

// Max Modes
//
Expand Down
Loading

0 comments on commit e430b21

Please sign in to comment.