👽 Updated to work with latest libNX

main
Nichole Mattera 2 years ago
parent 08c63b7a1d
commit 55f03516f7
  1. 6
      Makefile
  2. 1
      README.md
  3. 25
      source/main.cpp
  4. 14
      source/server.cpp
  5. 6
      source/server.hpp

@ -40,7 +40,6 @@ include $(DEVKITPRO)/libnx/switch_rules
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include
#---------------------------------------------------------------------------------
# options for code generation
@ -59,11 +58,6 @@ LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $
LIBS := -ljansson -lnx
ifneq ($(shell which ccache),)
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib

@ -1,5 +1,4 @@
# Open Joystick Display Server NX
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/R6R11DV5K)
This is a very simple system module that listens for Open Joystick Display to request controller inputs, and then send back the controller inputs to be displayed. To install simply put the contents of the zip file in the root of your SD card. Thanks to Jakibaki for most of the code in this and for the help on Discord. For more information on Open Joystick Display: [Click Here](https://ojdproject.com/)

@ -1,7 +1,7 @@
/*
* Open Joystick Display Server NX
* Copyright (C) 2019 Nichole Mattera
* This file is part of OJDS-NX <https://github.com/NicholeMattera/OJDS-NX>.
* Copyright (C) 2021 Nichole Mattera
* This file is part of OJDS-NX <https://git.nicholemattera.com/NicholeMattera/OJDS-NX>.
*
* OJDS-NX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -49,11 +49,11 @@ extern "C" {
rc = smInitialize();
if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
rc = hidInitialize();
if (R_FAILED(rc))
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID));
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_InitFail_HID));
static const SocketInitConfig socketInitConfig = {
.bsdsockets_version = 1,
@ -71,7 +71,7 @@ extern "C" {
rc = socketInitialize(&socketInitConfig);
if (R_FAILED(rc))
fatalSimple(rc);
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen));
}
void __appExit(void) {
@ -86,6 +86,11 @@ int main(int argc, char * argv[]) {
auto server_sock = setupServerSocket();
int client_sock = -1;
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
PadState pad;
padInitializeDefault(&pad);
while (appletMainLoop()) {
client_sock = accept(server_sock, NULL, NULL);
if (client_sock <= 0) {
@ -103,13 +108,11 @@ int main(int argc, char * argv[]) {
break;
}
hidScanInput();
auto keys = hidKeysHeld(CONTROLLER_P1_AUTO);
padUpdate(&pad);
auto keys = padGetButtons(&pad);
JoystickPosition lPos;
JoystickPosition rPos;
hidJoystickRead(&lPos, CONTROLLER_P1_AUTO, JOYSTICK_LEFT);
hidJoystickRead(&rPos, CONTROLLER_P1_AUTO, JOYSTICK_RIGHT);
HidAnalogStickState lPos = padGetStickPos(&pad, 0);
HidAnalogStickState rPos = padGetStickPos(&pad, 1);
auto payload = buildJSONPayload(keys, lPos, rPos);
write(client_sock, payload.c_str(), payload.size());

@ -1,7 +1,7 @@
/*
* Open Joystick Display Server NX
* Copyright (C) 2019 Nichole Mattera
* This file is part of OJDS-NX <https://github.com/NicholeMattera/OJDS-NX>.
* Copyright (C) 2021 Nichole Mattera
* This file is part of OJDS-NX <https://git.nicholemattera.com/NicholeMattera/OJDS-NX>.
*
* OJDS-NX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -44,7 +44,7 @@ int setupServerSocket() {
return server_sock;
}
string buildJSONPayload(u64 keys, JoystickPosition lPos, JoystickPosition rPos) {
string buildJSONPayload(u64 keys, HidAnalogStickState lPos, HidAnalogStickState rPos) {
auto root = json_object();
auto axes = json_array();
auto buttons = json_array();
@ -57,10 +57,10 @@ string buildJSONPayload(u64 keys, JoystickPosition lPos, JoystickPosition rPos)
json_object_set_new(root, "mapping", json_string("standard"));
json_object_set_new(root, "timestamp", json_real(0));
json_array_append_new(axes, json_real((double) lPos.dx / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) lPos.dy * -1 / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) rPos.dx / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) rPos.dy * -1 / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) lPos.x / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) lPos.y * -1 / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) rPos.x / (double) SHRT_MAX));
json_array_append_new(axes, json_real((double) rPos.y * -1 / (double) SHRT_MAX));
for (int i = 0; i < 16; i++) {
bool keyPressed = keys & BIT(i);

@ -1,7 +1,7 @@
/*
* Open Joystick Display Server NX
* Copyright (C) 2019 Nichole Mattera
* This file is part of OJDS-NX <https://github.com/NicholeMattera/OJDS-NX>.
* Copyright (C) 2021 Nichole Mattera
* This file is part of OJDS-NX <https://git.nicholemattera.com/NicholeMattera/OJDS-NX>.
*
* OJDS-NX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,4 +23,4 @@
#include <switch.h>
int setupServerSocket();
std::string buildJSONPayload(u64 keys, JoystickPosition lPos, JoystickPosition rPos);
std::string buildJSONPayload(u64 keys, HidAnalogStickState lPos, HidAnalogStickState rPos);

Loading…
Cancel
Save