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

feat ✨: Add controller text support #1

Merged
merged 77 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
dee3d53
add buffer and handling
PA055 May 22, 2024
246c781
added line cycleing
PA055 May 22, 2024
e129183
fix critical bug :)
PA055 May 22, 2024
1042eba
Merge branch 'main' into text
ion098 May 22, 2024
2b8d9c9
add rumble and make clarity changes
PA055 May 22, 2024
4be8668
Merge branch 'text' of https://github.com/PA055/Gamepad into text
PA055 May 22, 2024
3fc76b4
merge changes
PA055 May 22, 2024
0d64b62
oops, forgot the rumble function
PA055 May 22, 2024
f04764b
check for rumble pattern length
PA055 May 23, 2024
c5a8982
changed std::uint... to uint...
PA055 May 23, 2024
acda18e
Minor change to formatting to trigger pros-build action
ion098 May 23, 2024
dd053c2
Merge branch 'LemLib:main' into text
PA055 May 23, 2024
26053a5
Fixed off by one error in Gamepad::updateScreen
ion098 May 24, 2024
735acae
add rumble to cycle
PA055 May 26, 2024
3817758
Merge branch 'text' of https://github.com/PA055/Gamepad into text
PA055 May 26, 2024
d457248
Merge branch 'LemLib:main' into text
PA055 Jun 3, 2024
d1394b3
seperate alerts and prints
PA055 Jun 4, 2024
5cdd7a1
change rumble from alert like to print like
PA055 Jun 8, 2024
2bc3862
add multi line alerts
PA055 Jun 26, 2024
1e8182e
add ability to have newlines in alerts
PA055 Jun 26, 2024
ec5c814
make add_alerts private
PA055 Jun 27, 2024
599d3c1
remove unnessasary lines parameter
PA055 Jun 28, 2024
20138bb
add multiline prints
PA055 Jul 6, 2024
e73d095
add rumbles to alerts
PA055 Jul 8, 2024
57371a6
refactored screen update loop
PA055 Jul 8, 2024
022b4df
add thread safety... hopefully?
PA055 Jul 8, 2024
a84efd3
Merge branch 'main' into text
ion098 Jul 20, 2024
b8eb242
some comments
PA055 Jul 27, 2024
f0fa75f
Merge branch 'text' of https://github.com/PA055/Gamepad into text
PA055 Jul 28, 2024
12f4d6f
finished abstract screen interface
PA055 Aug 12, 2024
7781c59
moved the stuff that needs to be moved... kinda
PA055 Aug 13, 2024
18a4ed6
why am i getting these errors💔
PA055 Aug 13, 2024
66945cf
idk what happened but no errors now, also screen update works hopefully
PA055 Aug 13, 2024
4b17c36
shared pointers :sparkles:
PA055 Aug 13, 2024
6c90b92
it builds now
PA055 Aug 13, 2024
8dbb732
alerts should work
PA055 Aug 18, 2024
3929050
Merge branch 'main' into text
ion098 Aug 23, 2024
23c4bbf
what should i do for this?
PA055 Sep 4, 2024
bf82fef
Merge branch 'text' of https://github.com/PA055/Gamepad into text
PA055 Sep 4, 2024
790929c
bug fixing :sob:
PA055 Sep 10, 2024
d82ef22
help :skull:
PA055 Sep 10, 2024
385fc82
why do i need to commit debug.log :interrobang:
PA055 Sep 10, 2024
8395b9b
Merge branch 'main' into text
PA055 Sep 10, 2024
d5b226a
idk but this breaks it
PA055 Sep 10, 2024
466b8e1
bug: :bug: explicit controller constructor isnt getting called
PA055 Sep 21, 2024
9bfcbb3
fix: :construction: it might work
PA055 Sep 25, 2024
4958fa1
feat: :construction_worker: add vexide sim devcontainer
PA055 Sep 25, 2024
2797d2c
feat: 👷 add launch configs and tasks
PA055 Sep 26, 2024
76f1af3
feat: :construction: Hot/Cold linking breaks it
PA055 Sep 26, 2024
4a70a4a
fix: :construction: reenable hot-cold
ion098 Sep 27, 2024
c50258f
refactor: :twisted_rightwards_arrows: Merge branch 'main' into text
PA055 Sep 27, 2024
b2e027b
fix: :construction: more testing
ion098 Sep 27, 2024
075c379
fix: :bug: Fix usage of unintialized fields
ion098 Oct 10, 2024
fe7fa7a
fix: :bug: initalize attributes in all classes
PA055 Oct 10, 2024
db239d4
chore: :twisted_rightwards_arrows: Merge branches
PA055 Oct 10, 2024
72ecda3
fix: :bug: Fix bug where AbsrtactScreen was not abstract
PA055 Oct 12, 2024
d06277a
fix: :bug: fix nullpointers getting turned into empty strings
PA055 Oct 12, 2024
c357038
fix: :bug: multiples line changes not registering
PA055 Oct 12, 2024
a1c3f15
fix: :bug: screen not being cleared first print
PA055 Oct 12, 2024
dd06cda
chore: :poop: get_priority is the problem, idk why
PA055 Oct 12, 2024
82c0937
test: :sparkles: the alerts are kinda working
PA055 Oct 13, 2024
b1e4093
fix: :bug: repeated alert rumbles
PA055 Oct 13, 2024
aa4904d
chore: :fire: remove debug prints
PA055 Oct 13, 2024
993960f
chore: :fire: remove debug prints
PA055 Oct 13, 2024
5606ac5
Merge branch 'text' of https://github.com/PA055/Gamepad into text
PA055 Oct 13, 2024
a5f29cb
refactor: :art: run clang-format
PA055 Oct 13, 2024
85be74a
feat: :sparkles: disconnect/reconnect logic
PA055 Oct 16, 2024
6812d03
test line clearing
PA055 Oct 31, 2024
9c16e78
Merge branch 'main' into text
ion098 Nov 4, 2024
e27010e
docs: :memo: Added all of the documentation
PA055 Nov 13, 2024
0237fe8
feat: :sparkles: actually impliment the handle_events interface
PA055 Nov 13, 2024
f70c9d6
docs: :memo: Add examples
PA055 Nov 13, 2024
2a7ff7a
fix: :bug: actually make it compile
PA055 Nov 13, 2024
bdcd568
chore: :fire: removed debug.log
PA055 Nov 15, 2024
e0db1e4
refactor: :white_check_mark: address code review comments
PA055 Nov 15, 2024
057f8d7
ci: :fire: remove .devcontainer files because of licence stuff
PA055 Nov 19, 2024
1febcc0
Merge branch 'main' into text
PA055 Dec 7, 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
13 changes: 13 additions & 0 deletions include/gamepad/controller.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once

PA055 marked this conversation as resolved.
Show resolved Hide resolved
#include <cstdint>
#include <deque>
#include <functional>
#include <string>
#include <utility>
#ifndef PROS_USE_SIMPLE_NAMES
#define PROS_USE_SIMPLE_NAMES
#endif
Expand Down Expand Up @@ -47,6 +50,8 @@ class Controller {
* @note Create a separate instance for each task.
*/
void update();

void println(std::uint8_t line, std::string str, std::uint32_t duration);
PA055 marked this conversation as resolved.
Show resolved Hide resolved
/**
* Get the state of a button on the controller.
* @param button Which button's state you want.
Expand All @@ -57,13 +62,21 @@ class Controller {
* @param joystick Which joystick axis's value to return
*/
float operator[](pros::controller_analog_e_t joystick);

Button L1{}, L2{}, R1{}, R2{},
Up{}, Down{}, Left{}, Right{},
X{}, B{}, Y{}, A{};
float LeftX = 0, LeftY = 0, RightX = 0, RightY = 0;
private:
static Button Controller::* button_to_ptr(pros::controller_digital_e_t button);
void updateButton(pros::controller_digital_e_t button_id);
void updateScreen();

std::deque<std::pair<std::string, std::uint32_t>> screen_buffer[3];
PA055 marked this conversation as resolved.
Show resolved Hide resolved
std::pair<std::string, std::uint32_t> screen_contents[3];
PA055 marked this conversation as resolved.
Show resolved Hide resolved
uint32_t line_set_time[3];
PA055 marked this conversation as resolved.
Show resolved Hide resolved
uint8_t last_printed_line = 0;
uint32_t last_print_time = 0;
pros::Controller controller;
}; // namespace Gamepad
}
34 changes: 34 additions & 0 deletions src/gamepad/controller.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include "gamepad/controller.hpp"
#include "pros/rtos.hpp"
#include <cstdint>
#include <cstdlib>
#include <string>
#include <utility>

namespace Gamepad {
void Controller::updateButton(pros::controller_digital_e_t button_id) {
Expand All @@ -15,6 +20,27 @@ void Controller::updateButton(pros::controller_digital_e_t button_id) {
}
}

void Controller::updateScreen() {
if (pros::millis() - this->last_print_time < 50)
return;

for (int i = 1; i < 3; i++) {
PA055 marked this conversation as resolved.
Show resolved Hide resolved
int line = (this->last_printed_line + i) % 3;

if (pros::millis() - this->line_set_time[line] < this->screen_contents[line].second)
PA055 marked this conversation as resolved.
Show resolved Hide resolved
continue;

this->controller.clear_line(line);
PA055 marked this conversation as resolved.
Show resolved Hide resolved
this->controller.set_text(line, 0, this->screen_buffer[line][0].first.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this->controller.set_text(line, 0, this->screen_buffer[line][0].first.c_str());
this->controller.set_text(line + std::string(40, ' '), 0, this->screen_buffer[line][0].first.c_str());

Use extra spaces to clear line instead of using clear_line (see above).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The exact number of spaces will likely need some tuning.

PA055 marked this conversation as resolved.
Show resolved Hide resolved
this->screen_contents[line] = this->screen_buffer[line][0];
this->screen_buffer[line].pop_front();

this->last_printed_line = line;
this->last_print_time = pros::millis();
break;
}
}

void Controller::update() {
for(int i = DIGITAL_L1; i != DIGITAL_A; ++i) {
this->updateButton(static_cast<pros::controller_digital_e_t>(i));
Expand All @@ -24,6 +50,14 @@ void Controller::update() {
this->LeftY = this->controller.get_analog(ANALOG_LEFT_Y);
this->RightX = this->controller.get_analog(ANALOG_RIGHT_X);
this->RightY = this->controller.get_analog(ANALOG_RIGHT_Y);

this->updateScreen();
}

void Controller::println(uint8_t line, std::string str, std::uint32_t duration) {
PA055 marked this conversation as resolved.
Show resolved Hide resolved
if (line > 2) std::exit(1); // TODO: change handling

screen_buffer[line].push_back(std::make_pair(str, duration));
PA055 marked this conversation as resolved.
Show resolved Hide resolved
}

const Button& Controller::operator[](pros::controller_digital_e_t button) {
Expand Down