Skip to content

Commit 3b17c8b

Browse files
committed
Add option to enable/disable sensorbar
1 parent 5c70719 commit 3b17c8b

File tree

9 files changed

+277
-101
lines changed

9 files changed

+277
-101
lines changed

.github/workflows/ci.yml

+15-22
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@ name: CI-Release
33
on:
44
push:
55
branches:
6-
- main
76
- master
87

98
jobs:
109
clang-format:
1110
runs-on: ubuntu-22.04
1211
steps:
13-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1413
- name: clang-format
1514
run: |
16-
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src
15+
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src
1716
build-binary:
1817
runs-on: ubuntu-22.04
1918
needs: clang-format
2019
steps:
21-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
21+
- name: create version.h
22+
run: |
23+
git_hash=$(git rev-parse --short "$GITHUB_SHA")
24+
cat <<EOF > ./src/version.h
25+
#pragma once
26+
#define VERSION_EXTRA " (nightly-$git_hash)"
27+
EOF
2228
- name: build binary
2329
run: |
2430
docker build . -t builder
@@ -42,25 +48,12 @@ jobs:
4248
- name: zip artifact
4349
run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps
4450
- name: Create Release
45-
id: create_release
46-
uses: actions/create-release@v1
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
uses: "softprops/action-gh-release@v1"
4952
with:
5053
tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
51-
release_name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
5254
draft: false
5355
prerelease: true
54-
body: |
55-
Not a stable release:
56-
${{ github.event.head_commit.message }}
57-
- name: Upload Release Asset
58-
id: upload-release-asset
59-
uses: actions/upload-release-asset@v1
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62-
with:
63-
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
64-
asset_path: ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
65-
asset_name: ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
66-
asset_content_type: application/zip
56+
generate_release_notes: true
57+
name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
58+
files: |
59+
./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ INCLUDES := src
3030
#-------------------------------------------------------------------------------
3131
# options for code generation
3232
#-------------------------------------------------------------------------------
33-
CFLAGS := -g -Wall -O3 -ffunction-sections -fno-exceptions -fno-rtti \
33+
CFLAGS := -g -Wall -O2 -ffunction-sections \
3434
$(MACHDEP)
3535

3636
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__

README.md

+46-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,61 @@
1-
DRC Sensorbar
2-
===============
1+
# DRC Sensorbar
2+
33
This plugin for the [WiiUPluginSystem](https://github.com/wiiu-env/WiiUPluginSystem) enables the sensor bar of the
44
GamePad (DRC) permanently.
55

66
## Limitations
7-
* The sensor bar is turned off when opening the HOME menu or when the GamePad is disconnected. It gets re-enabled when the HOME menu is closed/the GamePad is connected again. This is a system limitation and expected behaviour
8-
* Does not work in applets like the web browser - this is a limitation of the Plugin System
9-
* While using, remember that the cursor is not always shown on the GamePad - you should maybe use this together with
7+
8+
- The sensor bar is turned off when opening the HOME menu or when the GamePad is disconnected. It gets re-enabled when the HOME menu is closed/the GamePad is connected again. This is a system limitation and expected behaviour
9+
- Does not work in applets like the web browser - this is a limitation of the Plugin System
10+
- While using, remember that the cursor is not always shown on the GamePad - you should maybe use this together with
1011
another plugin, that can swap the screens (depending on the game/app)
1112

1213
## Installation
1314

1415
1. Install Aroma
1516
2. Check the Releases page and download the [latest non-preview version](https://github.com/WiiDatabase/DRC-Sensorbar/releases/latest) of this plugin
16-
3. Extract it to "SD://wiiu/environments/aroma/plugins"
17+
3. Extract it to "`SD://wiiu/environments/aroma/plugins`"
1718
4. Done!
19+
5. You can disable the plugin via the WUPS Config Menu ("L" + "D-Pad Down" + "Minus")
1820

1921
## Building
22+
2023
For building you need:
2124

22-
- [wups](https://github.com/wiiu-env/WiiUPluginSystem)
23-
- [wut](https://github.com/devkitPro/wut)
25+
- [wups](https://github.com/Maschell/WiiUPluginSystem)
26+
- [wut](https://github.com/devkitpro/wut)
27+
28+
Install them (in this order) according to their README's. Don't forget the dependencies of the libs itself.
29+
30+
Then you should be able to compile via `make` (with no logging) or `make DEBUG=1` (with logging).
31+
32+
## Buildflags
33+
34+
### Logging
35+
36+
Building via `make` only logs errors (via OSReport). To enable logging via the [LoggingModule](https://github.com/wiiu-env/LoggingModule) set `DEBUG` to `1` or `VERBOSE`.
37+
38+
`make` Logs errors only (via OSReport).
39+
`make DEBUG=1` Enables information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule).
40+
`make DEBUG=VERBOSE` Enables verbose information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule).
41+
42+
If the [LoggingModule](https://github.com/wiiu-env/LoggingModule) is not present, it'll fallback to UDP (Port 4405) and [CafeOS](https://github.com/wiiu-env/USBSerialLoggingModule) logging.
43+
44+
## Building using the Dockerfile
45+
46+
It's possible to use a docker image for building. This way you don't need anything installed on your host system.
47+
48+
```
49+
# Build docker image (only needed once)
50+
docker build . -t drc-sensorbar-builder
51+
52+
# make
53+
docker run -it --rm -v ${PWD}:/project drc-sensorbar-builder make DEBUG=1
54+
55+
# make clean
56+
docker run -it --rm -v ${PWD}:/project drc-sensorbar-builder make clean
57+
```
58+
59+
## Format the code via docker
60+
61+
`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src -i`

clang-format

-67
This file was deleted.

src/main.cpp

+81-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,89 @@
1+
#include "main.h"
2+
#include "utils/logger.h"
13
#include <vpad/input.h>
24
#include <wups.h>
5+
#include <wups/config/WUPSConfigItemBoolean.h>
36

47
WUPS_PLUGIN_NAME("DRC-Sensorbar");
58
WUPS_PLUGIN_DESCRIPTION(
6-
"Enables the sensorbar of the Wii U GamePad permanently.");
7-
WUPS_PLUGIN_VERSION("v2.0");
9+
"Enables the sensorbar of the Wii U GamePad permanently.");
10+
WUPS_PLUGIN_VERSION(VERSION_FULL);
811
WUPS_PLUGIN_AUTHOR("WiiDatabase.de");
912
WUPS_PLUGIN_LICENSE("MIT");
13+
WUPS_USE_STORAGE("drc_sensorbar");
1014

11-
ON_APPLICATION_START() { VPADSetSensorBar(VPAD_CHAN_0, true); }
15+
#define CONFIG_ID_SENSORBAR_ENABLED "enabled"
16+
bool enabled = true;
17+
18+
19+
INITIALIZE_PLUGIN() {
20+
initLogging();
21+
DEBUG_FUNCTION_LINE("INITIALIZE_PLUGIN of example_plugin!");
22+
23+
WUPSStorageError storageRes = WUPS_OpenStorage();
24+
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
25+
DEBUG_FUNCTION_LINE("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
26+
} else {
27+
if ((storageRes = WUPS_GetBool(nullptr, CONFIG_ID_SENSORBAR_ENABLED, &enabled)) == WUPS_STORAGE_ERROR_NOT_FOUND) {
28+
if (WUPS_StoreBool(nullptr, CONFIG_ID_SENSORBAR_ENABLED, enabled) != WUPS_STORAGE_ERROR_SUCCESS) {
29+
DEBUG_FUNCTION_LINE("Failed to store bool");
30+
}
31+
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
32+
DEBUG_FUNCTION_LINE("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
33+
}
34+
35+
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
36+
DEBUG_FUNCTION_LINE("Failed to close storage");
37+
}
38+
}
39+
deinitLogging();
40+
}
41+
42+
WUPS_CONFIG_CLOSED() {
43+
// Save all changes
44+
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
45+
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
46+
}
47+
}
48+
49+
ON_APPLICATION_START() {
50+
initLogging();
51+
if (enabled) {
52+
VPADSetSensorBar(VPAD_CHAN_0, true);
53+
}
54+
}
55+
56+
ON_APPLICATION_ENDS() {
57+
deinitLogging();
58+
}
59+
60+
void enabledChanged(ConfigItemBoolean *item, bool newValue) {
61+
DEBUG_FUNCTION_LINE_INFO("New value in enabledChanged: %d", newValue);
62+
enabled = newValue;
63+
WUPS_StoreInt(nullptr, CONFIG_ID_SENSORBAR_ENABLED, enabled);
64+
65+
if (enabled) {
66+
VPADSetSensorBar(VPAD_CHAN_0, true);
67+
} else {
68+
VPADSetSensorBar(VPAD_CHAN_0, false);
69+
}
70+
}
71+
72+
WUPS_GET_CONFIG() {
73+
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
74+
DEBUG_FUNCTION_LINE("Failed to open storage");
75+
return 0;
76+
}
77+
78+
WUPSConfigHandle config;
79+
WUPSConfig_CreateHandled(&config, "DRC-Sensorbar");
80+
81+
WUPSConfigCategoryHandle cat;
82+
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &cat);
83+
84+
WUPSConfigItemBoolean_AddToCategoryHandled(
85+
config, cat, CONFIG_ID_SENSORBAR_ENABLED, "Enable GamePad Sensorbar", enabled,
86+
&enabledChanged);
87+
88+
return config;
89+
}

src/main.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#include "version.h"
4+
5+
#define VERSION "v2.1"
6+
#define VERSION_FULL VERSION VERSION_EXTRA

src/utils/logger.c

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifdef DEBUG
2+
#include <stdint.h>
3+
#include <whb/log_cafe.h>
4+
#include <whb/log_module.h>
5+
#include <whb/log_udp.h>
6+
7+
uint32_t moduleLogInit = false;
8+
uint32_t cafeLogInit = false;
9+
uint32_t udpLogInit = false;
10+
#endif // DEBUG
11+
12+
void initLogging() {
13+
#ifdef DEBUG
14+
if (!(moduleLogInit = WHBLogModuleInit())) {
15+
cafeLogInit = WHBLogCafeInit();
16+
udpLogInit = WHBLogUdpInit();
17+
}
18+
#endif // DEBUG
19+
}
20+
21+
void deinitLogging() {
22+
#ifdef DEBUG
23+
if (moduleLogInit) {
24+
WHBLogModuleDeinit();
25+
moduleLogInit = false;
26+
}
27+
if (cafeLogInit) {
28+
WHBLogCafeDeinit();
29+
cafeLogInit = false;
30+
}
31+
if (udpLogInit) {
32+
WHBLogUdpDeinit();
33+
udpLogInit = false;
34+
}
35+
#endif // DEBUG
36+
}

0 commit comments

Comments
 (0)