Skip to content

Commit

Permalink
Merge branch 'big_module_update' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
DvaMishkiLapa committed Dec 15, 2024
2 parents e2f5394 + b35d556 commit 92b7a96
Show file tree
Hide file tree
Showing 28 changed files with 602 additions and 149 deletions.
4 changes: 2 additions & 2 deletions client/packages/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ pub fn load_config() -> color_eyre::Result<Config> {
}

// Add the source for environment variables
settings = settings.add_source(Environment::with_prefix("VITAOXIPAD"));
settings = settings.add_source(Environment::with_prefix("VITA_"));

// Check if environment variables are found
if env::vars().any(|(key, _)| key.starts_with("VITAOXIPAD_")) {
if env::vars().any(|(key, _)| key.starts_with("VITA_")) {
println!("Environment variables found. They will take precedence over the config file.");
}

Expand Down
2 changes: 2 additions & 0 deletions client/packages/vita_reports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct ButtonsData {
pub square: bool,
pub vol_up: bool,
pub vol_down: bool,
pub ps: bool,
// timestamp: u64;
}

Expand All @@ -34,6 +35,7 @@ impl From<flatbuffers_structs::net_protocol::ButtonsData> for ButtonsData {
square: buttons.square(),
vol_up: buttons.vol_up(),
vol_down: buttons.vol_down(),
ps: buttons.ps(),
// timestamp: buttons.timestamp(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/packages/vita_virtual_device/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn map_button_to_ds4(button: Button) -> Key {
Button::Circle => Key::ButtonEast,
Button::Cross => Key::ButtonSouth,
Button::Square => Key::ButtonWest,
Button::PSButton => Key::ButtonMode,
}
}

Expand Down Expand Up @@ -144,6 +145,7 @@ impl<F: AsRawFd> VitaDevice<F> {
Button::Circle,
Button::Cross,
Button::Square,
Button::PSButton,
] {
main_handle.set_keybit(map_button_to_ds4(button))?;
}
Expand Down
1 change: 1 addition & 0 deletions client/packages/vita_virtual_device/src/virtual_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum Button {
Circle,
Cross,
Square,
PSButton,
}

#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
Expand Down
1 change: 1 addition & 0 deletions client/packages/vita_virtual_device/src/virtual_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn get_pressed_buttons(
(report_buttons.triangle, Button::Triangle),
(report_buttons.start, Button::Options),
(report_buttons.select, Button::Share),
(report_buttons.ps, Button::PSButton),
];

// Trigger processing depending on the configuration
Expand Down
32 changes: 19 additions & 13 deletions client/packages/vita_virtual_device/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use windows::Win32::UI::Input::KeyboardAndMouse::{
};

use crate::virtual_button::{Button, DpadDirection};
use crate::virtual_config::{Config, ConfigBuilder, TouchConfig, TriggerConfig};
use crate::virtual_config::{Config, ConfigBuilder, TouchConfig};
use crate::virtual_touch::{Point, TouchAction};
use crate::virtual_utils::{compute_dpad_direction, get_pressed_buttons};
use crate::{f32_to_i16, VitaVirtualDevice, FRONT_TOUCHPAD_RECT, REAR_TOUCHPAD_RECT};
Expand Down Expand Up @@ -90,6 +90,7 @@ fn map_button_to_ds4(button: Button) -> u16 {
Button::Circle => DS4Buttons::CIRCLE,
Button::Cross => DS4Buttons::CROSS,
Button::Square => DS4Buttons::SQUARE,
Button::PSButton => DS4SpecialButtons::PS_HOME as u16, // Doesn't really work, added for compatibility between platforms
}
}

Expand Down Expand Up @@ -270,24 +271,12 @@ impl VitaVirtualDevice<&ConfigBuilder> for VitaDevice {
&self.config.front_touch_config,
&mut buttons,
);

process_touch_reports(
&report.back_touch.reports,
&self.config.rear_touch_config,
&mut buttons,
);

// Trigger processing for Trigger configuration
let (mut pwr_trigger_l, mut pwr_trigger_r) = (0u8, 0u8);
if let TriggerConfig::Trigger = self.config.trigger_config {
if report.buttons.lt {
pwr_trigger_l = 255;
}
if report.buttons.rt {
pwr_trigger_r = 255;
}
}

// Handling special touchpad buttons
let is_touching = match (
&self.config.front_touch_config,
Expand All @@ -300,6 +289,7 @@ impl VitaVirtualDevice<&ConfigBuilder> for VitaDevice {

let mut special_buttons = DS4SpecialButtons::new();

// Touch click emulation
if is_touching && !self.touch_state {
self.touch_start_time = Some(Instant::now());
} else if !is_touching && self.touch_state {
Expand All @@ -312,6 +302,8 @@ impl VitaVirtualDevice<&ConfigBuilder> for VitaDevice {
self.touch_start_time = None;
}

special_buttons = special_buttons.ps_home(report.buttons.ps);

self.touch_state = is_touching;

// Создаем touchpad report
Expand All @@ -327,6 +319,20 @@ impl VitaVirtualDevice<&ConfigBuilder> for VitaDevice {
let gyro_y_i16 = f32_to_i16(-report.motion.gyro.y, -35.0, 35.0); //inverted
let gyro_z_i16 = f32_to_i16(report.motion.gyro.z, -35.0, 35.0);

// Trigger processing for Trigger configuration
let (pwr_trigger_l, pwr_trigger_r) = (
if buttons | DS4Buttons::TRIGGER_LEFT == buttons {
255
} else {
0
},
if buttons | DS4Buttons::TRIGGER_RIGHT == buttons {
255
} else {
0
},
);

let report = DS4ReportExBuilder::new()
.thumb_lx(report.lx)
.thumb_ly(report.ly)
Expand Down
1 change: 1 addition & 0 deletions common/netprotocol.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ButtonsData
square: bool;
vol_up: bool;
vol_down: bool;
ps: bool;
}

struct Vector3
Expand Down
40 changes: 35 additions & 5 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.15)

# Set up the Vita SDK toolchain
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VITASDK})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file")
Expand All @@ -8,7 +9,7 @@ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
endif()
endif()


# Application metadata
project(VitaOxiPad)
include("${VITASDK}/share/vita.cmake" REQUIRED)
set(VITA_APP_NAME "VitaOxiPad")
Expand All @@ -20,19 +21,33 @@ if(DEFINED ENV{VITA_IP})
set(VITA_IP $ENV{VITA_IP})
endif()

# Compiler options
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1")
set(VITA_MAKE_FSELF_FLAGS "${VITA_MAKE_FSELF_FLAGS} -a 0x2800000000000001")

# Build FlatBuffers
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../cmake/")
include(BuildFlatBuffers)

add_subdirectory(module)

link_directories(
${CMAKE_CURRENT_BINARY_DIR}
)

# Include directories
include_directories(
./include
../include
module/include
${CMAKE_CURRENT_BINARY_DIR}/module
${CMAKE_BINARY_DIR}/generated
)

link_directories(${CMAKE_CURRENT_BINARY_DIR}/module)

file(GLOB SRC_FLATBUFFERS
../common/*.fbs
)
Expand All @@ -47,21 +62,29 @@ build_flatbuffers("${SRC_FLATBUFFERS}"

include_directories(${CMAKE_BINARY_DIR}/generated)

# App Source files
add_executable(${VITA_APP_NAME}
src/status.cpp
src/ctrl.cpp
src/main.cpp
src/net.cpp
src/status.cpp
src/ctrl.cpp
src/thread_helper.cpp
src/draw_helper.cpp
)

add_compile_definitions(FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE)
target_compile_options(${VITA_APP_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror)

# Dependencies
add_dependencies(${VITA_APP_NAME} flatbuffers_target)
add_dependencies(${VITA_APP_NAME} kctrl_all)

# Libraries
target_link_libraries(${VITA_APP_NAME}
stdc++
vita2d
kctrl_stub_weak
taihen_stub
SceCtrl_stub
SceTouch_stub
SceDisplay_stub
Expand All @@ -71,26 +94,32 @@ target_link_libraries(${VITA_APP_NAME}
ScePower_stub
SceCommonDialog_stub
SceGxm_stub
SceVshBridge_stub
SceShellSvc_stub
SceLibDbg_stub
)

# Create the application self and VPK
vita_create_self(${VITA_APP_NAME}.self ${VITA_APP_NAME})
vita_create_vpk(${VITA_APP_NAME}.vpk ${VITA_TITLEID} ${VITA_APP_NAME}.self
VERSION ${VITA_VERSION}
NAME ${VITA_APP_NAME}
FILE sce_sys/icon0.png sce_sys/icon0.png
FILE sce_sys/pic0.png sce_sys/pic0.png
FILE sce_sys/livearea/contents/bg.png sce_sys/livearea/contents/bg.png
FILE sce_sys/livearea/contents/startup.png sce_sys/livearea/contents/startup.png
FILE sce_sys/livearea/contents/template.xml sce_sys/livearea/contents/template.xml
FILE ${CMAKE_CURRENT_BINARY_DIR}/module/kctrl.skprx module/kctrl.skprx
)

# Send the VPK directly to the PS Vita

# Optional: Send the VPK directly to the PS Vita
if (VITA_IP)
add_custom_target(send
COMMAND "echo" destroy | nc ${VITA_IP} 1338
COMMAND "sleep" 1s
COMMAND unzip -o ${VITA_APP_NAME}.vpk eboot.bin -d ${CMAKE_BINARY_DIR}
COMMAND "curl" --ftp-method nocwd -T ${CMAKE_BINARY_DIR}/eboot.bin "ftp://${VITA_IP}:1337/ux0:/app/${VITA_TITLEID}/"
COMMAND "curl" --ftp-method nocwd -T ${CMAKE_BINARY_DIR}/module/kctrl.skprx "ftp://${VITA_IP}:1337/ux0:/app/${VITA_TITLEID}/module/"
COMMAND "echo" launch ${VITA_TITLEID} | nc ${VITA_IP} 1338
DEPENDS ${VITA_APP_NAME}.vpk
)
Expand All @@ -100,6 +129,7 @@ if(DEFINED ENV{VITA_IP})
set(PARSECOREPATH $ENV{PARSECOREPATH})
endif()

# Optional: Dump debugging information
add_custom_target(dump
COMMAND ${CMAKE_SOURCE_DIR}/get_dump.sh ${VITA_IP}
COMMAND python3 ${PARSECOREPATH} coredump ${CMAKE_PROJECT_NAME}
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions server/include/ctrl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __CTRL_H__
#define __CTRL_H__

#include <netprotocol_generated.h>

#include "events.hpp"

void get_ctrl(SceCtrlData *pad, SceMotionState *motion_data, SceTouchData *touch_data_front,
SceTouchData *touch_data_back);
void ctrl_as_netprotocol(SceCtrlData *pad, SceMotionState *motion_data,
SceTouchData *touch_data_front, SceTouchData *touch_data_back,
flatbuffers::FlatBufferBuilder &builder, int battery_level);

#endif // __CTRL_H__
21 changes: 21 additions & 0 deletions server/include/draw_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <vita2d.h>

#include "events.hpp"

#ifndef DRAW_HELPER_HPP
#define DRAW_HELPER_HPP

extern vita2d_pgf *debug_font;
extern uint32_t need_color;
extern uint32_t common_color;
extern uint32_t error_color;
extern uint32_t done_color;

void draw_rectangle_outline(float x, float y, float width, float height, uint32_t color);
void draw_old_module();
void draw_start_mode(bool connected_to_network, bool pc_connect_state, char *vita_ip,
SharedData *shared_data);
void draw_pad_mode(bool connected_to_network, bool pc_connect_state, char *vita_ip,
SharedData *shared_data);

#endif // DRAW_HELPER_HPP
21 changes: 11 additions & 10 deletions server/src/events.hpp → server/include/events.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef EVENTS_HPP
#define EVENTS_HPP

#include <psp2/ctrl.h>
#include <psp2/kernel/threadmgr.h>
#include <psp2/net/net.h>
#include <psp2/net/netctl.h>
#include <psp2/net/netctl.h>

#include <arpa/inet.h>

Expand All @@ -13,15 +11,15 @@

enum MainEvent {
// For NetThread
PC_DISCONNECT = 1 << 0, // 0x0001
PC_CONNECT = 1 << 1, // 0x0002
NET_CONNECT = 1 << 2, // 0x0004
NET_DISCONNECT = 1 << 3, // 0x0008
PC_DISCONNECT = 1 << 0, // 0x0001
PC_CONNECT = 1 << 1, // 0x0002
NET_CONNECT = 1 << 2, // 0x0004
NET_DISCONNECT = 1 << 3, // 0x0008

// For StatusThread
BATTERY_LEVEL = 1 << 8, // 0x0100
STATUS_CHARGER = 1 << 9, // 0x0200
WIFI_SIGNAL = 1 << 10, // 0x0400
BATTERY_LEVEL = 1 << 8, // 0x0100
STATUS_CHARGER = 1 << 9, // 0x0200
WIFI_SIGNAL = 1 << 10, // 0x0400
};

struct SharedData {
Expand All @@ -30,6 +28,9 @@ struct SharedData {
bool charger_connected = false;
unsigned int wifi_signal_strength = 0;
char client_ip[INET_ADDRSTRLEN] = "N/A";
SceCtrlData pad_data;
bool pad_mode = false;
bool display_on = true;
std::mutex mutex;
};

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion server/src/net.hpp → server/include/net.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef NET_HPP
#define NET_HPP

#include <psp2/net/net.h>
#include <psp2/net/netctl.h>

#include <atomic>
Expand Down
7 changes: 0 additions & 7 deletions server/src/status.hpp → server/include/status.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#ifndef STATUS_HPP
#define STATUS_HPP

#include <atomic>
#include <mutex>

#include <psp2/kernel/threadmgr.h>
#include <psp2/net/net.h>
#include <psp2/net/netctl.h>

#include <atomic>

#include "events.hpp"
Expand Down
21 changes: 21 additions & 0 deletions server/include/thread_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <psp2/kernel/threadmgr.h>

#ifndef THREAD_HELPER_HPP
#define THREAD_HELPER_HPP

struct ThreadParams {
const char *name;
SceKernelThreadEntry entry;
int initPriority;
SceSize stackSize;
SceUInt attr;
int cpuAffinityMask;
const SceKernelThreadOptParam *option;
void *threadArgs;
SceSize threadArgSize;
};

SceUID create_and_start_thread(const ThreadParams &params);
int stop_thread(SceUID thread_uid, SceUInt timeout);

#endif // THREAD_HELPER_HPP
Loading

0 comments on commit 92b7a96

Please sign in to comment.