2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
#include "DriverStationGui.h"
|
|
|
|
|
|
2021-01-12 22:57:04 -05:00
|
|
|
#include <algorithm>
|
2020-09-02 20:51:43 -07:00
|
|
|
#include <atomic>
|
2019-09-23 00:24:10 -07:00
|
|
|
#include <cstring>
|
2020-08-14 20:02:35 -07:00
|
|
|
#include <memory>
|
2019-09-23 00:24:10 -07:00
|
|
|
#include <string>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <string_view>
|
2020-08-14 20:02:35 -07:00
|
|
|
#include <vector>
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <fmt/format.h>
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <glass/Context.h>
|
|
|
|
|
#include <glass/Storage.h>
|
|
|
|
|
#include <glass/other/FMS.h>
|
|
|
|
|
#include <glass/support/ExtraGuiWidgets.h>
|
|
|
|
|
#include <glass/support/NameSetting.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <hal/DriverStationTypes.h>
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/simulation/DriverStationData.h>
|
|
|
|
|
#include <hal/simulation/MockHooks.h>
|
2019-09-23 00:24:10 -07:00
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <imgui_internal.h>
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
#include <wpi/SmallVector.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <wpi/StringExtras.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <wpigui.h>
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
#include "HALDataSource.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
#include "HALSimGui.h"
|
|
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
struct HALJoystickData {
|
|
|
|
|
HALJoystickData() {
|
|
|
|
|
std::memset(&desc, 0, sizeof(desc));
|
|
|
|
|
desc.type = -1;
|
|
|
|
|
std::memset(&axes, 0, sizeof(axes));
|
|
|
|
|
std::memset(&buttons, 0, sizeof(buttons));
|
|
|
|
|
std::memset(&povs, 0, sizeof(povs));
|
|
|
|
|
}
|
|
|
|
|
HAL_JoystickDescriptor desc;
|
|
|
|
|
HAL_JoystickAxes axes;
|
|
|
|
|
HAL_JoystickButtons buttons;
|
|
|
|
|
HAL_JoystickPOVs povs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SystemJoystick {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SystemJoystick() = default;
|
|
|
|
|
|
|
|
|
|
bool IsPresent() const { return m_present; }
|
|
|
|
|
bool IsAnyButtonPressed() const { return m_anyButtonPressed; }
|
|
|
|
|
bool IsGamepad() const { return m_isGamepad; }
|
|
|
|
|
|
|
|
|
|
virtual void SettingsDisplay() {}
|
|
|
|
|
virtual void Update() = 0;
|
|
|
|
|
virtual const char* GetName() const = 0;
|
|
|
|
|
virtual void GetData(HALJoystickData* data, bool mapGamepad) const = 0;
|
|
|
|
|
virtual const char* GetGUID() const = 0;
|
|
|
|
|
virtual int GetIndex() const = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool m_present = false;
|
|
|
|
|
bool m_anyButtonPressed = false;
|
|
|
|
|
bool m_isGamepad = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GlfwSystemJoystick : public SystemJoystick {
|
|
|
|
|
public:
|
|
|
|
|
explicit GlfwSystemJoystick(int i) : m_index{i} {}
|
|
|
|
|
|
|
|
|
|
void Update() override;
|
|
|
|
|
const char* GetName() const override { return m_name ? m_name : "(null)"; }
|
|
|
|
|
void GetData(HALJoystickData* data, bool mapGamepad) const override;
|
|
|
|
|
const char* GetGUID() const override { return glfwGetJoystickGUID(m_index); }
|
|
|
|
|
int GetIndex() const override { return m_index; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_index;
|
|
|
|
|
int m_axisCount = 0;
|
|
|
|
|
const float* m_axes = nullptr;
|
|
|
|
|
int m_buttonCount = 0;
|
|
|
|
|
const unsigned char* m_buttons = nullptr;
|
|
|
|
|
int m_hatCount = 0;
|
|
|
|
|
const unsigned char* m_hats = nullptr;
|
|
|
|
|
const char* m_name = nullptr;
|
|
|
|
|
GLFWgamepadstate m_gamepadState;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class KeyboardJoystick : public SystemJoystick {
|
|
|
|
|
public:
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
KeyboardJoystick(glass::Storage& storage, int index);
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
void SettingsDisplay() override;
|
|
|
|
|
void Update() override;
|
|
|
|
|
const char* GetName() const override { return m_name; }
|
|
|
|
|
void GetData(HALJoystickData* data, bool mapGamepad) const override {
|
|
|
|
|
*data = m_data;
|
|
|
|
|
}
|
|
|
|
|
const char* GetGUID() const override { return m_guid; }
|
|
|
|
|
int GetIndex() const override { return m_index + GLFW_JOYSTICK_LAST + 1; }
|
|
|
|
|
|
|
|
|
|
void ClearKey(int key);
|
|
|
|
|
virtual const char* GetKeyName(int key) const = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void EditKey(const char* label, int* key);
|
|
|
|
|
|
|
|
|
|
int m_index;
|
|
|
|
|
char m_name[20];
|
|
|
|
|
char m_guid[20];
|
|
|
|
|
|
|
|
|
|
static int* s_keyEdit;
|
|
|
|
|
|
|
|
|
|
HALJoystickData m_data;
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
int& m_axisCount;
|
|
|
|
|
int& m_buttonCount;
|
|
|
|
|
int& m_povCount;
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
struct AxisConfig {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
explicit AxisConfig(glass::Storage& storage);
|
|
|
|
|
|
|
|
|
|
int& incKey;
|
|
|
|
|
int& decKey;
|
|
|
|
|
float& keyRate;
|
|
|
|
|
float& decayRate;
|
|
|
|
|
float& maxAbsValue;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
};
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<glass::Storage>>& m_axisStorage;
|
|
|
|
|
std::vector<AxisConfig> m_axisConfig;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
static constexpr int kMaxButtonCount = 32;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
std::vector<int>& m_buttonKey;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
struct PovConfig {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
explicit PovConfig(glass::Storage& storage);
|
|
|
|
|
|
|
|
|
|
int& key0;
|
|
|
|
|
int& key45;
|
|
|
|
|
int& key90;
|
|
|
|
|
int& key135;
|
|
|
|
|
int& key180;
|
|
|
|
|
int& key225;
|
|
|
|
|
int& key270;
|
|
|
|
|
int& key315;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
};
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
std::vector<std::unique_ptr<glass::Storage>>& m_povStorage;
|
|
|
|
|
std::vector<PovConfig> m_povConfig;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class GlfwKeyboardJoystick : public KeyboardJoystick {
|
|
|
|
|
public:
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
GlfwKeyboardJoystick(glass::Storage& storage, int index);
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
2021-01-05 17:55:11 -08:00
|
|
|
const char* GetKeyName(int key) const override;
|
2019-09-23 00:24:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct RobotJoystick {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
explicit RobotJoystick(glass::Storage& storage);
|
|
|
|
|
|
|
|
|
|
glass::NameSetting name;
|
|
|
|
|
std::string& guid;
|
2019-09-23 00:24:10 -07:00
|
|
|
const SystemJoystick* sys = nullptr;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
bool& useGamepad; // = false;
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
HALJoystickData data;
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
void Clear() { data = HALJoystickData{}; }
|
2019-09-23 00:24:10 -07:00
|
|
|
void Update();
|
|
|
|
|
void SetHAL(int i);
|
2020-08-23 16:47:46 -07:00
|
|
|
void GetHAL(int i);
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
bool IsButtonPressed(int i) {
|
|
|
|
|
return (data.buttons.buttons & (1u << i)) != 0;
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
};
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
class JoystickModel {
|
2020-08-14 20:02:35 -07:00
|
|
|
public:
|
2020-09-12 10:55:46 -07:00
|
|
|
explicit JoystickModel(int index);
|
|
|
|
|
~JoystickModel() {
|
2020-08-14 20:02:35 -07:00
|
|
|
HALSIM_CancelDriverStationNewDataCallback(m_callback);
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int i = 0; i < buttonCount; ++i) {
|
|
|
|
|
delete buttons[i];
|
|
|
|
|
}
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
JoystickModel(const JoystickModel&) = delete;
|
|
|
|
|
JoystickModel& operator=(const JoystickModel&) = delete;
|
2020-08-14 20:02:35 -07:00
|
|
|
|
|
|
|
|
int axisCount;
|
|
|
|
|
int buttonCount;
|
|
|
|
|
int povCount;
|
2025-01-03 13:36:40 -08:00
|
|
|
std::unique_ptr<glass::DoubleSource> axes[HAL_kMaxJoystickAxes];
|
2020-08-14 20:02:35 -07:00
|
|
|
// use pointer instead of unique_ptr to allow it to be passed directly
|
|
|
|
|
// to DrawLEDSources()
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::BooleanSource* buttons[32];
|
|
|
|
|
std::unique_ptr<glass::IntegerSource> povs[HAL_kMaxJoystickPOVs];
|
2020-08-14 20:02:35 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static void CallbackFunc(const char*, void* param, const HAL_Value*);
|
|
|
|
|
|
|
|
|
|
int m_index;
|
|
|
|
|
int32_t m_callback;
|
|
|
|
|
};
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
class FMSSimModel : public glass::FMSModel {
|
|
|
|
|
public:
|
|
|
|
|
FMSSimModel();
|
|
|
|
|
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::BooleanSource* GetFmsAttachedData() override { return &m_fmsAttached; }
|
|
|
|
|
glass::BooleanSource* GetDsAttachedData() override { return &m_dsAttached; }
|
|
|
|
|
glass::IntegerSource* GetAllianceStationIdData() override {
|
2020-09-12 10:55:46 -07:00
|
|
|
return &m_allianceStationId;
|
|
|
|
|
}
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::DoubleSource* GetMatchTimeData() override { return &m_matchTime; }
|
|
|
|
|
glass::BooleanSource* GetEStopData() override { return &m_estop; }
|
|
|
|
|
glass::BooleanSource* GetEnabledData() override { return &m_enabled; }
|
|
|
|
|
glass::BooleanSource* GetTestData() override { return &m_test; }
|
|
|
|
|
glass::BooleanSource* GetAutonomousData() override { return &m_autonomous; }
|
|
|
|
|
glass::StringSource* GetGameSpecificMessageData() override {
|
|
|
|
|
return &m_gameMessage;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2024-01-20 21:10:02 -08:00
|
|
|
void SetFmsAttached(bool val) override { m_fmsAttached.SetValue(val); }
|
|
|
|
|
void SetDsAttached(bool val) override { m_dsAttached.SetValue(val); }
|
2020-09-12 10:55:46 -07:00
|
|
|
void SetAllianceStationId(int val) override {
|
2024-01-20 21:10:02 -08:00
|
|
|
m_allianceStationId.SetValue(val);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2024-01-20 21:10:02 -08:00
|
|
|
void SetMatchTime(double val) override { m_matchTime.SetValue(val); }
|
|
|
|
|
void SetEStop(bool val) override { m_estop.SetValue(val); }
|
|
|
|
|
void SetEnabled(bool val) override { m_enabled.SetValue(val); }
|
|
|
|
|
void SetTest(bool val) override { m_test.SetValue(val); }
|
|
|
|
|
void SetAutonomous(bool val) override { m_autonomous.SetValue(val); }
|
2022-12-09 16:10:23 -05:00
|
|
|
void SetGameSpecificMessage(std::string_view val) override {
|
2025-01-03 13:36:40 -08:00
|
|
|
m_gameMessage.SetValue(val);
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2024-01-20 21:10:02 -08:00
|
|
|
void UpdateHAL();
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
void Update() override;
|
|
|
|
|
|
|
|
|
|
bool Exists() override { return true; }
|
|
|
|
|
|
|
|
|
|
bool IsReadOnly() override;
|
|
|
|
|
|
|
|
|
|
private:
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::BooleanSource m_fmsAttached{"FMS:FMSAttached"};
|
|
|
|
|
glass::BooleanSource m_dsAttached{"FMS:DSAttached"};
|
|
|
|
|
glass::IntegerSource m_allianceStationId{"FMS:AllianceStationID"};
|
|
|
|
|
glass::DoubleSource m_matchTime{"FMS:MatchTime"};
|
|
|
|
|
glass::BooleanSource m_estop{"FMS:EStop"};
|
|
|
|
|
glass::BooleanSource m_enabled{"FMS:RobotEnabled"};
|
|
|
|
|
glass::BooleanSource m_test{"FMS:TestMode"};
|
|
|
|
|
glass::BooleanSource m_autonomous{"FMS:AutonomousMode"};
|
2022-02-12 22:31:10 -08:00
|
|
|
double m_startMatchTime = -1.0;
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::StringSource m_gameMessage{"FMS:GameSpecificMessage"};
|
2020-09-12 10:55:46 -07:00
|
|
|
};
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
// system joysticks
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
static std::vector<std::unique_ptr<SystemJoystick>> gGlfwJoysticks;
|
|
|
|
|
static int gNumGlfwJoysticks = 0;
|
2021-01-05 17:55:11 -08:00
|
|
|
static std::vector<std::unique_ptr<GlfwKeyboardJoystick>> gKeyboardJoysticks;
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
// robot joysticks
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
static std::vector<RobotJoystick> gRobotJoysticks;
|
2020-09-12 10:55:46 -07:00
|
|
|
static std::unique_ptr<JoystickModel> gJoystickSources[HAL_kMaxJoysticks];
|
|
|
|
|
|
|
|
|
|
// FMS
|
|
|
|
|
static std::unique_ptr<FMSSimModel> gFMSModel;
|
|
|
|
|
|
|
|
|
|
// Window management
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
std::unique_ptr<DSManager> DriverStationGui::dsManager;
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
static bool* gpDisableDS = nullptr;
|
|
|
|
|
static bool* gpZeroDisconnectedJoysticks = nullptr;
|
|
|
|
|
static bool* gpUseEnableDisableHotkeys = nullptr;
|
|
|
|
|
static bool* gpUseEstopHotkey = nullptr;
|
|
|
|
|
static std::atomic<bool>* gpDSSocketConnected = nullptr;
|
2020-09-02 20:51:43 -07:00
|
|
|
|
|
|
|
|
static inline bool IsDSDisabled() {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
return (gpDisableDS != nullptr && *gpDisableDS) ||
|
|
|
|
|
(gpDSSocketConnected && *gpDSSocketConnected);
|
2020-09-02 20:51:43 -07:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
JoystickModel::JoystickModel(int index) : m_index{index} {
|
2020-08-14 20:02:35 -07:00
|
|
|
HAL_JoystickAxes halAxes;
|
|
|
|
|
HALSIM_GetJoystickAxes(index, &halAxes);
|
|
|
|
|
axisCount = halAxes.count;
|
|
|
|
|
for (int i = 0; i < axisCount; ++i) {
|
2025-01-03 13:36:40 -08:00
|
|
|
axes[i] = std::make_unique<glass::DoubleSource>(
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::format("Joystick[{}] Axis[{}]", index, i));
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HAL_JoystickButtons halButtons;
|
|
|
|
|
HALSIM_GetJoystickButtons(index, &halButtons);
|
|
|
|
|
buttonCount = halButtons.count;
|
|
|
|
|
for (int i = 0; i < buttonCount; ++i) {
|
2025-01-03 13:36:40 -08:00
|
|
|
buttons[i] = new glass::BooleanSource(
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::format("Joystick[{}] Button[{}]", index, i + 1));
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int i = buttonCount; i < 32; ++i) {
|
|
|
|
|
buttons[i] = nullptr;
|
|
|
|
|
}
|
2020-08-14 20:02:35 -07:00
|
|
|
|
|
|
|
|
HAL_JoystickPOVs halPOVs;
|
|
|
|
|
HALSIM_GetJoystickPOVs(index, &halPOVs);
|
|
|
|
|
povCount = halPOVs.count;
|
|
|
|
|
for (int i = 0; i < povCount; ++i) {
|
2025-01-03 13:36:40 -08:00
|
|
|
povs[i] = std::make_unique<glass::IntegerSource>(
|
2021-06-06 16:13:58 -07:00
|
|
|
fmt::format("Joystick[{}] POV [{}]", index, i));
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_callback =
|
|
|
|
|
HALSIM_RegisterDriverStationNewDataCallback(CallbackFunc, this, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
void JoystickModel::CallbackFunc(const char*, void* param, const HAL_Value*) {
|
|
|
|
|
auto self = static_cast<JoystickModel*>(param);
|
2020-08-14 20:02:35 -07:00
|
|
|
|
|
|
|
|
HAL_JoystickAxes halAxes;
|
|
|
|
|
HALSIM_GetJoystickAxes(self->m_index, &halAxes);
|
|
|
|
|
for (int i = 0; i < halAxes.count; ++i) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto axis = self->axes[i].get()) {
|
|
|
|
|
axis->SetValue(halAxes.axes[i]);
|
|
|
|
|
}
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HAL_JoystickButtons halButtons;
|
|
|
|
|
HALSIM_GetJoystickButtons(self->m_index, &halButtons);
|
|
|
|
|
for (int i = 0; i < halButtons.count; ++i) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto button = self->buttons[i]) {
|
2020-08-14 20:02:35 -07:00
|
|
|
button->SetValue((halButtons.buttons & (1u << i)) != 0 ? 1 : 0);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HAL_JoystickPOVs halPOVs;
|
|
|
|
|
HALSIM_GetJoystickPOVs(self->m_index, &halPOVs);
|
|
|
|
|
for (int i = 0; i < halPOVs.count; ++i) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto pov = self->povs[i].get()) {
|
|
|
|
|
pov->SetValue(halPOVs.povs[i]);
|
|
|
|
|
}
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
void GlfwSystemJoystick::Update() {
|
|
|
|
|
bool wasPresent = m_present;
|
|
|
|
|
m_present = glfwJoystickPresent(m_index);
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!m_present) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
m_axes = glfwGetJoystickAxes(m_index, &m_axisCount);
|
|
|
|
|
m_buttons = glfwGetJoystickButtons(m_index, &m_buttonCount);
|
|
|
|
|
m_hats = glfwGetJoystickHats(m_index, &m_hatCount);
|
|
|
|
|
m_isGamepad = glfwGetGamepadState(m_index, &m_gamepadState);
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
m_anyButtonPressed = false;
|
|
|
|
|
for (int j = 0; j < m_buttonCount; ++j) {
|
|
|
|
|
if (m_buttons[j]) {
|
|
|
|
|
m_anyButtonPressed = true;
|
2019-09-23 00:24:10 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
for (int j = 0; j < m_hatCount; ++j) {
|
|
|
|
|
if (m_hats[j] != GLFW_HAT_CENTERED) {
|
|
|
|
|
m_anyButtonPressed = true;
|
2019-09-23 00:24:10 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!m_present || wasPresent) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
m_name = glfwGetJoystickName(m_index);
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
// try to find matching GUID
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if (const char* guid = glfwGetJoystickGUID(m_index)) {
|
2019-09-23 00:24:10 -07:00
|
|
|
for (auto&& joy : gRobotJoysticks) {
|
|
|
|
|
if (guid == joy.guid) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
joy.sys = this;
|
2019-09-23 00:24:10 -07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int HatToAngle(unsigned char hat) {
|
|
|
|
|
switch (hat) {
|
|
|
|
|
case GLFW_HAT_UP:
|
|
|
|
|
return 0;
|
|
|
|
|
case GLFW_HAT_RIGHT:
|
|
|
|
|
return 90;
|
|
|
|
|
case GLFW_HAT_DOWN:
|
|
|
|
|
return 180;
|
|
|
|
|
case GLFW_HAT_LEFT:
|
|
|
|
|
return 270;
|
|
|
|
|
case GLFW_HAT_RIGHT_UP:
|
|
|
|
|
return 45;
|
|
|
|
|
case GLFW_HAT_RIGHT_DOWN:
|
|
|
|
|
return 135;
|
|
|
|
|
case GLFW_HAT_LEFT_UP:
|
|
|
|
|
return 315;
|
|
|
|
|
case GLFW_HAT_LEFT_DOWN:
|
|
|
|
|
return 225;
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
void GlfwSystemJoystick::GetData(HALJoystickData* data, bool mapGamepad) const {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!m_present) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
// use gamepad mappings if present and enabled
|
|
|
|
|
const float* sysAxes;
|
|
|
|
|
const unsigned char* sysButtons;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if (m_isGamepad && mapGamepad) {
|
|
|
|
|
sysAxes = m_gamepadState.axes;
|
2019-10-11 23:27:04 -07:00
|
|
|
// don't remap on windows
|
|
|
|
|
#ifdef _WIN32
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
sysButtons = m_buttons;
|
2019-10-11 23:27:04 -07:00
|
|
|
#else
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
sysButtons = m_gamepadState.buttons;
|
2019-10-11 23:27:04 -07:00
|
|
|
#endif
|
2019-09-23 00:24:10 -07:00
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
sysAxes = m_axes;
|
|
|
|
|
sysButtons = m_buttons;
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy into HAL structures
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->desc.isXbox = m_isGamepad ? 1 : 0;
|
|
|
|
|
data->desc.type = m_isGamepad ? 21 : 20;
|
2020-12-17 21:51:57 -08:00
|
|
|
std::strncpy(data->desc.name, m_name, sizeof(data->desc.name) - 1);
|
|
|
|
|
data->desc.name[sizeof(data->desc.name) - 1] = '\0';
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->desc.axisCount = (std::min)(m_axisCount, HAL_kMaxJoystickAxes);
|
2019-09-23 00:24:10 -07:00
|
|
|
// desc.axisTypes ???
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->desc.buttonCount = (std::min)(m_buttonCount, 32);
|
|
|
|
|
data->desc.povCount = (std::min)(m_hatCount, HAL_kMaxJoystickPOVs);
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->buttons.count = data->desc.buttonCount;
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int j = 0; j < data->buttons.count; ++j) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->buttons.buttons |= (sysButtons[j] ? 1u : 0u) << j;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->axes.count = data->desc.axisCount;
|
|
|
|
|
if (m_isGamepad && mapGamepad) {
|
2019-10-11 23:27:04 -07:00
|
|
|
// the FRC DriverStation maps gamepad (XInput) trigger values to 0-1 range
|
|
|
|
|
// on axis 2 and 3.
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->axes.axes[0] = sysAxes[0];
|
|
|
|
|
data->axes.axes[1] = sysAxes[1];
|
|
|
|
|
data->axes.axes[2] = 0.5 + sysAxes[4] / 2.0;
|
|
|
|
|
data->axes.axes[3] = 0.5 + sysAxes[5] / 2.0;
|
|
|
|
|
data->axes.axes[4] = sysAxes[2];
|
|
|
|
|
data->axes.axes[5] = sysAxes[3];
|
2019-10-11 23:27:04 -07:00
|
|
|
|
|
|
|
|
// the start button for gamepads is not mapped on the FRC DriverStation
|
|
|
|
|
// platforms, so remove it if present
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if (data->buttons.count == 11) {
|
|
|
|
|
--data->desc.buttonCount;
|
|
|
|
|
--data->buttons.count;
|
|
|
|
|
data->buttons.buttons = (data->buttons.buttons & 0xff) |
|
|
|
|
|
((data->buttons.buttons >> 1) & 0x300);
|
2019-10-11 23:27:04 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
std::memcpy(data->axes.axes, sysAxes,
|
2023-01-31 23:40:22 -08:00
|
|
|
data->axes.count * sizeof(data->axes.axes[0]));
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data->povs.count = data->desc.povCount;
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int j = 0; j < data->povs.count; ++j) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
data->povs.povs[j] = HatToAngle(m_hats[j]);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
KeyboardJoystick::AxisConfig::AxisConfig(glass::Storage& storage)
|
|
|
|
|
: incKey{storage.GetInt("incKey", -1)},
|
|
|
|
|
decKey{storage.GetInt("decKey", -1)},
|
|
|
|
|
keyRate{storage.GetFloat("keyRate", 0.05f)},
|
|
|
|
|
decayRate{storage.GetFloat("decayRate", 0.05f)},
|
|
|
|
|
maxAbsValue{storage.GetFloat("maxAbsValue", 1.0f)} {
|
|
|
|
|
// sanity check the key ranges
|
|
|
|
|
if (incKey < -1 || incKey >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
incKey = -1;
|
|
|
|
|
}
|
|
|
|
|
if (decKey < -1 || decKey >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
decKey = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KeyboardJoystick::PovConfig::PovConfig(glass::Storage& storage)
|
|
|
|
|
: key0{storage.GetInt("key0", -1)},
|
|
|
|
|
key45{storage.GetInt("key45", -1)},
|
|
|
|
|
key90{storage.GetInt("key90", -1)},
|
|
|
|
|
key135{storage.GetInt("key135", -1)},
|
|
|
|
|
key180{storage.GetInt("key180", -1)},
|
|
|
|
|
key225{storage.GetInt("key225", -1)},
|
|
|
|
|
key270{storage.GetInt("key270", -1)},
|
|
|
|
|
key315{storage.GetInt("key315", -1)} {
|
|
|
|
|
// sanity check the key ranges
|
|
|
|
|
if (key0 < -1 || key0 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key0 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key45 < -1 || key45 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key45 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key90 < -1 || key90 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key90 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key135 < -1 || key135 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key135 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key180 < -1 || key180 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key180 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key225 < -1 || key225 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key225 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key270 < -1 || key270 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key270 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (key315 < -1 || key315 >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key315 = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KeyboardJoystick::KeyboardJoystick(glass::Storage& storage, int index)
|
|
|
|
|
: m_index{index},
|
|
|
|
|
m_axisCount{storage.GetInt("axisCount", -1)},
|
|
|
|
|
m_buttonCount{storage.GetInt("buttonCount", -1)},
|
|
|
|
|
m_povCount{storage.GetInt("povCount", -1)},
|
|
|
|
|
m_axisStorage{storage.GetChildArray("axisConfig")},
|
|
|
|
|
m_buttonKey{storage.GetIntArray("buttonKeys")},
|
|
|
|
|
m_povStorage{storage.GetChildArray("povConfig")} {
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(m_name, sizeof(m_name), "Keyboard {}", index);
|
|
|
|
|
wpi::format_to_n_c_str(m_guid, sizeof(m_guid), "Keyboard{}", index);
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
// init axes
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
for (auto&& axisConfig : m_axisStorage) {
|
|
|
|
|
m_axisConfig.emplace_back(*axisConfig);
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
// sanity check the button key ranges
|
|
|
|
|
for (auto&& key : m_buttonKey) {
|
|
|
|
|
if (key < -1 || key >= IM_ARRAYSIZE(ImGuiIO::KeysDown)) {
|
|
|
|
|
key = -1;
|
|
|
|
|
}
|
2019-10-11 23:27:04 -07:00
|
|
|
}
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
// init POVs
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
for (auto&& povConfig : m_povStorage) {
|
|
|
|
|
m_povConfig.emplace_back(*povConfig);
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
// init desc structure
|
|
|
|
|
m_data.desc.isXbox = 0;
|
|
|
|
|
m_data.desc.type = 20;
|
|
|
|
|
std::strncpy(m_data.desc.name, m_name, 256);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int* KeyboardJoystick::s_keyEdit = nullptr;
|
|
|
|
|
|
|
|
|
|
void KeyboardJoystick::EditKey(const char* label, int* key) {
|
|
|
|
|
ImGui::PushID(label);
|
|
|
|
|
ImGui::Text("%s", label);
|
|
|
|
|
ImGui::SameLine();
|
2023-09-17 20:00:16 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
char editLabel[32];
|
2023-09-17 20:00:16 -07:00
|
|
|
if (s_keyEdit == key) {
|
|
|
|
|
wpi::format_to_n_c_str(editLabel, sizeof(editLabel), "(press key)###edit");
|
|
|
|
|
} else {
|
|
|
|
|
wpi::format_to_n_c_str(editLabel, sizeof(editLabel), "{}###edit",
|
|
|
|
|
GetKeyName(*key));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ImGui::SmallButton(editLabel)) {
|
|
|
|
|
s_keyEdit = key;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::SameLine();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (ImGui::SmallButton("Clear")) {
|
|
|
|
|
*key = -1;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeyboardJoystick::SettingsDisplay() {
|
|
|
|
|
if (s_keyEdit) {
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2023-12-02 21:20:43 -08:00
|
|
|
// NOLINTNEXTLINE(bugprone-sizeof-expression)
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); ++i) {
|
|
|
|
|
if (io.KeysDown[i]) {
|
|
|
|
|
// remove all other uses
|
2020-12-28 12:58:06 -08:00
|
|
|
for (auto&& joy : gKeyboardJoysticks) {
|
|
|
|
|
joy->ClearKey(i);
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
*s_keyEdit = i;
|
|
|
|
|
s_keyEdit = nullptr;
|
2020-12-30 11:37:54 -08:00
|
|
|
break;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char label[64];
|
|
|
|
|
ImGui::PushItemWidth(ImGui::GetFontSize() * 6);
|
|
|
|
|
// axes
|
|
|
|
|
if (ImGui::CollapsingHeader("Axes", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
ImGui::PushID("Axes");
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (ImGui::InputInt("Count", &m_axisCount)) {
|
|
|
|
|
if (m_axisCount < 0) {
|
|
|
|
|
m_axisCount = 0;
|
|
|
|
|
} else if (m_axisCount > HAL_kMaxJoystickAxes) {
|
|
|
|
|
m_axisCount = HAL_kMaxJoystickAxes;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
while (m_axisCount > static_cast<int>(m_axisConfig.size())) {
|
|
|
|
|
m_axisStorage.emplace_back(std::make_unique<glass::Storage>());
|
|
|
|
|
m_axisConfig.emplace_back(*m_axisStorage.back());
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < m_axisCount; ++i) {
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "Axis {}", i);
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if (ImGui::TreeNodeEx(label, ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
EditKey("Increase", &m_axisConfig[i].incKey);
|
|
|
|
|
EditKey("Decrease", &m_axisConfig[i].decKey);
|
|
|
|
|
ImGui::InputFloat("Key Rate", &m_axisConfig[i].keyRate);
|
|
|
|
|
ImGui::InputFloat("Decay Rate", &m_axisConfig[i].decayRate);
|
2021-01-12 22:57:04 -05:00
|
|
|
|
|
|
|
|
float maxAbsValue = m_axisConfig[i].maxAbsValue;
|
|
|
|
|
if (ImGui::InputFloat("Max Absolute Value", &maxAbsValue)) {
|
|
|
|
|
m_axisConfig[i].maxAbsValue = std::clamp(maxAbsValue, -1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
|
if (ImGui::CollapsingHeader("Buttons", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
ImGui::PushID("Buttons");
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (ImGui::InputInt("Count", &m_buttonCount)) {
|
|
|
|
|
if (m_buttonCount < 0) {
|
|
|
|
|
m_buttonCount = 0;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (m_buttonCount > kMaxButtonCount) {
|
|
|
|
|
m_buttonCount = kMaxButtonCount;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
while (m_buttonCount > static_cast<int>(m_buttonKey.size())) {
|
|
|
|
|
m_buttonKey.emplace_back(-1);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < m_buttonCount; ++i) {
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "Button {}", i + 1);
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
EditKey(label, &m_buttonKey[i]);
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// povs
|
|
|
|
|
if (ImGui::CollapsingHeader("POVs", ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
ImGui::PushID("POVs");
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (ImGui::InputInt("Count", &m_povCount)) {
|
|
|
|
|
if (m_povCount < 0) {
|
|
|
|
|
m_povCount = 0;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (m_povCount > HAL_kMaxJoystickPOVs) {
|
|
|
|
|
m_povCount = HAL_kMaxJoystickPOVs;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
while (m_povCount > static_cast<int>(m_povConfig.size())) {
|
|
|
|
|
m_povStorage.emplace_back(std::make_unique<glass::Storage>());
|
|
|
|
|
m_povConfig.emplace_back(*m_povStorage.back());
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < m_povCount; ++i) {
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "POV {}", i);
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if (ImGui::TreeNodeEx(label, ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
EditKey(" 0 deg", &m_povConfig[i].key0);
|
|
|
|
|
EditKey(" 45 deg", &m_povConfig[i].key45);
|
|
|
|
|
EditKey(" 90 deg", &m_povConfig[i].key90);
|
|
|
|
|
EditKey("135 deg", &m_povConfig[i].key135);
|
|
|
|
|
EditKey("180 deg", &m_povConfig[i].key180);
|
|
|
|
|
EditKey("225 deg", &m_povConfig[i].key225);
|
|
|
|
|
EditKey("270 deg", &m_povConfig[i].key270);
|
|
|
|
|
EditKey("315 deg", &m_povConfig[i].key315);
|
|
|
|
|
ImGui::TreePop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-12 22:12:20 -08:00
|
|
|
static inline bool IsKeyDown(ImGuiIO& io, int key) {
|
|
|
|
|
return key >= 0 && key < IM_ARRAYSIZE(ImGuiIO::KeysDown) && io.KeysDown[key];
|
|
|
|
|
}
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
void KeyboardJoystick::Update() {
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (m_axisCount < 0) {
|
|
|
|
|
m_axisCount = 0;
|
|
|
|
|
}
|
|
|
|
|
if (m_buttonCount < 0) {
|
|
|
|
|
m_buttonCount = 0;
|
|
|
|
|
}
|
|
|
|
|
if (m_povCount < 0) {
|
|
|
|
|
m_povCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_data.axes.count =
|
|
|
|
|
(std::min)(m_axisCount, static_cast<int>(m_axisConfig.size()));
|
|
|
|
|
m_data.buttons.count =
|
|
|
|
|
(std::min)(m_buttonCount, static_cast<int>(m_buttonKey.size()));
|
|
|
|
|
m_data.povs.count =
|
|
|
|
|
(std::min)(m_povCount, static_cast<int>(m_povConfig.size()));
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if (m_data.axes.count > 0 || m_data.buttons.count > 0 ||
|
2020-12-28 12:58:06 -08:00
|
|
|
m_data.povs.count > 0) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
m_present = true;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
// axes
|
|
|
|
|
for (int i = 0; i < m_data.axes.count; ++i) {
|
|
|
|
|
auto& config = m_axisConfig[i];
|
|
|
|
|
float& axisValue = m_data.axes.axes[i];
|
|
|
|
|
// increase/decrease while key held down (to saturation); decay back to 0
|
2021-02-12 22:12:20 -08:00
|
|
|
if (IsKeyDown(io, config.incKey)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
axisValue += config.keyRate;
|
2021-01-12 22:57:04 -05:00
|
|
|
if (axisValue > config.maxAbsValue) {
|
|
|
|
|
axisValue = config.maxAbsValue;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
} else if (axisValue > 0) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (axisValue < config.decayRate) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
axisValue = 0;
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
axisValue -= config.decayRate;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
2021-02-12 22:12:20 -08:00
|
|
|
if (IsKeyDown(io, config.decKey)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
axisValue -= config.keyRate;
|
2021-01-12 22:57:04 -05:00
|
|
|
if (axisValue < -config.maxAbsValue) {
|
|
|
|
|
axisValue = -config.maxAbsValue;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
} else if (axisValue < 0) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (axisValue > -config.decayRate) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
axisValue = 0;
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
axisValue += config.decayRate;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
|
m_data.buttons.buttons = 0;
|
|
|
|
|
m_anyButtonPressed = false;
|
|
|
|
|
for (int i = 0; i < m_data.buttons.count; ++i) {
|
2021-02-12 22:12:20 -08:00
|
|
|
if (IsKeyDown(io, m_buttonKey[i])) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
m_data.buttons.buttons |= 1u << i;
|
|
|
|
|
m_anyButtonPressed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// povs
|
|
|
|
|
for (int i = 0; i < m_data.povs.count; ++i) {
|
|
|
|
|
auto& config = m_povConfig[i];
|
|
|
|
|
auto& povValue = m_data.povs.povs[i];
|
|
|
|
|
povValue = -1;
|
2021-02-12 22:12:20 -08:00
|
|
|
if (IsKeyDown(io, config.key0)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 0;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key45)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 45;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key90)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 90;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key135)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 135;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key180)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 180;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key225)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 225;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key270)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 270;
|
2021-02-12 22:12:20 -08:00
|
|
|
} else if (IsKeyDown(io, config.key315)) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
povValue = 315;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// try to find matching GUID
|
|
|
|
|
for (auto&& joy : gRobotJoysticks) {
|
|
|
|
|
if (m_guid == joy.guid) {
|
|
|
|
|
joy.sys = this;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update desc
|
|
|
|
|
m_data.desc.axisCount = m_data.axes.count;
|
|
|
|
|
m_data.desc.buttonCount = m_data.buttons.count;
|
|
|
|
|
m_data.desc.povCount = m_data.povs.count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KeyboardJoystick::ClearKey(int key) {
|
|
|
|
|
for (auto&& config : m_axisConfig) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (config.incKey == key) {
|
|
|
|
|
config.incKey = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.decKey == key) {
|
|
|
|
|
config.decKey = -1;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
for (auto&& buttonKey : m_buttonKey) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (buttonKey == key) {
|
|
|
|
|
buttonKey = -1;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
for (auto&& config : m_povConfig) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (config.key0 == key) {
|
|
|
|
|
config.key0 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key45 == key) {
|
|
|
|
|
config.key45 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key90 == key) {
|
|
|
|
|
config.key90 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key135 == key) {
|
|
|
|
|
config.key135 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key180 == key) {
|
|
|
|
|
config.key180 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key225 == key) {
|
|
|
|
|
config.key225 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key270 == key) {
|
|
|
|
|
config.key270 = -1;
|
|
|
|
|
}
|
|
|
|
|
if (config.key315 == key) {
|
|
|
|
|
config.key315 = -1;
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
GlfwKeyboardJoystick::GlfwKeyboardJoystick(glass::Storage& storage, int index)
|
|
|
|
|
: KeyboardJoystick{storage, index} {
|
|
|
|
|
// set up a default keyboard config for 0, 1, and 2
|
|
|
|
|
if (index == 0) {
|
|
|
|
|
if (m_axisCount == -1 && m_axisStorage.empty()) {
|
|
|
|
|
m_axisCount = 3;
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
|
m_axisStorage.emplace_back(std::make_unique<glass::Storage>());
|
|
|
|
|
m_axisConfig.emplace_back(*m_axisStorage.back());
|
2021-06-06 16:13:58 -07:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
m_axisConfig[0].incKey = GLFW_KEY_D;
|
|
|
|
|
m_axisConfig[0].decKey = GLFW_KEY_A;
|
|
|
|
|
m_axisConfig[1].incKey = GLFW_KEY_S;
|
|
|
|
|
m_axisConfig[1].decKey = GLFW_KEY_W;
|
|
|
|
|
m_axisConfig[2].incKey = GLFW_KEY_R;
|
|
|
|
|
m_axisConfig[2].decKey = GLFW_KEY_E;
|
|
|
|
|
m_axisConfig[2].keyRate = 0.01f;
|
|
|
|
|
m_axisConfig[2].decayRate = 0; // works like a throttle
|
|
|
|
|
}
|
|
|
|
|
if (m_buttonCount == -1 && m_buttonKey.empty()) {
|
|
|
|
|
m_buttonCount = 4;
|
|
|
|
|
m_buttonKey.resize(4);
|
|
|
|
|
m_buttonKey[0] = GLFW_KEY_Z;
|
|
|
|
|
m_buttonKey[1] = GLFW_KEY_X;
|
|
|
|
|
m_buttonKey[2] = GLFW_KEY_C;
|
|
|
|
|
m_buttonKey[3] = GLFW_KEY_V;
|
|
|
|
|
}
|
|
|
|
|
if (m_povCount == -1 && m_povStorage.empty()) {
|
|
|
|
|
m_povCount = 1;
|
|
|
|
|
m_povStorage.emplace_back(std::make_unique<glass::Storage>());
|
|
|
|
|
m_povConfig.emplace_back(*m_povStorage.back());
|
|
|
|
|
m_povConfig[0].key0 = GLFW_KEY_KP_8;
|
|
|
|
|
m_povConfig[0].key45 = GLFW_KEY_KP_9;
|
|
|
|
|
m_povConfig[0].key90 = GLFW_KEY_KP_6;
|
|
|
|
|
m_povConfig[0].key135 = GLFW_KEY_KP_3;
|
|
|
|
|
m_povConfig[0].key180 = GLFW_KEY_KP_2;
|
|
|
|
|
m_povConfig[0].key225 = GLFW_KEY_KP_1;
|
|
|
|
|
m_povConfig[0].key270 = GLFW_KEY_KP_4;
|
|
|
|
|
m_povConfig[0].key315 = GLFW_KEY_KP_7;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
} else if (index == 1) {
|
|
|
|
|
if (m_axisCount == -1 && m_axisStorage.empty()) {
|
|
|
|
|
m_axisCount = 2;
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
m_axisStorage.emplace_back(std::make_unique<glass::Storage>());
|
|
|
|
|
m_axisConfig.emplace_back(*m_axisStorage.back());
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
m_axisConfig[0].incKey = GLFW_KEY_L;
|
|
|
|
|
m_axisConfig[0].decKey = GLFW_KEY_J;
|
|
|
|
|
m_axisConfig[1].incKey = GLFW_KEY_K;
|
|
|
|
|
m_axisConfig[1].decKey = GLFW_KEY_I;
|
|
|
|
|
}
|
|
|
|
|
if (m_buttonCount == -1 && m_buttonKey.empty()) {
|
|
|
|
|
m_buttonCount = 4;
|
|
|
|
|
m_buttonKey.resize(4);
|
|
|
|
|
m_buttonKey[0] = GLFW_KEY_M;
|
|
|
|
|
m_buttonKey[1] = GLFW_KEY_COMMA;
|
|
|
|
|
m_buttonKey[2] = GLFW_KEY_PERIOD;
|
|
|
|
|
m_buttonKey[3] = GLFW_KEY_SLASH;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
} else if (index == 2) {
|
|
|
|
|
if (m_axisCount == -1 && m_axisStorage.empty()) {
|
|
|
|
|
m_axisCount = 2;
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
m_axisStorage.emplace_back(std::make_unique<glass::Storage>());
|
|
|
|
|
m_axisConfig.emplace_back(*m_axisStorage.back());
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
m_axisConfig[0].incKey = GLFW_KEY_RIGHT;
|
|
|
|
|
m_axisConfig[0].decKey = GLFW_KEY_LEFT;
|
|
|
|
|
m_axisConfig[1].incKey = GLFW_KEY_DOWN;
|
|
|
|
|
m_axisConfig[1].decKey = GLFW_KEY_UP;
|
|
|
|
|
}
|
|
|
|
|
if (m_buttonCount == -1 && m_buttonKey.empty()) {
|
|
|
|
|
m_buttonCount = 6;
|
|
|
|
|
m_buttonKey.resize(6);
|
|
|
|
|
m_buttonKey[0] = GLFW_KEY_INSERT;
|
|
|
|
|
m_buttonKey[1] = GLFW_KEY_HOME;
|
|
|
|
|
m_buttonKey[2] = GLFW_KEY_PAGE_UP;
|
|
|
|
|
m_buttonKey[3] = GLFW_KEY_DELETE;
|
|
|
|
|
m_buttonKey[4] = GLFW_KEY_END;
|
|
|
|
|
m_buttonKey[5] = GLFW_KEY_PAGE_DOWN;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 17:55:11 -08:00
|
|
|
const char* GlfwKeyboardJoystick::GetKeyName(int key) const {
|
|
|
|
|
if (key < 0) {
|
|
|
|
|
return "(None)";
|
|
|
|
|
}
|
|
|
|
|
const char* name = glfwGetKeyName(key, 0);
|
|
|
|
|
if (name) {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
// glfwGetKeyName sometimes doesn't have these keys
|
|
|
|
|
switch (key) {
|
|
|
|
|
case GLFW_KEY_RIGHT:
|
|
|
|
|
return "Right";
|
|
|
|
|
case GLFW_KEY_LEFT:
|
|
|
|
|
return "Left";
|
|
|
|
|
case GLFW_KEY_DOWN:
|
|
|
|
|
return "Down";
|
|
|
|
|
case GLFW_KEY_UP:
|
|
|
|
|
return "Up";
|
|
|
|
|
case GLFW_KEY_INSERT:
|
|
|
|
|
return "Insert";
|
|
|
|
|
case GLFW_KEY_HOME:
|
|
|
|
|
return "Home";
|
|
|
|
|
case GLFW_KEY_PAGE_UP:
|
|
|
|
|
return "PgUp";
|
|
|
|
|
case GLFW_KEY_DELETE:
|
|
|
|
|
return "Delete";
|
|
|
|
|
case GLFW_KEY_END:
|
|
|
|
|
return "End";
|
|
|
|
|
case GLFW_KEY_PAGE_DOWN:
|
|
|
|
|
return "PgDn";
|
|
|
|
|
}
|
|
|
|
|
return "(Unknown)";
|
|
|
|
|
}
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
RobotJoystick::RobotJoystick(glass::Storage& storage)
|
|
|
|
|
: name{storage.GetString("name")},
|
|
|
|
|
guid{storage.GetString("guid")},
|
|
|
|
|
useGamepad{storage.GetBool("useGamepad")} {}
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
void RobotJoystick::Update() {
|
|
|
|
|
Clear();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (sys) {
|
|
|
|
|
sys->GetData(&data, useGamepad);
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RobotJoystick::SetHAL(int i) {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if ((gpZeroDisconnectedJoysticks != nullptr &&
|
|
|
|
|
!gpZeroDisconnectedJoysticks) &&
|
|
|
|
|
(!sys || !sys->IsPresent())) {
|
2020-12-28 12:58:06 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
// set at HAL level
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
HALSIM_SetJoystickDescriptor(i, &data.desc);
|
|
|
|
|
HALSIM_SetJoystickAxes(i, &data.axes);
|
|
|
|
|
HALSIM_SetJoystickButtons(i, &data.buttons);
|
|
|
|
|
HALSIM_SetJoystickPOVs(i, &data.povs);
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-23 16:47:46 -07:00
|
|
|
void RobotJoystick::GetHAL(int i) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
HALSIM_GetJoystickDescriptor(i, &data.desc);
|
|
|
|
|
HALSIM_GetJoystickAxes(i, &data.axes);
|
|
|
|
|
HALSIM_GetJoystickButtons(i, &data.buttons);
|
|
|
|
|
HALSIM_GetJoystickPOVs(i, &data.povs);
|
2020-08-23 16:47:46 -07:00
|
|
|
}
|
|
|
|
|
|
2024-01-20 21:10:02 -08:00
|
|
|
static void DriverStationConnect(bool enabled, bool autonomous, bool test) {
|
|
|
|
|
if (!HALSIM_GetDriverStationDsAttached()) {
|
|
|
|
|
// initialize FMS bits too
|
|
|
|
|
gFMSModel->SetDsAttached(true);
|
|
|
|
|
gFMSModel->SetEnabled(enabled);
|
|
|
|
|
gFMSModel->SetAutonomous(autonomous);
|
|
|
|
|
gFMSModel->SetTest(test);
|
|
|
|
|
gFMSModel->UpdateHAL();
|
|
|
|
|
} else {
|
|
|
|
|
HALSIM_SetDriverStationEnabled(enabled);
|
|
|
|
|
HALSIM_SetDriverStationAutonomous(autonomous);
|
|
|
|
|
HALSIM_SetDriverStationTest(test);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
static void DriverStationExecute() {
|
2020-08-14 20:02:35 -07:00
|
|
|
// update sources
|
|
|
|
|
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
|
|
|
|
|
auto& source = gJoystickSources[i];
|
|
|
|
|
int32_t axisCount, buttonCount, povCount;
|
|
|
|
|
HALSIM_GetJoystickCounts(i, &axisCount, &buttonCount, &povCount);
|
|
|
|
|
if (axisCount != 0 || buttonCount != 0 || povCount != 0) {
|
|
|
|
|
if (!source || source->axisCount != axisCount ||
|
|
|
|
|
source->buttonCount != buttonCount || source->povCount != povCount) {
|
|
|
|
|
source.reset();
|
2020-09-12 10:55:46 -07:00
|
|
|
source = std::make_unique<JoystickModel>(i);
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
source.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
static bool prevDisableDS = false;
|
2020-09-02 20:51:43 -07:00
|
|
|
|
|
|
|
|
bool disableDS = IsDSDisabled();
|
|
|
|
|
if (disableDS && !prevDisableDS) {
|
2024-11-27 23:03:55 -08:00
|
|
|
if (auto win = DriverStationGui::dsManager->GetWindow("System Joysticks")) {
|
2020-09-12 10:55:46 -07:00
|
|
|
win->SetVisibility(glass::Window::kDisabled);
|
|
|
|
|
}
|
2020-09-02 20:51:43 -07:00
|
|
|
} else if (!disableDS && prevDisableDS) {
|
2024-11-27 23:03:55 -08:00
|
|
|
if (auto win = DriverStationGui::dsManager->GetWindow("System Joysticks")) {
|
2020-09-12 10:55:46 -07:00
|
|
|
win->SetVisibility(glass::Window::kShow);
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
2020-09-02 20:51:43 -07:00
|
|
|
prevDisableDS = disableDS;
|
2020-12-28 12:58:06 -08:00
|
|
|
if (disableDS) {
|
2024-11-30 09:49:09 -08:00
|
|
|
gFMSModel->Update();
|
2020-12-28 12:58:06 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
double curTime = glfwGetTime();
|
|
|
|
|
|
|
|
|
|
// update system joysticks
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
gNumGlfwJoysticks = 0;
|
2019-09-23 00:24:10 -07:00
|
|
|
for (int i = 0; i <= GLFW_JOYSTICK_LAST; ++i) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
gGlfwJoysticks[i]->Update();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (gGlfwJoysticks[i]->IsPresent()) {
|
|
|
|
|
gNumGlfwJoysticks = i + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (auto&& joy : gKeyboardJoysticks) {
|
|
|
|
|
joy->Update();
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update robot joysticks
|
2020-12-28 12:58:06 -08:00
|
|
|
for (auto&& joy : gRobotJoysticks) {
|
|
|
|
|
joy.Update();
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2024-01-20 21:10:02 -08:00
|
|
|
bool isAttached = HALSIM_GetDriverStationDsAttached();
|
2019-09-23 00:24:10 -07:00
|
|
|
bool isEnabled = HALSIM_GetDriverStationEnabled();
|
|
|
|
|
bool isAuto = HALSIM_GetDriverStationAutonomous();
|
|
|
|
|
bool isTest = HALSIM_GetDriverStationTest();
|
|
|
|
|
|
|
|
|
|
// Robot state
|
|
|
|
|
{
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
// DS hotkeys
|
|
|
|
|
bool enableHotkey = false;
|
|
|
|
|
bool disableHotkey = false;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (gpUseEnableDisableHotkeys != nullptr && *gpUseEnableDisableHotkeys) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (io.KeysDown[GLFW_KEY_ENTER] || io.KeysDown[GLFW_KEY_KP_ENTER]) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
disableHotkey = true;
|
2020-12-28 12:58:06 -08:00
|
|
|
} else if (io.KeysDown[GLFW_KEY_LEFT_BRACKET] &&
|
|
|
|
|
io.KeysDown[GLFW_KEY_RIGHT_BRACKET] &&
|
|
|
|
|
io.KeysDown[GLFW_KEY_BACKSLASH]) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
enableHotkey = true;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (gpUseEstopHotkey != nullptr && *gpUseEstopHotkey) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
if (io.KeysDown[GLFW_KEY_SPACE]) {
|
|
|
|
|
HALSIM_SetDriverStationEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::SetNextWindowPos(ImVec2{5, 20}, ImGuiCond_FirstUseEver);
|
2025-01-01 17:20:35 -06:00
|
|
|
const char* title = "Robot State";
|
|
|
|
|
// Accounts for size of title and collapse button
|
|
|
|
|
float minWidth = ImGui::CalcTextSize(title).x + ImGui::GetFontSize() +
|
|
|
|
|
ImGui::GetStyle().ItemInnerSpacing.x * 2 +
|
|
|
|
|
ImGui::GetStyle().FramePadding.x * 2 +
|
|
|
|
|
ImGui::GetStyle().WindowBorderSize;
|
|
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2{minWidth, 0},
|
|
|
|
|
ImVec2{FLT_MAX, FLT_MAX});
|
|
|
|
|
ImGui::Begin(title, nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
2024-01-20 21:10:02 -08:00
|
|
|
if (ImGui::Selectable("Disconnected", !isAttached)) {
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSIM_SetDriverStationEnabled(false);
|
2024-01-20 21:10:02 -08:00
|
|
|
HALSIM_SetDriverStationDsAttached(false);
|
|
|
|
|
isAttached = false;
|
|
|
|
|
gFMSModel->Update();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::Selectable("Disabled", isAttached && !isEnabled) ||
|
|
|
|
|
disableHotkey) {
|
|
|
|
|
DriverStationConnect(false, false, false);
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
2024-01-20 21:10:02 -08:00
|
|
|
if (ImGui::Selectable("Autonomous",
|
|
|
|
|
isAttached && isEnabled && isAuto && !isTest)) {
|
|
|
|
|
DriverStationConnect(true, true, false);
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
2024-01-20 21:10:02 -08:00
|
|
|
if (ImGui::Selectable("Teleoperated",
|
|
|
|
|
isAttached && isEnabled && !isAuto && !isTest) ||
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
enableHotkey) {
|
2024-01-20 21:10:02 -08:00
|
|
|
DriverStationConnect(true, false, false);
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
if (ImGui::Selectable("Test", isEnabled && isTest)) {
|
2024-01-20 21:10:02 -08:00
|
|
|
DriverStationConnect(true, false, true);
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update HAL
|
2024-06-21 22:56:23 -05:00
|
|
|
if (isAttached && !isAuto) {
|
2024-01-20 21:10:02 -08:00
|
|
|
for (int i = 0, end = gRobotJoysticks.size();
|
|
|
|
|
i < end && i < HAL_kMaxJoysticks; ++i) {
|
|
|
|
|
gRobotJoysticks[i].SetHAL(i);
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
// Send new data every 20 ms (may be slower depending on GUI refresh rate)
|
|
|
|
|
static double lastNewDataTime = 0.0;
|
2024-01-20 21:10:02 -08:00
|
|
|
if ((curTime - lastNewDataTime) > 0.02 && !HALSIM_IsTimingPaused() &&
|
|
|
|
|
isAttached) {
|
2019-09-23 00:24:10 -07:00
|
|
|
lastNewDataTime = curTime;
|
2024-01-20 21:10:02 -08:00
|
|
|
gFMSModel->Update();
|
2019-09-23 00:24:10 -07:00
|
|
|
HALSIM_NotifyDriverStationNewData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
FMSSimModel::FMSSimModel() {
|
2022-02-12 22:31:10 -08:00
|
|
|
m_matchTime.SetValue(-1.0);
|
2024-01-20 21:10:02 -08:00
|
|
|
m_allianceStationId.SetValue(HAL_AllianceStationID_kRed1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FMSSimModel::UpdateHAL() {
|
|
|
|
|
HALSIM_SetDriverStationFmsAttached(m_fmsAttached.GetValue());
|
|
|
|
|
HALSIM_SetDriverStationAllianceStationId(
|
|
|
|
|
static_cast<HAL_AllianceStationID>(m_allianceStationId.GetValue()));
|
|
|
|
|
HALSIM_SetDriverStationEStop(m_estop.GetValue());
|
|
|
|
|
HALSIM_SetDriverStationEnabled(m_enabled.GetValue());
|
|
|
|
|
HALSIM_SetDriverStationTest(m_test.GetValue());
|
|
|
|
|
HALSIM_SetDriverStationAutonomous(m_autonomous.GetValue());
|
|
|
|
|
HALSIM_SetDriverStationMatchTime(m_matchTime.GetValue());
|
2025-01-03 13:36:40 -08:00
|
|
|
auto str = wpi::make_string(m_gameMessage.GetValue());
|
Change C APIs to a unified string implementation (#6299)
Currently in the entire C API of WPILib we have ~8 different ways of handling strings. The C API actually isn't built for pure C callers (We don't actually have any of those). Instead, they're built for interop between languages like LabVIEW and C# which can talk to C API's directly.
For output parameters, the choice was fairly obvious. An output struct containing a const string pointer and a length makes the most sense. Its easy to use these from most other languages, and doesn't require special null termination handling. Freeing these is also easy, as if you ever receive one of these string structures, theres just a single function call to free it.
Input parameters are a bit more complex. To be used from pure C, and from LabVIEW, a null terminated string is the best in most cases. However, null terminated strings in general have a lot of downsides. Additionally, from LabVIEW there are other considerations around encoding that having a wrapper struct helps make a bit easier. From a language like C#, a wrapper struct is by far the easiest, as custom marshalling can make it trivial to marshal both UTF8 and UTF16 strings down.
The final consideration is its nice to have an identical concept for both input and output. It makes the rules fairly easy to understand.
WPILib will not have any APIs that manipulate a string allocated externally. This means WPI_String can be const, as across the boundary it is always const.
If a WPILib API takes a const WPI_String*, WPILib will not manipulate or attempt to free that string, and that string is treated as an input. It is up to the caller to handle that memory, WPILib will never hold onto that memory longer than the call.
If a WPILib API takes a WPI_String*, that string is an output. WPILib will allocate that API with WPI_AllocateString(), fill in the string, and return to the caller. When the caller is done with the string, they must free it with WPI_FreeString().
If an output struct contains a WPI_String member, that member is considered read only, and should not be explicitly freed. The caller should call the free function for that struct.
If an array of WPI_Strings are returned, each individual string is considered read only, and should not be explicitly freed. The free function for that array should be called by the caller.
If an input struct containing a WPI_String, or an input array of WPI_Strings is passed to WPILib, the individual strings will not be manipulated or freed by WPILib, and the caller owns and should free that memory.
Callbacks also follow these rules. The most common is a callback either getting passed a const WPI_String* or a struct containing a WPI_String. In both of these cases, the callback target should consider these strings read only, and not attempt to free them or manipulate them.
2024-05-13 05:35:14 -07:00
|
|
|
HALSIM_SetGameSpecificMessage(&str);
|
2024-01-20 21:10:02 -08:00
|
|
|
HALSIM_SetDriverStationDsAttached(m_dsAttached.GetValue());
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
void FMSSimModel::Update() {
|
|
|
|
|
bool enabled = HALSIM_GetDriverStationEnabled();
|
|
|
|
|
m_fmsAttached.SetValue(HALSIM_GetDriverStationFmsAttached());
|
|
|
|
|
m_dsAttached.SetValue(HALSIM_GetDriverStationDsAttached());
|
|
|
|
|
m_allianceStationId.SetValue(HALSIM_GetDriverStationAllianceStationId());
|
|
|
|
|
m_estop.SetValue(HALSIM_GetDriverStationEStop());
|
|
|
|
|
m_enabled.SetValue(enabled);
|
|
|
|
|
m_test.SetValue(HALSIM_GetDriverStationTest());
|
|
|
|
|
m_autonomous.SetValue(HALSIM_GetDriverStationAutonomous());
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
double matchTime = HALSIM_GetDriverStationMatchTime();
|
2022-02-12 22:31:10 -08:00
|
|
|
if (!IsDSDisabled() && enabled) {
|
2020-09-12 10:55:46 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
double curTime = HAL_GetFPGATime(&status) * 1.0e-6;
|
2022-02-12 22:31:10 -08:00
|
|
|
if (m_startMatchTime == -1.0) {
|
|
|
|
|
m_startMatchTime = matchTime + curTime;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2022-02-12 22:31:10 -08:00
|
|
|
matchTime = m_startMatchTime - curTime;
|
|
|
|
|
if (matchTime < 0) {
|
|
|
|
|
matchTime = -1.0;
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
2022-02-12 22:31:10 -08:00
|
|
|
HALSIM_SetDriverStationMatchTime(matchTime);
|
2020-09-12 10:55:46 -07:00
|
|
|
} else {
|
2022-02-12 22:31:10 -08:00
|
|
|
if (m_startMatchTime != -1.0) {
|
|
|
|
|
matchTime = -1.0;
|
|
|
|
|
HALSIM_SetDriverStationMatchTime(matchTime);
|
|
|
|
|
}
|
|
|
|
|
m_startMatchTime = -1.0;
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
m_matchTime.SetValue(matchTime);
|
2024-01-20 21:10:02 -08:00
|
|
|
|
|
|
|
|
HAL_MatchInfo info;
|
|
|
|
|
HALSIM_GetMatchInfo(&info);
|
2025-01-03 13:36:40 -08:00
|
|
|
m_gameMessage.SetValue(
|
|
|
|
|
std::string_view{reinterpret_cast<const char*>(info.gameSpecificMessage),
|
|
|
|
|
reinterpret_cast<const char*>(info.gameSpecificMessage) +
|
|
|
|
|
info.gameSpecificMessageSize});
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
bool FMSSimModel::IsReadOnly() {
|
|
|
|
|
return IsDSDisabled();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
static void DisplaySystemJoystick(SystemJoystick& joy, int i) {
|
|
|
|
|
char label[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "{}: {}", i, joy.GetName());
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
// highlight if any buttons pressed
|
|
|
|
|
bool anyButtonPressed = joy.IsAnyButtonPressed();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (anyButtonPressed) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 0, 255));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Selectable(label, false,
|
|
|
|
|
joy.IsPresent() ? ImGuiSelectableFlags_None
|
|
|
|
|
: ImGuiSelectableFlags_Disabled);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (anyButtonPressed) {
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
|
|
|
|
// drag and drop sources are the low level joysticks
|
|
|
|
|
if (ImGui::BeginDragDropSource()) {
|
|
|
|
|
SystemJoystick* joyPtr = &joy;
|
2021-01-01 10:27:49 -08:00
|
|
|
ImGui::SetDragDropPayload("Joystick", &joyPtr, sizeof(joyPtr)); // NOLINT
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text("%d: %s", i, joy.GetName());
|
|
|
|
|
ImGui::EndDragDropSource();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
static void DisplaySystemJoysticks() {
|
|
|
|
|
ImGui::Text("(Drag and drop to Joysticks)");
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
int numShowJoysticks = gNumGlfwJoysticks < 6 ? 6 : gNumGlfwJoysticks;
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int i = 0; i < numShowJoysticks; ++i) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
DisplaySystemJoystick(*gGlfwJoysticks[i], i);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < gKeyboardJoysticks.size(); ++i) {
|
2021-01-23 09:10:58 -08:00
|
|
|
auto joy = gKeyboardJoysticks[i].get();
|
|
|
|
|
DisplaySystemJoystick(*joy, i + GLFW_JOYSTICK_LAST + 1);
|
|
|
|
|
if (ImGui::BeginPopupContextItem()) {
|
|
|
|
|
char buf[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(buf, sizeof(buf), "{} Settings", joy->GetName());
|
|
|
|
|
|
2021-01-23 09:10:58 -08:00
|
|
|
if (ImGui::MenuItem(buf)) {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (auto win = DriverStationGui::dsManager->GetWindow(buf)) {
|
2021-01-23 09:10:58 -08:00
|
|
|
win->SetVisible(true);
|
|
|
|
|
}
|
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void DisplayJoysticks() {
|
2020-09-02 20:51:43 -07:00
|
|
|
bool disableDS = IsDSDisabled();
|
2019-09-23 00:24:10 -07:00
|
|
|
// imgui doesn't size columns properly with autoresize, so force it
|
2019-10-13 23:25:21 -07:00
|
|
|
ImGui::Dummy(ImVec2(ImGui::GetFontSize() * 10 * HAL_kMaxJoysticks, 0));
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
ImGui::Columns(HAL_kMaxJoysticks, "Joysticks", false);
|
|
|
|
|
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
|
|
|
|
|
auto& joy = gRobotJoysticks[i];
|
2020-01-20 22:47:36 -08:00
|
|
|
char label[128];
|
2020-08-14 20:02:35 -07:00
|
|
|
joy.name.GetLabel(label, sizeof(label), "Joystick", i);
|
2020-09-02 20:51:43 -07:00
|
|
|
if (!disableDS && joy.sys) {
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::Selectable(label, false);
|
|
|
|
|
if (ImGui::BeginDragDropSource()) {
|
2021-01-01 10:27:49 -08:00
|
|
|
ImGui::SetDragDropPayload("Joystick", &joy.sys,
|
|
|
|
|
sizeof(joy.sys)); // NOLINT
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text("%d: %s", joy.sys->GetIndex(), joy.sys->GetName());
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::EndDragDropSource();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Selectable(label, false, ImGuiSelectableFlags_Disabled);
|
|
|
|
|
}
|
2020-09-02 20:51:43 -07:00
|
|
|
if (!disableDS && ImGui::BeginDragDropTarget()) {
|
2019-09-23 00:24:10 -07:00
|
|
|
if (const ImGuiPayload* payload =
|
|
|
|
|
ImGui::AcceptDragDropPayload("Joystick")) {
|
2021-01-01 10:27:49 -08:00
|
|
|
IM_ASSERT(payload->DataSize == sizeof(SystemJoystick*)); // NOLINT
|
2019-09-23 00:24:10 -07:00
|
|
|
SystemJoystick* payload_sys =
|
|
|
|
|
*static_cast<SystemJoystick* const*>(payload->Data);
|
|
|
|
|
// clear it from the other joysticks
|
|
|
|
|
for (auto&& joy2 : gRobotJoysticks) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (joy2.sys == payload_sys) {
|
|
|
|
|
joy2.sys = nullptr;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
joy2.guid.clear();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
joy.sys = payload_sys;
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
joy.guid = payload_sys->GetGUID();
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view name{payload_sys->GetName()};
|
|
|
|
|
joy.useGamepad =
|
|
|
|
|
wpi::starts_with(name, "Xbox") || wpi::contains(name, "pad");
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
ImGui::EndDragDropTarget();
|
|
|
|
|
}
|
2020-01-20 22:47:36 -08:00
|
|
|
joy.name.PopupEditName(i);
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
|
|
|
|
|
auto& joy = gRobotJoysticks[i];
|
2020-08-14 20:02:35 -07:00
|
|
|
auto source = gJoystickSources[i].get();
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (disableDS) {
|
|
|
|
|
joy.GetHAL(i);
|
|
|
|
|
}
|
2020-08-23 16:47:46 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
if ((disableDS && joy.data.desc.type != 0) ||
|
|
|
|
|
(joy.sys && joy.sys->IsPresent())) {
|
2019-09-23 00:24:10 -07:00
|
|
|
// update GUI display
|
|
|
|
|
ImGui::PushID(i);
|
2020-09-02 20:51:43 -07:00
|
|
|
if (disableDS) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text("%s", joy.data.desc.name);
|
|
|
|
|
ImGui::Text("Gamepad: %s", joy.data.desc.isXbox ? "Yes" : "No");
|
2020-08-23 16:47:46 -07:00
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text("%d: %s", joy.sys->GetIndex(), joy.sys->GetName());
|
2019-09-23 00:24:10 -07:00
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
if (joy.sys->IsGamepad()) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Checkbox("Map gamepad", &joy.useGamepad);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-08-23 16:47:46 -07:00
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
for (int j = 0; j < joy.data.axes.count; ++j) {
|
2020-08-14 20:02:35 -07:00
|
|
|
if (source && source->axes[j]) {
|
|
|
|
|
char label[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "Axis[{}]", j);
|
|
|
|
|
|
2020-08-14 20:02:35 -07:00
|
|
|
ImGui::Selectable(label);
|
|
|
|
|
source->axes[j]->EmitDrag();
|
|
|
|
|
ImGui::SameLine();
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text(": %.3f", joy.data.axes.axes[j]);
|
2020-08-14 20:02:35 -07:00
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text("Axis[%d]: %.3f", j, joy.data.axes.axes[j]);
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
for (int j = 0; j < joy.data.povs.count; ++j) {
|
2020-08-14 20:02:35 -07:00
|
|
|
if (source && source->povs[j]) {
|
|
|
|
|
char label[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "POVs[{}]", j);
|
|
|
|
|
|
2020-08-14 20:02:35 -07:00
|
|
|
ImGui::Selectable(label);
|
|
|
|
|
source->povs[j]->EmitDrag();
|
|
|
|
|
ImGui::SameLine();
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text(": %d", joy.data.povs.povs[j]);
|
2020-08-14 20:02:35 -07:00
|
|
|
} else {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
ImGui::Text("POVs[%d]: %d", j, joy.data.povs.povs[j]);
|
2020-08-14 20:02:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
|
|
|
|
|
// show buttons as multiple lines of LED indicators, 8 per line
|
|
|
|
|
static const ImU32 color = IM_COL32(255, 255, 102, 255);
|
|
|
|
|
wpi::SmallVector<int, 64> buttons;
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
buttons.resize(joy.data.buttons.count);
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int j = 0; j < joy.data.buttons.count; ++j) {
|
2019-09-23 00:24:10 -07:00
|
|
|
buttons[j] = joy.IsButtonPressed(j) ? 1 : -1;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-08-14 20:02:35 -07:00
|
|
|
DrawLEDSources(buttons.data(), source ? source->buttons : nullptr,
|
|
|
|
|
buttons.size(), 8, &color);
|
2019-09-23 00:24:10 -07:00
|
|
|
ImGui::PopID();
|
|
|
|
|
} else {
|
|
|
|
|
ImGui::Text("Unassigned");
|
|
|
|
|
}
|
|
|
|
|
ImGui::NextColumn();
|
|
|
|
|
}
|
|
|
|
|
ImGui::Columns(1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
void DSManager::DisplayMenu() {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (gpDSSocketConnected && *gpDSSocketConnected) {
|
2020-09-02 20:51:43 -07:00
|
|
|
ImGui::MenuItem("Turn off DS (real DS connected)", nullptr, true, false);
|
|
|
|
|
} else {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (gpDisableDS != nullptr) {
|
|
|
|
|
ImGui::MenuItem("Turn off DS", nullptr, gpDisableDS);
|
|
|
|
|
}
|
|
|
|
|
if (gpZeroDisconnectedJoysticks != nullptr) {
|
|
|
|
|
ImGui::MenuItem("Zero disconnected joysticks", nullptr,
|
|
|
|
|
gpZeroDisconnectedJoysticks);
|
|
|
|
|
}
|
|
|
|
|
if (gpUseEnableDisableHotkeys != nullptr) {
|
|
|
|
|
ImGui::MenuItem("Enable on []\\ combo, Disable on Enter", nullptr,
|
|
|
|
|
gpUseEnableDisableHotkeys);
|
|
|
|
|
}
|
|
|
|
|
if (gpUseEstopHotkey != nullptr) {
|
|
|
|
|
ImGui::MenuItem("Disable on Spacebar", nullptr, gpUseEstopHotkey);
|
|
|
|
|
}
|
2020-09-02 20:51:43 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
for (auto&& window : m_windows) {
|
|
|
|
|
window->DisplayMenuItem();
|
|
|
|
|
}
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
2020-09-12 10:55:46 -07:00
|
|
|
void DriverStationGui::GlobalInit() {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
auto& storageRoot = glass::GetStorageRoot("ds");
|
|
|
|
|
dsManager = std::make_unique<DSManager>(storageRoot);
|
|
|
|
|
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
// set up system joysticks (both GLFW and keyboard)
|
2020-12-28 12:58:06 -08:00
|
|
|
for (int i = 0; i <= GLFW_JOYSTICK_LAST; ++i) {
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
gGlfwJoysticks.emplace_back(std::make_unique<GlfwSystemJoystick>(i));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
dsManager->GlobalInit();
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
gFMSModel = std::make_unique<FMSSimModel>();
|
|
|
|
|
|
|
|
|
|
wpi::gui::AddEarlyExecute(DriverStationExecute);
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
storageRoot.SetCustomApply([&storageRoot] {
|
|
|
|
|
gpDisableDS = &storageRoot.GetBool("disable", false);
|
|
|
|
|
gpZeroDisconnectedJoysticks =
|
|
|
|
|
&storageRoot.GetBool("zeroDisconnectedJoysticks", true);
|
|
|
|
|
gpUseEnableDisableHotkeys =
|
|
|
|
|
&storageRoot.GetBool("useEnableDisableHotkeys", false);
|
|
|
|
|
gpUseEstopHotkey = &storageRoot.GetBool("useEstopHotkey", false);
|
|
|
|
|
|
|
|
|
|
auto& keyboardStorage = storageRoot.GetChildArray("keyboardJoysticks");
|
|
|
|
|
keyboardStorage.resize(4);
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (!keyboardStorage[i]) {
|
|
|
|
|
keyboardStorage[i] = std::make_unique<glass::Storage>();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gKeyboardJoysticks.emplace_back(
|
|
|
|
|
std::make_unique<GlfwKeyboardJoystick>(*keyboardStorage[i], i));
|
[sim] GUI: Add keyboard virtual joystick support (#2940)
This allows joystick testing without a physical joystick.
Comes with a default set of keyboard mappings, but these are fully customizable by the user.
Up to 4 virtual joysticks are supported.
Default keyboard mappings:
Joystick 0: axis 0: AD, axis 1: WS, axis 2: ER, buttons ZXCV, POV on numeric keypad
Joystick 1: axis 0: JL, axis 1: IK, buttons M,./
Joystick 2: axis 0: left/right arrow, axis 1: up/down arrow, buttons insert/home/pgup/del/end/pgdn
Also adds support for DS-style hotkeys of []\ enable, Enter disable, and spacebar disable.
All of these are disabled by default and must be explicitly enabled by the user.
2020-12-17 00:20:12 -08:00
|
|
|
}
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
|
|
|
|
|
auto& robotJoystickStorage = storageRoot.GetChildArray("robotJoysticks");
|
|
|
|
|
robotJoystickStorage.resize(HAL_kMaxJoysticks);
|
|
|
|
|
for (int i = 0; i < HAL_kMaxJoysticks; ++i) {
|
|
|
|
|
if (!robotJoystickStorage[i]) {
|
|
|
|
|
robotJoystickStorage[i] = std::make_unique<glass::Storage>();
|
|
|
|
|
}
|
|
|
|
|
gRobotJoysticks.emplace_back(*robotJoystickStorage[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (auto&& joy : gKeyboardJoysticks) {
|
|
|
|
|
char label[64];
|
2023-09-17 20:00:16 -07:00
|
|
|
wpi::format_to_n_c_str(label, sizeof(label), "{} Settings",
|
|
|
|
|
joy->GetName());
|
|
|
|
|
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
if (auto win = dsManager->AddWindow(
|
|
|
|
|
label, [j = joy.get()] { j->SettingsDisplay(); },
|
|
|
|
|
glass::Window::kHide)) {
|
|
|
|
|
win->DisableRenamePopup();
|
|
|
|
|
win->SetDefaultPos(10 + 310 * i++, 50);
|
|
|
|
|
if (i > 3) {
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
|
win->SetDefaultSize(300, 560);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-20 21:10:02 -08:00
|
|
|
if (auto win = dsManager->AddWindow("FMS", [] {
|
|
|
|
|
if (HALSIM_GetDriverStationDsAttached()) {
|
|
|
|
|
DisplayFMSReadOnly(gFMSModel.get());
|
|
|
|
|
} else {
|
|
|
|
|
DisplayFMS(gFMSModel.get(), false);
|
|
|
|
|
}
|
|
|
|
|
})) {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
win->DisableRenamePopup();
|
|
|
|
|
win->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
win->SetDefaultPos(5, 540);
|
|
|
|
|
}
|
|
|
|
|
if (auto win =
|
|
|
|
|
dsManager->AddWindow("System Joysticks", DisplaySystemJoysticks)) {
|
|
|
|
|
win->DisableRenamePopup();
|
|
|
|
|
win->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
win->SetDefaultPos(5, 350);
|
|
|
|
|
}
|
|
|
|
|
if (auto win = dsManager->AddWindow("Joysticks", DisplayJoysticks)) {
|
|
|
|
|
win->DisableRenamePopup();
|
|
|
|
|
win->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
win->SetDefaultPos(250, 465);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
storageRoot.SetCustomClear([&storageRoot] {
|
|
|
|
|
dsManager->EraseWindows();
|
|
|
|
|
gKeyboardJoysticks.clear();
|
|
|
|
|
gRobotJoysticks.clear();
|
|
|
|
|
storageRoot.GetChildArray("keyboardJoysticks").clear();
|
|
|
|
|
storageRoot.GetChildArray("robotJoysticks").clear();
|
|
|
|
|
storageRoot.ClearValues();
|
|
|
|
|
});
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
2020-09-02 20:51:43 -07:00
|
|
|
|
|
|
|
|
void DriverStationGui::SetDSSocketExtension(void* data) {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
gpDSSocketConnected = static_cast<std::atomic<bool>*>(data);
|
2020-09-02 20:51:43 -07:00
|
|
|
}
|