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

Draft
wants to merge 67 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 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
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
62 changes: 62 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM rust:1.67 as builder

RUN git clone https://github.com/ion098/vex-v5-qemu.git -b feat/hot-cold --single-branch /vex-v5-qemu

WORKDIR /vex-v5-qemu
RUN cd packages/kernel; cargo build --target-dir /target/kernel

RUN cd packages/client-cli; cargo install --path . --root /target/client-cli

FROM mcr.microsoft.com/devcontainers/cpp:1.0-jammy
# ------------
# Install Required Packages
# ------------
RUN sudo apt-get update
COPY ./.devcontainer/packagelist /packagelist
RUN sudo apt-get -y install $(cat /packagelist)
RUN rm /packagelist # Cleanup image
RUN sudo apt-get clean # Cleanup image

# ------------
# Install Clangd
# ------------
RUN curl -sLo clangd.zip $( \
curl -s https://api.github.com/repos/clangd/clangd/releases/latest \
| jq -r '[.assets[] | select(.name | test ("^clangd-linux"))][0].browser_download_url' \
) \
&& unzip clangd.zip -d /usr/local/share \
&& mv /usr/local/share/clangd_*/ /usr/local/share/clangd \
&& rm clangd.zip

ENV PATH="$PATH:/usr/local/share/clangd/bin"

# ------------
# Install PROS CLI
# ------------
RUN python3 -m pip install pros-cli

# ------------
# Install ARM Toolchain
# ------------
COPY --from=ghcr.io/lemlib/pros-build:v2.0.2 /gcc-arm-none-eabi-10.3-2021.10 /usr/local/share/arm-none-eabi
ENV PATH="$PATH:/usr/local/share/arm-none-eabi/bin"

# Copy the simulator binary
COPY --from=builder /target/client-cli/bin/client-cli /usr/local/bin/simulator

# Clone pros kernel source so we can reference it when debugging
COPY ./project.pros /project.pros
ENV PROS_SOURCE_PATH="$HOME/.pros"
RUN git clone https://github.com/purduesigbots/pros.git $PROS_SOURCE_PATH \
--depth 1 \
--branch $(</project.pros jq -r '.["py/state"].templates.kernel.version')
RUN rm /project.pros # Cleanup image

# Copy the sim kernel, as its required to run the simulator
ENV V5_SIM_PATH="$HOME/.vex-v5-qemu"
ENV V5_SIM_KERNEL_PATH="$V5_SIM_PATH/kernel"
COPY --from=builder /target/kernel/armv7a-none-eabi/debug/kernel $V5_SIM_KERNEL_PATH

# Copy the sim source, so we can reference it when debugging
ENV V5_SIM_SOURCE_PATH="$V5_SIM_PATH/source"
COPY --from=builder /vex-v5-qemu $V5_SIM_SOURCE_PATH
13 changes: 12 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"postCreateCommand": "chmod 777 .devcontainer/postCreateCommand.bash && .devcontainer/postCreateCommand.bash && source ~/.bashrc"
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"customizations": {
"vscode": {
"settings": {
"clangd.path": "/usr/local/share/clangd/bin/clangd"
}
}
}
// "postCreateCommand": "chmod 777 .devcontainer/postCreateCommand.bash && .devcontainer/postCreateCommand.bash && source ~/.bashrc"
}
6 changes: 6 additions & 0 deletions .devcontainer/packagelist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git
python3-minimal
python3-pip
qemu-system
gdb-multiarch
jq
6 changes: 6 additions & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[0909/102831.528:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
[0909/102852.263:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
[0910/182219.664:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
[0910/183206.884:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
[0910/183223.865:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
[0910/183232.392:ERROR:registration_protocol_win.cc(108)] CreateFile: The system cannot find the file specified. (0x2)
3 changes: 2 additions & 1 deletion include/gamepad/api.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "gamepad/event_handler.hpp" // IWYU pragma: export
#include "gamepad/controller.hpp" // IWYU pragma: export
#include "gamepad/gamepad.hpp" // IWYU pragma: export
#include "gamepad/screens/alertScreen.hpp" // IWYU pragma: export
57 changes: 54 additions & 3 deletions include/gamepad/controller.hpp → include/gamepad/gamepad.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#pragma once

#include "pros/misc.h"
#include "screens/defaultScreen.hpp"
#include <cstdint>
#include <string>

#include <memory>
#include <vector>
#include <sys/types.h>
#include "screens/abstractScreen.hpp"
#include "button.hpp"
#include "pros/misc.hpp"

Expand All @@ -26,6 +31,37 @@ class Gamepad {
*
*/
void update();
/**
* Add a screen to the sceen update loop that can update the controller's screen
*
* @param screen the `AbstractScreen` to add to the screen queue
*/
void add_screen(std::shared_ptr<AbstractScreen> screen);
/**
* print a line to the console like pros (low priority)
*
* @param line the line number to print the string on (0-2)
* @param str the string to print onto the controller (\n to go to the next line)
*/
void print_line(uint8_t line, std::string str);
/**
* @brief clears all lines on the controller, similar to the pros function (low priority)
*
*/
void clear();
/**
* @brief clears the specific line on the controller, similar to the pros function clear_line (low priority)
*
* @param line the line to clear (0-2)
*/
void clear(uint8_t line);
/**
* makes the controller rumble like pros (low priority)
*
* @param rumble_pattern A string consisting of the characters '.', '-', and ' ', where dots are short rumbles,
* dashes are long rumbles, and spaces are pauses. Maximum supported length is 8 characters.
*/
void rumble(std::string rumble_pattern);
/**
* @brief Get the state of a button on the controller.
*
Expand Down Expand Up @@ -75,7 +111,9 @@ class Gamepad {
static Gamepad partner;
private:
Gamepad(pros::controller_id_e_t id)
: controller(id) {}
: controller(id) {
this->add_screen(defaultScreen);
}

Button m_L1 {}, m_L2 {}, m_R1 {}, m_R2 {}, m_Up {}, m_Down {}, m_Left {}, m_Right {}, m_X {}, m_B {}, m_Y {},
m_A {};
Expand All @@ -90,9 +128,22 @@ class Gamepad {
* @return std::string A unique listener name
*/
static std::string unique_name();
static Button Gamepad::*button_to_ptr(pros::controller_digital_e_t button);
static Button Gamepad::* button_to_ptr(pros::controller_digital_e_t button);
void updateButton(pros::controller_digital_e_t button_id);

void updateScreens();

std::shared_ptr<DefaultScreen> defaultScreen = std::make_shared<DefaultScreen>();
std::vector<std::shared_ptr<AbstractScreen>> screens {};
ScreenBuffer currentScreen {};
ScreenBuffer nextBuffer {};
pros::Controller controller;

uint8_t last_printed_line = 0;
uint last_print_time = 0;
uint last_update_time = 0;
bool screenCleared = false;
pros::Mutex mut {};
};

inline Gamepad Gamepad::master {pros::E_CONTROLLER_MASTER};
Expand Down
34 changes: 34 additions & 0 deletions include/gamepad/screens/abstractScreen.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <array>
#include <optional>
#include <set>
#include <string>
#include <sys/types.h>
#include "pros/misc.h"

namespace gamepad {

/**
* @brief type for conveying a full screen with the first 3 being the lines
* of text on the controller screen and the last being a rumble pattern
*/
typedef std::array<std::optional<std::string>, 4> ScreenBuffer;

class AbstractScreen {
public:
AbstractScreen(uint priority)
: priority(priority) {}

virtual void update(uint delta_time) {}

virtual ScreenBuffer get_screen(std::set<uint8_t> visible_lines) = 0;

virtual void handle_events(std::set<pros::controller_digital_e_t> button_events) {}

uint get_priority() { return this->priority; }
protected:
const uint priority;
};

} // namespace gamepad
34 changes: 34 additions & 0 deletions include/gamepad/screens/alertScreen.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <cstdint>
#include <deque>
#include <optional>
#include <string>
#include "abstractScreen.hpp"
#include "pros/rtos.hpp"
#include "gamepad/screens/abstractScreen.hpp"

namespace gamepad {

class AlertScreen : public AbstractScreen {
public:
AlertScreen()
: AbstractScreen(UINT32_MAX - 100) {}

void update(uint delta_time);
ScreenBuffer get_screen(std::set<uint8_t> visible_lines);

void add_alerts(uint8_t line, std::string strs, uint32_t duration, std::string rumble = "");
private:
struct AlertBuffer {
ScreenBuffer screen;
uint duration;
};

std::deque<AlertBuffer> screen_buffer {};
std::optional<AlertBuffer> screen_contents {};
uint line_set_time = 0;
pros::Mutex mut {};
};

} // namespace gamepad
22 changes: 22 additions & 0 deletions include/gamepad/screens/defaultScreen.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "gamepad/screens/abstractScreen.hpp"
#include "pros/rtos.hpp"

namespace gamepad {

class DefaultScreen : public AbstractScreen {
public:
DefaultScreen()
: AbstractScreen(1) {}

ScreenBuffer get_screen(std::set<uint8_t> visible_lines);

void print_line(uint8_t line, std::string str);
void rumble(std::string rumble_pattern);
private:
ScreenBuffer currentBuffer {};
pros::Mutex mut {};
};

} // namespace gamepad
65 changes: 0 additions & 65 deletions src/gamepad/controller.cpp

This file was deleted.

Loading