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

Player indicator fade #3

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions example/led_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void gradient_touchpad_backlight_demo(Gamepad& gamepad)
void player_indicator_demo(Gamepad& gamepad)
{
auto& lights = gamepad.lights();
lights.enable_player_indicator_fade(false);

std::this_thread::sleep_for(1s);

Expand Down Expand Up @@ -171,6 +172,79 @@ void player_indicator_demo(Gamepad& gamepad)
gamepad.push_state();
}

void player_indicator_fade_demo(Gamepad& gamepad)
{
auto& lights = gamepad.lights();
lights.enable_player_indicator_fade(true);

std::this_thread::sleep_for(1s);

std::cout << "5..";
std::flush(std::cout);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::PLAYER_FIVE);
gamepad.push_state();

std::this_thread::sleep_for(1s);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::DISABLED);
gamepad.push_state();

std::this_thread::sleep_for(1s);

std::cout << "4..";
std::flush(std::cout);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::PLAYER_FOUR);
gamepad.push_state();

std::this_thread::sleep_for(1s);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::DISABLED);
gamepad.push_state();

std::this_thread::sleep_for(1s);

std::cout << "3..";
std::flush(std::cout);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::PLAYER_THREE);
gamepad.push_state();

std::this_thread::sleep_for(2s);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::DISABLED);
gamepad.push_state();

std::this_thread::sleep_for(1s);

std::cout << "2..";
std::flush(std::cout);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::PLAYER_TWO);
gamepad.push_state();

std::this_thread::sleep_for(2s);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::DISABLED);
gamepad.push_state();

std::this_thread::sleep_for(1s);

std::cout << "1..";
std::flush(std::cout);

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::PLAYER_ONE);
gamepad.push_state();

std::this_thread::sleep_for(2s);

std::cout << "0" << std::endl;

gamepad.lights().set_player_indicator(dual_sense_hid::Gamepad::Lights::PlayerIndicator::DISABLED);
gamepad.push_state();
}

void mute_mic_indicator_demo(Gamepad& gamepad)
{
auto& lights = gamepad.lights();
Expand Down Expand Up @@ -228,8 +302,12 @@ int main(int argc, char **argv)

gradient_touchpad_backlight_demo(demo_device);

std::cout << "Countdown..." << std::endl;
player_indicator_demo(demo_device);

std::cout << "Countdown with fade..." << std::endl;
player_indicator_fade_demo(demo_device);

mute_mic_indicator_demo(demo_device);

return 0;
Expand Down
7 changes: 7 additions & 0 deletions include/dual_sense_hid/gamepad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ namespace dual_sense_hid
*/
void set_player_indicator_brightness(PlayerIndicatorBrightness brightness);

/**
* @brief Control player indicator fade (instant changes or smooth fading in)
* @param enabled fade enabled
*/
void enable_player_indicator_fade(bool enabled);

/**
* @brief Set color of touchpad backlight
* @param red brightness level
Expand All @@ -108,6 +114,7 @@ namespace dual_sense_hid
MuteLightMode mute_light_mode_;

PlayerIndicator player_indicator_;
bool player_indicator_fade_enabled_;
PlayerIndicatorBrightness player_indicator_brightness_;

uint8_t touchpad_light_red_;
Expand Down
11 changes: 10 additions & 1 deletion src/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ namespace dual_sense_hid

void Gamepad::Lights::set_mute_light_mode(MuteLightMode mute_light_mode)
{
changed_ |= mute_light_mode_ == mute_light_mode;
changed_ |= mute_light_mode_ != mute_light_mode;

mute_light_mode_ = mute_light_mode;
}

void Gamepad::Lights::enable_player_indicator_fade(bool enabled)
{
changed_ |= enabled != player_indicator_fade_enabled_;

player_indicator_fade_enabled_ = enabled;
}

Gamepad::Gamepad(const DeviceInfo &device_info, bool fetch_calibration_data)
:connection_type_(device_info.connection_type)
{
Expand Down Expand Up @@ -367,6 +374,8 @@ namespace dual_sense_hid
common_report.player_led.led_5 = true;
}

common_report.player_led.led_fade = !lights_.player_indicator_fade_enabled_;

common_report.touchpad_led_color.red_led = lights_.touchpad_light_red_;
common_report.touchpad_led_color.green_led = lights_.touchpad_light_green_;
common_report.touchpad_led_color.blue_led = lights_.touchpad_light_blue_;
Expand Down
Loading