Skip to content

Commit

Permalink
Add option to enable/disable sensorbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Mar 27, 2023
1 parent 5c70719 commit 3b17c8b
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 101 deletions.
37 changes: 15 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ name: CI-Release
on:
push:
branches:
- main
- master

jobs:
clang-format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src
build-binary:
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: create version.h
run: |
git_hash=$(git rev-parse --short "$GITHUB_SHA")
cat <<EOF > ./src/version.h
#pragma once
#define VERSION_EXTRA " (nightly-$git_hash)"
EOF
- name: build binary
run: |
docker build . -t builder
Expand All @@ -42,25 +48,12 @@ jobs:
- name: zip artifact
run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: "softprops/action-gh-release@v1"
with:
tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
release_name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
draft: false
prerelease: true
body: |
Not a stable release:
${{ github.event.head_commit.message }}
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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
asset_path: ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
asset_name: ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
asset_content_type: application/zip
generate_release_notes: true
name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
files: |
./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ INCLUDES := src
#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O3 -ffunction-sections -fno-exceptions -fno-rtti \
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(MACHDEP)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
Expand Down
54 changes: 46 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
DRC Sensorbar
===============
# DRC Sensorbar

This plugin for the [WiiUPluginSystem](https://github.com/wiiu-env/WiiUPluginSystem) enables the sensor bar of the
GamePad (DRC) permanently.

## Limitations
* 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
* Does not work in applets like the web browser - this is a limitation of the Plugin System
* While using, remember that the cursor is not always shown on the GamePad - you should maybe use this together with

- 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
- Does not work in applets like the web browser - this is a limitation of the Plugin System
- While using, remember that the cursor is not always shown on the GamePad - you should maybe use this together with
another plugin, that can swap the screens (depending on the game/app)

## Installation

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

## Building

For building you need:

- [wups](https://github.com/wiiu-env/WiiUPluginSystem)
- [wut](https://github.com/devkitPro/wut)
- [wups](https://github.com/Maschell/WiiUPluginSystem)
- [wut](https://github.com/devkitpro/wut)

Install them (in this order) according to their README's. Don't forget the dependencies of the libs itself.

Then you should be able to compile via `make` (with no logging) or `make DEBUG=1` (with logging).

## Buildflags

### Logging

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`.

`make` Logs errors only (via OSReport).
`make DEBUG=1` Enables information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule).
`make DEBUG=VERBOSE` Enables verbose information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule).

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.

## Building using the Dockerfile

It's possible to use a docker image for building. This way you don't need anything installed on your host system.

```
# Build docker image (only needed once)
docker build . -t drc-sensorbar-builder
# make
docker run -it --rm -v ${PWD}:/project drc-sensorbar-builder make DEBUG=1
# make clean
docker run -it --rm -v ${PWD}:/project drc-sensorbar-builder make clean
```

## Format the code via docker

`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src -i`
67 changes: 0 additions & 67 deletions clang-format

This file was deleted.

84 changes: 81 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,89 @@
#include "main.h"
#include "utils/logger.h"
#include <vpad/input.h>
#include <wups.h>
#include <wups/config/WUPSConfigItemBoolean.h>

WUPS_PLUGIN_NAME("DRC-Sensorbar");
WUPS_PLUGIN_DESCRIPTION(
"Enables the sensorbar of the Wii U GamePad permanently.");
WUPS_PLUGIN_VERSION("v2.0");
"Enables the sensorbar of the Wii U GamePad permanently.");
WUPS_PLUGIN_VERSION(VERSION_FULL);
WUPS_PLUGIN_AUTHOR("WiiDatabase.de");
WUPS_PLUGIN_LICENSE("MIT");
WUPS_USE_STORAGE("drc_sensorbar");

ON_APPLICATION_START() { VPADSetSensorBar(VPAD_CHAN_0, true); }
#define CONFIG_ID_SENSORBAR_ENABLED "enabled"
bool enabled = true;


INITIALIZE_PLUGIN() {
initLogging();
DEBUG_FUNCTION_LINE("INITIALIZE_PLUGIN of example_plugin!");

WUPSStorageError storageRes = WUPS_OpenStorage();
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to open storage %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
} else {
if ((storageRes = WUPS_GetBool(nullptr, CONFIG_ID_SENSORBAR_ENABLED, &enabled)) == WUPS_STORAGE_ERROR_NOT_FOUND) {
if (WUPS_StoreBool(nullptr, CONFIG_ID_SENSORBAR_ENABLED, enabled) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to store bool");
}
} else if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to get bool %s (%d)", WUPS_GetStorageStatusStr(storageRes), storageRes);
}

if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to close storage");
}
}
deinitLogging();
}

WUPS_CONFIG_CLOSED() {
// Save all changes
if (WUPS_CloseStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
}
}

ON_APPLICATION_START() {
initLogging();
if (enabled) {
VPADSetSensorBar(VPAD_CHAN_0, true);
}
}

ON_APPLICATION_ENDS() {
deinitLogging();
}

void enabledChanged(ConfigItemBoolean *item, bool newValue) {
DEBUG_FUNCTION_LINE_INFO("New value in enabledChanged: %d", newValue);
enabled = newValue;
WUPS_StoreInt(nullptr, CONFIG_ID_SENSORBAR_ENABLED, enabled);

if (enabled) {
VPADSetSensorBar(VPAD_CHAN_0, true);
} else {
VPADSetSensorBar(VPAD_CHAN_0, false);
}
}

WUPS_GET_CONFIG() {
if (WUPS_OpenStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE("Failed to open storage");
return 0;
}

WUPSConfigHandle config;
WUPSConfig_CreateHandled(&config, "DRC-Sensorbar");

WUPSConfigCategoryHandle cat;
WUPSConfig_AddCategoryByNameHandled(config, "Settings", &cat);

WUPSConfigItemBoolean_AddToCategoryHandled(
config, cat, CONFIG_ID_SENSORBAR_ENABLED, "Enable GamePad Sensorbar", enabled,
&enabledChanged);

return config;
}
6 changes: 6 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "version.h"

#define VERSION "v2.1"
#define VERSION_FULL VERSION VERSION_EXTRA
36 changes: 36 additions & 0 deletions src/utils/logger.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>

uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif // DEBUG

void initLogging() {
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
}

void deinitLogging() {
#ifdef DEBUG
if (moduleLogInit) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}
Loading

0 comments on commit 3b17c8b

Please sign in to comment.