Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel/chromadeck/next work #135

Merged
merged 25 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4505809
idk
Unreal-Dan Nov 14, 2023
3e4ccb8
stuff
Unreal-Dan Nov 14, 2023
ffc4994
idk
Unreal-Dan Nov 14, 2023
e9f3bba
idk for now
Unreal-Dan Nov 15, 2023
357cdcf
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Dec 1, 2023
5ff4b49
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Dec 12, 2023
7cf6bd2
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Dec 12, 2023
3692174
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Dec 21, 2023
e16f3b1
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Dec 23, 2023
24b7921
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Dec 24, 2023
c4dfda1
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Jan 1, 2024
f811d59
testing VL
Unreal-Dan Jan 1, 2024
79e0c1f
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Jan 19, 2024
8f3e966
some fixes
Unreal-Dan Jan 19, 2024
b1d7de1
Pin nums updated for new hardware
LivingSynthesis Jan 22, 2024
403072d
fix button init
LivingSynthesis Jan 23, 2024
f87c21c
loggin level evil
LivingSynthesis Jan 25, 2024
491fa2f
reversed direction
Unreal-Dan Jan 25, 2024
97098bf
Merge branch 'daniel/chromadeck/next_work' of https://github.com/Unre…
Unreal-Dan Jan 25, 2024
d9a5ee0
Merge branch 'chromadeck' into daniel/chromadeck/next_work
Unreal-Dan Jan 25, 2024
cb17757
fix the filters
Unreal-Dan Jan 25, 2024
28e3e21
recorded tests
Unreal-Dan Jan 25, 2024
da025ff
testing new VLReceiver approach
Unreal-Dan Jan 26, 2024
7de94c5
wrong adc channel
Unreal-Dan Jan 26, 2024
0e4287c
removed useless stuff
Unreal-Dan Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions VortexEngine/VortexEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
<Filter>Source Files\Wireless</Filter>
</ClCompile>
<ClCompile Include="src\Menus\MainMenu.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\Menus</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -555,7 +555,7 @@
<Filter>Header Files\Wireless</Filter>
</ClInclude>
<ClInclude Include="src\Menus\MainMenu.h">
<Filter>Header Files</Filter>
<Filter>Header Files\Menus</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion VortexEngine/src/Buttons/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool Button::init(uint8_t pin)
m_releaseDuration = 0;
m_consecutivePresses = 0;
m_releaseCount = 0;
m_buttonState = check();
m_buttonState = false;
m_newPress = false;
m_newRelease = false;
m_isPressed = m_buttonState;
Expand Down
6 changes: 3 additions & 3 deletions VortexEngine/src/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Button Buttons::m_buttons[NUM_BUTTONS];
bool Buttons::init()
{
// initialize the button on pins 9/10/11
if (!m_buttons[0].init(9) ||
!m_buttons[1].init(10) ||
!m_buttons[2].init(11)) {
if (!m_buttons[0].init(5) ||
!m_buttons[1].init(6) ||
!m_buttons[2].init(7)) {
return false;
}
g_pButtonL = &m_buttons[0];
Expand Down
18 changes: 18 additions & 0 deletions VortexEngine/src/Leds/LedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ inline LedPos mapGetNextLed(LedMap map, LedPos pos)
#define MAP_PAIR_EVEN_EVENS (MAP_PAIR_EVEN(PAIR_3) | MAP_PAIR_EVEN(PAIR_1))
#define MAP_PAIR_EVEN_ODDS (MAP_PAIR_ODD(PAIR_3) | MAP_PAIR_ODD(PAIR_1))

#define MAP_RING_INNER (MAP_LED(LED_0) | MAP_LED(LED_1) | MAP_LED(LED_2) | MAP_LED(LED_3) | \
MAP_LED(LED_4) | MAP_LED(LED_5) | MAP_LED(LED_6) | MAP_LED(LED_7) | \
MAP_LED(LED_8) | MAP_LED(LED_9))
#define MAP_RING_OUTER (MAP_LED(LED_10) | MAP_LED(LED_11) | MAP_LED(LED_12) | MAP_LED(LED_13) | \
MAP_LED(LED_14) | MAP_LED(LED_15) | MAP_LED(LED_16) | MAP_LED(LED_17) | \
MAP_LED(LED_18) | MAP_LED(LED_19))

#define MAP_RING_INNER_EVEN (MAP_RING_INNER & 0xAAAAAAAA)
#define MAP_RING_INNER_ODD (MAP_RING_INNER & 0x55555555)
#define MAP_RING_OUTER_EVEN (MAP_RING_OUTER & 0xAAAAAAAA)
#define MAP_RING_OUTER_ODD (MAP_RING_OUTER & 0x55555555)

#define MAP_LINE_1 (MAP_LED(LED_0) | MAP_LED(LED_10) | MAP_LED(LED_15) | MAP_LED(LED_5))
#define MAP_LINE_2 (MAP_LED(LED_1) | MAP_LED(LED_11) | MAP_LED(LED_16) | MAP_LED(LED_6))
#define MAP_LINE_3 (MAP_LED(LED_2) | MAP_LED(LED_12) | MAP_LED(LED_17) | MAP_LED(LED_7))
#define MAP_LINE_4 (MAP_LED(LED_3) | MAP_LED(LED_13) | MAP_LED(LED_18) | MAP_LED(LED_8))
#define MAP_LINE_5 (MAP_LED(LED_4) | MAP_LED(LED_14) | MAP_LED(LED_19) | MAP_LED(LED_9))

// set a single led
inline void setLed(LedMap &map, LedPos pos)
{
Expand Down
5 changes: 1 addition & 4 deletions VortexEngine/src/Leds/Leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#ifdef VORTEX_EMBEDDED
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#include <FastLED.h>
#define LED_PIN 4
#define MOSFET_PIN 18
#define LED_PIN 0
#endif

// global brightness
Expand All @@ -29,8 +28,6 @@ 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);
Expand Down
30 changes: 24 additions & 6 deletions VortexEngine/src/Menus/MainMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "MainMenu.h"

#include "../Time/TimeControl.h"
#include "../Storage/Storage.h"
#include "../Buttons/Buttons.h"
#include "../Leds/LedTypes.h"
#include "../Modes/Modes.h"
#include "../Leds/Leds.h"
#include "../Log/Log.h"

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

#define NUM_SELECTIONS (LED_COUNT / 2)
Expand Down Expand Up @@ -51,23 +54,28 @@ void MainMenu::show()
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 += (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));
hue += (255 / (LED_COUNT / 2));
}
Leds::blinkIndex((LedPos)m_curSelection);
Leds::blinkIndex((LedPos)(m_curSelection + 10));
}

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

void MainMenu::pressRight()
bool MainMenu::isOpen()
{
return m_isOpen;
}

void MainMenu::pressLeft()
{
if (!m_curSelection) {
m_curSelection = NUM_SELECTIONS - 1;
Expand All @@ -76,7 +84,17 @@ void MainMenu::pressRight()
}
}

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

void MainMenu::select()
{
m_isOpen = false;
Storage::setStoragePage(m_curSelection);
if (!Modes::loadStorage()) {
Modes::setDefaults();
}
DEBUG_LOGF("Selected storage page: %u", m_curSelection);
}
4 changes: 4 additions & 0 deletions VortexEngine/src/Menus/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class MainMenu
static bool init();
static bool run();
static void show();

// open the main menu
static void open();
static bool isOpen();
private:
static void pressLeft();
static void pressRight();
Expand Down
129 changes: 82 additions & 47 deletions VortexEngine/src/Menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,53 @@
#include "../Leds/Leds.h"
#include "../Log/Log.h"

// this is an array of possible LED maps for LED selection
static LedMap ledPermutations[] = {
MAP_LED_ALL,
MAP_LED(LED_MULTI),
MAP_RING_INNER,
MAP_RING_OUTER,

MAP_RING_INNER_EVEN,
MAP_RING_INNER_ODD,
MAP_RING_OUTER_EVEN,
MAP_RING_OUTER_ODD,

MAP_LINE_1,
MAP_LINE_2,
MAP_LINE_3,
MAP_LINE_4,
MAP_LINE_5,

MAP_LED(LED_0),
MAP_LED(LED_1),
MAP_LED(LED_2),
MAP_LED(LED_3),
MAP_LED(LED_4),
MAP_LED(LED_5),
MAP_LED(LED_6),
MAP_LED(LED_7),
MAP_LED(LED_8),
MAP_LED(LED_9),
MAP_LED(LED_10),
MAP_LED(LED_11),
MAP_LED(LED_12),
MAP_LED(LED_13),
MAP_LED(LED_14),
MAP_LED(LED_15),
MAP_LED(LED_16),
MAP_LED(LED_17),
MAP_LED(LED_18),
MAP_LED(LED_19),
};

#define NUM_PERMUTATIONS (sizeof(ledPermutations)/ sizeof(ledPermutations[0]))

Menu::Menu(const RGBColor &col, bool advanced) :
m_previewMode(),
m_menuColor(col),
m_targetLeds(MAP_LED_ALL),
m_targetLeds(MAP_LED_NONE),
m_ledSelection(0),
m_curSelection(0),
m_ledSelected(false),
m_advanced(advanced),
Expand Down Expand Up @@ -42,6 +85,8 @@ bool Menu::init()
return false;
}
}
// reset the current selection
m_curSelection = 0;
// copy the current mode into the demo mode and initialize it
m_previewMode = *Modes::curMode();
m_previewMode.init();
Expand Down Expand Up @@ -69,19 +114,28 @@ Menu::MenuAction Menu::run()
// there is no guarantee the child class will call the parent
// class's onShortClick and onLongClick functions so

// every time the button is clicked, change the target led
if (g_pButtonM->onShortClick()) {
do {
nextBulbSelection();
} while (!isValidLedSelection(m_targetLeds));
// every time a button is clicked, change the led selection
if (g_pButtonR->onShortClick()) {
m_ledSelection = (m_ledSelection + 1) % NUM_PERMUTATIONS;
}
if (g_pButtonL->onShortClick()) {
m_ledSelection = (m_ledSelection > 0) ? (m_ledSelection - 1) : (NUM_PERMUTATIONS - 1);
}
// on a long press of the button, lock in the target led
if (g_pButtonM->onLongClick()) {
// if no target, set at least cur mask
if (m_targetLeds == 0) {
//if (m_targetLeds == MAP_LED_NONE) {
addSelectionMask();
}
m_ledSelected = true;
// call led selected callback
onLedSelected();
}

// on a long press of the 2nd button, add to selection
if (g_pButtonR->onLongClick()) {
addSelectionMask();
}
// render the bulb selection
showBulbSelection();

Expand All @@ -94,11 +148,15 @@ Menu::MenuAction Menu::run()
void Menu::showBulbSelection()
{
Leds::clearAll();
if (m_targetLeds == MAP_LED(LED_MULTI)) {
if (ledPermutations[m_ledSelection] == MAP_LED(LED_MULTI)) {
LedPos pos = (LedPos)((Time::getCurtime() / 30) % LED_COUNT);
Leds::blinkIndexOffset(pos, pos * 10, 50, 500, m_menuColor);
for (int dots = 0; dots < 4; ++dots) {
LedPos dotPos = (LedPos)((pos + (dots * (LED_COUNT / 4))) % LED_COUNT);
Leds::blinkIndexOffset(dotPos, dotPos * 10, 50, 500, m_menuColor);
}
} else {
Leds::blinkMap(m_targetLeds, BULB_SELECT_OFF_MS, BULB_SELECT_ON_MS, m_menuColor);
Leds::setMap(m_targetLeds, RGB_ORANGE);
Leds::blinkMap(ledPermutations[m_ledSelection], BULB_SELECT_OFF_MS, BULB_SELECT_ON_MS, m_menuColor);
}
// blink when selecting
Menus::showSelection(RGBColor(m_menuColor.red << 3,
Expand All @@ -117,43 +175,6 @@ void Menu::showExit()
Leds::blinkAll(EXIT_MENU_OFF_MS, EXIT_MENU_ON_MS, RGB_RED0);
}

void Menu::nextBulbSelection()
{
Mode *cur = Modes::curMode();
// The target led can be 0 through LED_COUNT to represent any led or all leds
// modulo by LED_COUNT + 1 to include LED_COUNT (all) as a target
switch (m_targetLeds) {
case MAP_LED_ALL:
if (cur->isMultiLed()) {
// do not allow multi led to select anything else
//break;
}
m_targetLeds = MAP_LED(LED_FIRST);
break;
case MAP_LED(LED_LAST):
m_targetLeds = MAP_PAIR_EVENS;
break;
case MAP_PAIR_EVENS:
m_targetLeds = MAP_PAIR_ODDS;
break;
case MAP_PAIR_ODDS:
m_targetLeds = MAP_LED(LED_MULTI);
break;
case MAP_LED(LED_MULTI):
m_targetLeds = MAP_LED_ALL;
break;
default: // LED_FIRST through LED_LAST
// do not allow multi led to select anything else
if (cur->isMultiLed()) {
//m_targetLeds = MAP_LED_ALL;
//break;
}
// iterate as normal
m_targetLeds = MAP_LED(((mapGetFirstLed(m_targetLeds) + 1) % (LED_COUNT + 1)));
break;
}
}

void Menu::onLedSelected()
{
}
Expand All @@ -174,3 +195,17 @@ void Menu::leaveMenu(bool doSave)
Modes::saveStorage();
}
}

// this adds the currently targeted ledPermutation to the selected leds
void Menu::addSelectionMask() {
// if selecting any of the individual leds then toggle
uint32_t mask = ledPermutations[m_ledSelection];
// checks if only 1 b it is set in the target mask
if ((mask & (mask - 1)) == 0) {
// if there's only one bit set then toggle that location
m_targetLeds ^= mask;
} else {
// otherwise just add the mask whatever it is
m_targetLeds |= mask;
}
}
5 changes: 5 additions & 0 deletions VortexEngine/src/Menus/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Menu

// iterate to next bulb selection
void nextBulbSelection();
void prevBulbSelection();

// an overridable api that allows derived menus to decide which led selections
// should be available before they have actually opened
Expand All @@ -55,6 +56,8 @@ class Menu
// tracks the targetted leds for this menu
// note this is an led map
LedMap m_targetLeds;
// current index of led maps
uint16_t m_ledSelection;
// all menus have a 'current selection'
uint8_t m_curSelection;
// true once a an led is selected
Expand All @@ -65,6 +68,8 @@ class Menu
private:
// internal flag to close the menu
bool m_shouldClose;
// add to the current selection of leds
void addSelectionMask();

#ifdef VORTEX_LIB
friend class Vortex;
Expand Down
Loading
Loading