Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9c68853
Convert aeos branch to C (aeos-c)
livingkurt Oct 16, 2025
9459776
Update CLI to use C API directly with extern C guards
livingkurt Oct 16, 2025
b2781d7
Fix POSIX function declarations for Linux compatibility
livingkurt Oct 16, 2025
717f09a
Refactor Helios state management and color selection logic. Introduce…
livingkurt Oct 17, 2025
cd714b3
Fix CLI test issues: increase INPUT_QUEUE_SIZE to 4096 and enable wak…
livingkurt Oct 17, 2025
6fd0f59
Enable wake on button press in sleep mode for CLI
livingkurt Oct 17, 2025
f88b13a
Add Helios core functionality: Implement button handling, color manag…
livingkurt Oct 17, 2025
b4ee18b
Refactor Makefile for HeliosCLI: Remove C++ compiler references and u…
livingkurt Oct 17, 2025
a55e7d0
Update .gitignore: Add rules to include test and configuration files,…
livingkurt Oct 17, 2025
5b4d8aa
Update Makefile for HeliosCLI: Change compiler from GCC to G++ and up…
livingkurt Oct 17, 2025
6601c8d
Refactor Makefile for HeliosCLI: Remove standard C++ library from lin…
livingkurt Oct 17, 2025
c4fbec2
Enhance EEPROM dump output in HeliosCLI: Include additional flags for…
livingkurt Oct 17, 2025
243c85c
Revert comment style changes back to C++ style comments
livingkurt Oct 18, 2025
88e270c
Convert remaining C-style comments to C++ style comments including mu…
livingkurt Oct 18, 2025
f9e3e9c
Restore meaningful multi-line comments in aeos-c branch
livingkurt Oct 18, 2025
110b9f5
Refactor comments in Button.cpp: Restore and enhance multi-line comme…
livingkurt Oct 18, 2025
c37083c
Enhance button handling in Button.cpp: Add a comment to clarify the p…
livingkurt Oct 18, 2025
c30b6a3
Fix missing and empty comments in Patterns.cpp and Colorset.cpp
livingkurt Oct 18, 2025
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
638 changes: 360 additions & 278 deletions Helios/Button.cpp

Large diffs are not rendered by default.

186 changes: 76 additions & 110 deletions Helios/Button.h
Original file line number Diff line number Diff line change
@@ -1,119 +1,85 @@
#include <stdint.h>
#ifndef BUTTON_H
#define BUTTON_H

#ifdef HELIOS_CLI
#include <queue>
#ifdef __cplusplus
extern "C" {
#endif

class Button
{
public:
// initialize a new button object with a pin number
static bool init();
// directly poll the pin for whether it's pressed right now
static bool check();
// poll the button pin and update the state of the button object
static void update();

// whether the button was pressed this tick
static bool onPress() { return m_newPress; }
// whether the button was released this tick
static bool onRelease() { return m_newRelease; }
// whether the button is currently pressed
static bool isPressed() { return m_isPressed; }

// whether the button was shortclicked this tick
static bool onShortClick() { return m_shortClick; }
// whether the button was long clicked this tick
static bool onLongClick() { return m_longClick; }
// whether the button was hold clicked this tick
static bool onHoldClick() { return m_holdClick; }

// detect if the button is being held past long click
static bool holdPressing();

// when the button was last pressed
static uint32_t pressTime() { return m_pressTime; }
// when the button was last released
static uint32_t releaseTime() { return m_releaseTime; }

// how long the button is currently or was last held down (in ticks)
static uint32_t holdDuration() { return m_holdDuration; }
// how long the button is currently or was last released for (in ticks)
static uint32_t releaseDuration() { return m_releaseDuration; }

// the number of releases
static uint8_t releaseCount() { return m_releaseCount; }

// enable wake on press
static void enableWake();
#include <stdint.h>

// Initialize button
uint8_t button_init(void);

// Directly poll the pin for whether it's pressed right now
uint8_t button_check(void);

// Poll the button pin and update the state of the button object
void button_update(void);

// Whether the button was pressed this tick
uint8_t button_on_press(void);

// Whether the button was released this tick
uint8_t button_on_release(void);

// Whether the button is currently pressed
uint8_t button_is_pressed(void);

// Whether the button was shortclicked this tick
uint8_t button_on_short_click(void);

// Whether the button was long clicked this tick
uint8_t button_on_long_click(void);

// Whether the button was hold clicked this tick
uint8_t button_on_hold_click(void);

// Detect if the button is being held past long click
uint8_t button_hold_pressing(void);

// When the button was last pressed
uint32_t button_press_time(void);

// When the button was last released
uint32_t button_release_time(void);

// How long the button is currently or was last held down (in ticks)
uint32_t button_hold_duration(void);

// How long the button is currently or was last released for (in ticks)
uint32_t button_release_duration(void);

// The number of releases
uint8_t button_release_count(void);

// Enable wake on press
void button_enable_wake(void);

#ifdef HELIOS_CLI
// these will 'inject' a short/long click without actually touching the
// button state, it's important that code uses 'onShortClick' or
// 'onLongClick' to capture this injected input event. Code that uses
// for example: 'button.holdDuration() >= threshold && button.onRelease()'
// will never trigger because the injected input event doesn't actually
// press the button or change the button state it just sets the 'shortClick'
// or 'longClick' values accordingly
static void doShortClick();
static void doLongClick();
static void doHoldClick();

// this will actually press down the button, it's your responsibility to wait
// for the appropriate number of ticks and then release the button
static void doPress();
static void doRelease();
static void doToggle();

// queue up an input event for the button
static void queueInput(char input);
static uint32_t inputQueueSize();
// These will 'inject' a short/long click without actually touching the
// button state, it's important that code uses 'button_on_short_click' or
// 'button_on_long_click' to capture this injected input event. Code that uses
// for example: 'button_hold_duration() >= threshold && button_on_release()'
// will never trigger because the injected input event doesn't actually
// press the button or change the button state it just sets the 'shortClick'
// or 'longClick' values accordingly
void button_do_short_click(void);
void button_do_long_click(void);
void button_do_hold_click(void);

// This will actually press down the button, it's your responsibility to wait
// for the appropriate number of ticks and then release the button
void button_do_press(void);
void button_do_release(void);
void button_do_toggle(void);

// Queue up an input event for the button
void button_queue_input(char input);
uint32_t button_input_queue_size(void);
#endif

private:
// ========================================
// state data that is populated each check

// the timestamp of when the button was pressed
static uint32_t m_pressTime;
// the timestamp of when the button was released
static uint32_t m_releaseTime;

// the last hold duration
static uint32_t m_holdDuration;
// the last release duration
static uint32_t m_releaseDuration;

// the number of times released, will overflow at 255
static uint8_t m_releaseCount;

// the active state of the button
static bool m_buttonState;

// whether pressed this tick
static bool m_newPress;
// whether released this tick
static bool m_newRelease;
// whether currently pressed
static bool m_isPressed;
// whether a short click occurred
static bool m_shortClick;
// whether a long click occurred
static bool m_longClick;
// whether a long hold occurred
static bool m_holdClick;
#ifdef __cplusplus
}
#endif

#ifdef HELIOS_CLI
// process pre or post input events from the queue
static bool processPreInput();
static bool processPostInput();

// an input queue for the button, each tick one even is processed
// out of this queue and used to produce input
static std::queue<char> m_inputQueue;
// the virtual pin state that is polled instead of a digital pin
static bool m_pinState;
// whether the button is waiting to wake the device
static bool m_enableWake;
#endif
};
Loading
Loading