Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27b7da8c89 | ||
|
|
78cc80064a | ||
|
|
8eb433f01e | ||
|
|
c4fa9e4138 | ||
|
|
a9f49d91b9 | ||
|
|
87818b6a22 | ||
|
|
17dcdcde23 | ||
|
|
5c0f871415 | ||
|
|
44b9dce139 | ||
|
|
a776085b76 | ||
|
|
0d30170de0 | ||
|
|
2aee847d7c | ||
|
|
9712396c6f | ||
|
|
6a36c2825f | ||
|
|
2b787cba00 | ||
|
|
3c81f749b8 | ||
|
|
3c1b1948fd | ||
|
|
3b10509ecd | ||
|
|
b734330d38 | ||
|
|
eb95db1dda | ||
|
|
3a803550ea | ||
|
|
26e0e87cd7 | ||
|
|
7f17a5307c | ||
|
|
ae87a2eaa5 | ||
|
|
738a181d61 | ||
|
|
ba6c624a59 | ||
|
|
822d4096e7 | ||
|
|
a3e932e2dc | ||
|
|
ad53dd654c | ||
|
|
522185d19b | ||
|
|
030813cd4f | ||
|
|
53467a2a5e | ||
|
|
b5fa399f79 | ||
|
|
4a72f760b6 | ||
|
|
89c73a2fd3 | ||
|
|
6b72e23638 | ||
|
|
8c6b8ef7ac | ||
|
|
a628afa815 | ||
|
|
712b900d68 | ||
|
|
79642a7653 | ||
|
|
fbe92cc1c9 | ||
|
|
9e32b3f286 | ||
|
|
b3b2c6854d | ||
|
|
29b446e648 | ||
|
|
0142ab61a3 | ||
|
|
09a832a38e | ||
|
|
9f99cb3e12 | ||
|
|
acc37e005a | ||
|
|
e5ac137b04 | ||
|
|
522a64b0f3 | ||
|
|
d465db0055 | ||
|
|
2eb48907a0 | ||
|
|
479c77d251 | ||
|
|
e32cac5666 | ||
|
|
93a967ec15 | ||
|
|
db6b5b027c | ||
|
|
76b7d4dafc | ||
|
|
f7df9ab90e | ||
|
|
5781518f44 | ||
|
|
ce05f0d78b | ||
|
|
7415ecf85f | ||
|
|
6b84a85639 | ||
|
|
38e13be623 | ||
|
|
2433417cf6 | ||
|
|
5b1ac7c74a | ||
|
|
24a5811b07 | ||
|
|
00a177fd2f | ||
|
|
acd52f78dd | ||
|
|
0b1014763e |
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
# https://gitlab.archlinux.org/archlinux/devtools/-/merge_requests/197
|
||||
|
||||
args=("$@")
|
||||
has_keep_unit=0
|
||||
|
||||
for arg in "${args[@]}"; do
|
||||
if [[ "$arg" == "--keep-unit" ]]; then
|
||||
has_keep_unit=1
|
||||
fi
|
||||
done
|
||||
|
||||
if ! (( has_keep_unit )); then
|
||||
args=("--keep-unit" "${args[@]}")
|
||||
fi
|
||||
|
||||
exec /usr/bin/systemd-nspawn "${args[@]}"
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
- name: Update apt
|
||||
run: sudo apt update
|
||||
- name: Install Dependencies
|
||||
run: sudo apt install -y libuv1-dev libargtable2-dev libserialport-dev libconfig-dev libhidapi-dev liblua5.4-dev libxdg-basedir-dev libxml2-dev libpulse-dev
|
||||
run: sudo apt install -y libuv1-dev libargtable2-dev libserialport-dev libconfig-dev libhidapi-dev liblua5.4-dev libxdg-basedir-dev libxml2-dev libpulse-dev libproc2-dev
|
||||
- name: Set build dir
|
||||
id: strings
|
||||
shell: bash
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
mkdir PKG_SOURCE
|
||||
mkdir -p PKG_SOURCE/DEBIAN
|
||||
mkdir -p PKG_SOURCE/usr/bin/
|
||||
cp ./tools/distro/debian/dpkg/control ./PKG_SOURCE/DEBIAN/control
|
||||
cp ./tools/distro/debian/dpkg/${{ matrix.os }}/control ./PKG_SOURCE/DEBIAN/control
|
||||
cp ./build/monocoque ./PKG_SOURCE/usr/bin/monocoque
|
||||
dpkg-deb --build PKG_SOURCE monocoque-${{ matrix.os }}.deb
|
||||
|
||||
@@ -79,3 +79,23 @@ jobs:
|
||||
with:
|
||||
files: monocoque-${{ matrix.os }}.rpm
|
||||
|
||||
#arch-build:
|
||||
# runs-on: ubuntu-latest
|
||||
# container:
|
||||
# image: archlinux
|
||||
# options: --privileged
|
||||
# steps:
|
||||
# - uses: actions/checkout@v3
|
||||
# - name: Set proper repository url in PKGBUILD
|
||||
# run: sed -i "s|%URL%|${{ github.server_url }}/${{ github.repository }}|" $GITHUB_WORKSPACE/tools/distro/arch/git/PKGBUILD
|
||||
# - run: echo "$GITHUB_WORKSPACE/.github/bin" >> "$GITHUB_PATH"
|
||||
# - name: Build Arch Linux package
|
||||
# uses: FFY00/build-arch-package@v1
|
||||
# with:
|
||||
# BUILD_SCRIPT: extra-x86_64-build
|
||||
# PKGBUILD: $GITHUB_WORKSPACE/tools/distro/arch/git/PKGBUILD
|
||||
# OUTDIR: $HOME/arch-packages
|
||||
# - name: Release the Package
|
||||
# uses: softprops/action-gh-release@v1
|
||||
# with:
|
||||
# files: $HOME/arch-packages/monocoque*.zst
|
||||
|
||||
+36
-6
@@ -1,7 +1,4 @@
|
||||
|
||||
# minimum CMake version required for C++20 support, among other things
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
# detect if Monocoque is being used as a sub-project of another CMake project
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
set(MONOCOQUE_SUBPROJECT OFF)
|
||||
@@ -20,9 +17,25 @@ set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed -ldl")
|
||||
set(LIBUSB_INCLUDE_DIR /usr/include/libusb-1.0)
|
||||
set(LIBXML_INCLUDE_DIR /usr/include/libxml2)
|
||||
|
||||
FIND_PACKAGE(Lua 5.3 REQUIRED)
|
||||
FIND_PACKAGE(Lua)
|
||||
set(INCLUDE_DIRS ${LUA_INCLUDE_DIR})
|
||||
include_directories(${LUA_INCLUDE_DIR})
|
||||
if(Lua_FOUND AND NOT TARGET Lua::Lua)
|
||||
add_library(Lua::Lua INTERFACE IMPORTED)
|
||||
set_target_properties(
|
||||
Lua::Lua
|
||||
PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
|
||||
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
|
||||
)
|
||||
|
||||
endif()
|
||||
message("Lua ${Lua_VERSION} found")
|
||||
if (Lua_VERSION VERSION_GREATER_EQUAL "5.5.0")
|
||||
add_compile_definitions(USE_LUA_55)
|
||||
else()
|
||||
remove_definitions(USE_LUA_55)
|
||||
endif()
|
||||
|
||||
#FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
|
||||
# HINTS $ENV{LIBUSB_ROOT}
|
||||
@@ -39,14 +52,31 @@ set(BUILD_SHARED_LIBS TRUE) # HIDAPI as static library on all platforms
|
||||
|
||||
add_executable(monocoque src/monocoque/monocoque.c)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(LIBPROCPS libprocps)
|
||||
pkg_check_modules(LIBPROC2 libproc2)
|
||||
|
||||
if (LIBPROCPS_FOUND)
|
||||
#add_compile_definitions(USE_OLD_PID_VAL=0)
|
||||
elseif (LIBPROC2_FOUND)
|
||||
if (LIBPROC2_VERSION VERSION_GREATER_EQUAL "4.0.5")
|
||||
#add_compile_definitions(USE_OLD_PID_VAL=0)
|
||||
else()
|
||||
add_compile_definitions(USE_OLD_PID_VAL=1)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "Either libprocps or libproc2 is required")
|
||||
endif()
|
||||
|
||||
#if(USE_PULSEAUDIO)
|
||||
#else()
|
||||
#endif()
|
||||
|
||||
message("Using pulseaudio backend...")
|
||||
add_compile_definitions(USE_PULSEAUDIO=true)
|
||||
target_link_libraries(monocoque m hidapi-hidraw pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir ${LUA_LIBRARY})
|
||||
target_link_libraries(monocoque m hidapi-hidraw pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir Lua::Lua proc2)
|
||||
|
||||
target_include_directories(monocoque PUBLIC config ${LIBXML_INCLUDE_DIR})
|
||||
target_include_directories(monocoque PUBLIC config ${LIBXML_INCLUDE_DIR} ${LUA_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(src/monocoque/gameloop)
|
||||
add_subdirectory(src/monocoque/simulatorapi)
|
||||
|
||||
@@ -21,6 +21,10 @@ Cross Platform device manager for driving and flight simulators, for use with co
|
||||
- Convincing shaker effects for noise tranducers for wheel slip, wheel lock, and abs, as well as engine rpm and gear shifts.
|
||||
- Support for many [wheels and pedals](https://spacefreak18.github.io/simapi/thirdpartydevices) including Clubsport Elite V3, [Logitech G29](https://spacefreak18.github.io/simapi/logitechg29), and Moza R5.
|
||||
|
||||
## Adding More Devices
|
||||
- If a device isn't already supported, feel free to assist in the reverse engineering process by submitting a pcap or even better working code in a pull request!
|
||||
https://santeri.pikarinen.com/pages/usb_hid_reverse_engineering/
|
||||
|
||||
## Quick Install
|
||||
|
||||
**One-Line Installation:**
|
||||
@@ -37,6 +41,20 @@ chmod +x install.sh
|
||||
./install.sh
|
||||
```
|
||||
|
||||
### Installation on Immutable Distros (Bazzite, Silverblue, etc.)
|
||||
|
||||
On immutable distributions where native package managers are unavailable,
|
||||
monocoque can be installed inside a distrobox container:
|
||||
|
||||
```bash
|
||||
bash tools/distro/distrobox/install-distrobox.sh
|
||||
```
|
||||
|
||||
This creates an Arch Linux container, installs all packages via AUR, and sets up
|
||||
wrapper scripts (`start-simd`, `start-monocoque`, `test-monocoque`) in `~/.local/bin/`.
|
||||
|
||||
To uninstall: `bash tools/distro/distrobox/uninstall-distrobox.sh`
|
||||
|
||||
**TUI Manager:**
|
||||
After installation, use the interactive manager:
|
||||
```bash
|
||||
@@ -62,11 +80,12 @@ for installation instructions***
|
||||
- libconfig
|
||||
- xdg-basedir
|
||||
- lua
|
||||
- libproc2
|
||||
- [slog](https://github.com/kala13x/slog) (static)
|
||||
- [simshmbridge](https://github.com/spacefreak18/simshmbridge) - for sims that need shared memory mapping like AC and Project Cars related.
|
||||
- [simapi](https://github.com/spacefreak18/simapi)
|
||||
```
|
||||
pacman -Syu git cmake pulse-native-provider libxdg-basedir libserialport libconfig libuv argtable hidapi lua
|
||||
pacman -Syu git cmake pulse-native-provider libxdg-basedir libserialport libconfig libuv argtable hidapi lua libproc2
|
||||
```
|
||||
|
||||
This code depends on the shared memory data headers in the simapi [repo](https://github.com/spacefreak18/simapi). When pulling lastest if the submodule does not download run:
|
||||
|
||||
@@ -26,6 +26,7 @@ configs = (
|
||||
modulation = "frequency";
|
||||
frequency = 17;
|
||||
frequencyMax = 37;
|
||||
noise = 10; // additive noise in Hz
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
@@ -219,6 +220,7 @@ configs = (
|
||||
config = "None";
|
||||
baud = 115200;
|
||||
devpath = "/dev/simdev1";
|
||||
fanpower = 0.6;
|
||||
},
|
||||
|
||||
{
|
||||
@@ -227,6 +229,7 @@ configs = (
|
||||
config = "None";
|
||||
baud = 115200;
|
||||
devpath = "/dev/simdev1";
|
||||
fanpower = 0.6;
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
+2
-2
@@ -95,7 +95,7 @@ install_dependencies() {
|
||||
|
||||
case $DISTRO in
|
||||
arch|manjaro)
|
||||
local deps="yder libuv argtable libserialport libconfig hidapi lua libxdg-basedir mingw-w64-gcc"
|
||||
local deps="yder libuv argtable libserialport libconfig hidapi lua54 libpulse pkgconfig libxdg-basedir mingw-w64-gcc"
|
||||
|
||||
# Check if yay is available for AUR
|
||||
if command -v yay &> /dev/null; then
|
||||
@@ -223,7 +223,7 @@ build_simapi() {
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake -DINSTALL_SYSTEMD_SERVICE=off ..
|
||||
make -j$(nproc)
|
||||
|
||||
log_info "Installing simapi library..."
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../monocoque/simulatorapi/simapi/simapi/simdata.h
|
||||
@@ -0,0 +1,166 @@
|
||||
# Makefile for Arduino based scketches
|
||||
#
|
||||
# Copyright 2020 Valerio Di Giampietro http://va.ler.io v@ler.io
|
||||
# MIT License - see License.txt file
|
||||
#
|
||||
# This Makefile uses the arduino-cli, the Arduino command line interface
|
||||
# and has been designed and tested to run on Linux, not on Windows.
|
||||
# Probably it will run on a Mac, but it has not been tested.
|
||||
#
|
||||
# Please note that:
|
||||
#
|
||||
# 1. each sketch must reside in his own folder with this Makefile
|
||||
#
|
||||
# 2. the main make targets are:
|
||||
# - all compiles and upload
|
||||
# - compile compiles only
|
||||
# - upload upload via serial port, compile if the binary file is
|
||||
# not available
|
||||
# - ota upload Over The Air, automatically find the device
|
||||
# IP address using the IOT_NAME (device hostname)
|
||||
# - clean clean the build directory
|
||||
# - find find OTA updatable devices on the local subnet
|
||||
# - requirements it the file "requirements.txt" exists it will
|
||||
# install the libraries listed in this file
|
||||
#
|
||||
# default is "all"
|
||||
#
|
||||
# 3. it gets the name of the sketch using the wildcard make command;
|
||||
# the name is *.ino; this means that you must have ONLY a file
|
||||
# with .ino extension, otherwise this makefile will break. This
|
||||
# also means that you can use this Makefile, almost unmodified,
|
||||
# for any sketch as long as you keep a single .ino file in each
|
||||
# folder
|
||||
#
|
||||
# 4. you can split your project in multiple files, if you wish,
|
||||
# using a single .ino file and multiple .h files, that you can
|
||||
# include in the .ino file with an '#include "myfile.h"'
|
||||
# directive
|
||||
#
|
||||
# Optionally some environment variables can be set:
|
||||
#
|
||||
# FQBN Fully Qualified Board Name; if not set in the environment
|
||||
# it will be assigned a value in this makefile
|
||||
#
|
||||
# SERIAL_DEV Serial device to upload the sketch; if not set in the
|
||||
# environment it will be assigned:
|
||||
# /dev/ttyUSB0 if it exists, or
|
||||
# /dev/ttyACM0 if it exists, or
|
||||
# unknown
|
||||
#
|
||||
# IOT_NAME Name of the IOT device; if not set in the environment
|
||||
# it will be assigned a value in this makefile. This is
|
||||
# very useful for OTA update, the device will be searched
|
||||
# on the local subnet using this name
|
||||
#
|
||||
# OTA_PORT Port used by OTA update; if not set in the environment
|
||||
# it will be assigned the default value of 8266 in this
|
||||
# makefile
|
||||
#
|
||||
# OTA_PASS Password used for OTA update; if not set in the environment
|
||||
# it will be assigned the default value of an empty string
|
||||
#
|
||||
# V verbose flag; can be 0 (quiet) or 1 (verbose); if not set
|
||||
# in the environment it will be assigned a default value
|
||||
# in this makefile
|
||||
|
||||
|
||||
MAKE_DIR := $(PWD)
|
||||
#
|
||||
# ----- setup wor Wemos D1 mini -----
|
||||
#FQBN ?= esp8266:esp8266:d1_mini
|
||||
#IOT_NAME ?= esp8266-meteo
|
||||
#OTA_PORT ?= 8266
|
||||
#OTA_PASS ?=
|
||||
# ----- setup for Arduino Uno
|
||||
FQBN ?= arduino:avr:uno
|
||||
# ----- ---------------------
|
||||
V ?= 0
|
||||
VFLAG =
|
||||
|
||||
ifeq "$(V)" "1"
|
||||
VFLAG =-v
|
||||
endif
|
||||
|
||||
ifndef SERIAL_DEV
|
||||
ifneq (,$(wildcard /dev/ttyUSB0))
|
||||
SERIAL_DEV = /dev/ttyUSB0
|
||||
else ifneq (,$(wildcard /dev/ttyACM0))
|
||||
SERIAL_DEV = /dev/ttyACM0
|
||||
else
|
||||
SERIAL_DEV = unknown
|
||||
endif
|
||||
endif
|
||||
|
||||
BUILD_DIR := $(subst :,.,build/$(FQBN))
|
||||
|
||||
SRC := $(wildcard *.ino)
|
||||
HDRS := $(wildcard *.h)
|
||||
BIN := $(BUILD_DIR)/$(SRC).bin
|
||||
ELF := $(BUILD_DIR)/$(SRC).elf
|
||||
|
||||
$(info FQBN is [${FQBN}])
|
||||
$(info IOT_NAME is [${IOT_NAME}])
|
||||
$(info OTA_PORT is [${OTA_PORT}])
|
||||
$(info OTA_PASS is [${OTA_PASS}])
|
||||
$(info V is [${V}])
|
||||
$(info VFLAG is [${VFLAG}])
|
||||
$(info MAKE_DIR is [${MAKE_DIR}])
|
||||
$(info BUILD_DIR is [${BUILD_DIR}])
|
||||
$(info SRC is [${SRC}])
|
||||
$(info HDRS is [${HDRS}])
|
||||
$(info BIN is [${BIN}])
|
||||
$(info SERIAL_DEV is [${SERIAL_DEV}])
|
||||
|
||||
all: $(ELF) upload
|
||||
.PHONY: all
|
||||
|
||||
compile: $(ELF)
|
||||
.PHONY: compile
|
||||
|
||||
$(ELF): $(SRC) $(HDRS)
|
||||
arduino-cli compile -b $(FQBN) $(VFLAG)
|
||||
@if which arduino-manifest.pl; \
|
||||
then echo "---> Generating manifest.txt"; \
|
||||
arduino-manifest.pl -b $(FQBN) $(SRC) $(HDRS) > manifest.txt; \
|
||||
else echo "---> If you want to generate manifest.txt, listing used libraries and their versions,"; \
|
||||
echo "---> please install arduino-manifest, see https://github.com/digiampietro/arduino-manifest"; \
|
||||
fi
|
||||
|
||||
upload:
|
||||
@if [ ! -c $(SERIAL_DEV) ] ; \
|
||||
then echo "---> ERROR: Serial Device not available, please set the SERIAL_DEV environment variable" ; \
|
||||
else echo "---> Uploading sketch\n"; \
|
||||
arduino-cli upload -b $(FQBN) -p $(SERIAL_DEV) $(VFLAG); \
|
||||
fi
|
||||
|
||||
ota:
|
||||
@PLAT_PATH=`arduino-cli compile -b $(FQBN) --show-properties | grep '^runtime.platform.path' | awk -F= '{print $$2}'` ; \
|
||||
PY_PATH=`arduino-cli compile -b $(FQBN) --show-properties | grep '^runtime.tools.python3.path' | awk -F= '{print $$2}'` ; \
|
||||
IOT_IP=`avahi-browse _arduino._tcp --resolve --parsable --terminate|grep -i ';$(IOT_NAME);'|grep ';$(OTA_PORT);'| awk -F\; '{print $$8}'|head -1`; \
|
||||
BINFILE=$(wildcard $(BUILD_DIR)/$(SRC)*bin); \
|
||||
echo "PLAT_PATH is [$$PLAT_PATH]" ; \
|
||||
echo "PY_PATH: is [$$PY_PATH]" ; \
|
||||
echo "IOT_IP: is [$$IOT_IP]" ; \
|
||||
echo "BINFILE: is [$$BINFILE]" ; \
|
||||
if [ "$$IOT_IP" = "" ] ; \
|
||||
then echo "Unable to find device IP. Check that the IOT_NAME environment variable is correctly set. Use 'make find' to search devices"; \
|
||||
else echo "---> Uploading Over The Air"; \
|
||||
$$PY_PATH/python3 $$PLAT_PATH/tools/espota.py -i $$IOT_IP -p $(OTA_PORT) --auth=$(OTA_PASS) -f $$BINFILE ;\
|
||||
fi
|
||||
|
||||
clean:
|
||||
@echo "---> Cleaning the build directory"
|
||||
rm -rf build
|
||||
|
||||
find:
|
||||
avahi-browse _arduino._tcp --resolve --parsable --terminate
|
||||
|
||||
requirements:
|
||||
@if [ -e requirements.txt ]; \
|
||||
then while read -r i ; do echo ; \
|
||||
echo "---> Installing " '"'$$i'"' ; \
|
||||
arduino-cli lib install "$$i" ; \
|
||||
done < requirements.txt ; \
|
||||
else echo "---> MISSING requirements.txt file"; \
|
||||
fi
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#ifndef _SIMWINDDATA_H
|
||||
#define _SIMWINDDATA_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t velocity;
|
||||
uint8_t fanpower;
|
||||
}
|
||||
SimWindData;
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "simwind.h"
|
||||
|
||||
// ============================================================
|
||||
// Configuration
|
||||
// ============================================================
|
||||
#define BAUD_RATE 115200
|
||||
#define PWM_PIN_1 9 // Fan PWM output pins
|
||||
#define PWM_PIN_2 10 //
|
||||
#define PWM_MAX 320 // Max PWM value for 25kHz (16MHz / 25kHz / 2)
|
||||
#define SPEED_MIN 0 // Min speed (mph) — fans off below this
|
||||
#define SPEED_MAX 100 // Max speed (mph) — full fan speed at this
|
||||
#define SPEED_THRESHOLD 5 // Below this speed fans are off
|
||||
// ============================================================
|
||||
|
||||
#define BYTE_SIZE sizeof(SimWindData)
|
||||
|
||||
int velocity = 0;
|
||||
int fanpower = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(BAUD_RATE);
|
||||
|
||||
// Configure Timer1 for Phase Correct PWM at 25kHz duty cycle
|
||||
// Mode 10: Phase Correct PWM, TOP = ICR1
|
||||
// WGM13:WGM12:WGM11:WGM10 = 1:0:1:0
|
||||
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
|
||||
TCCR1B = _BV(WGM13) | _BV(CS10); // <-- WGM13 restored, no prescaler
|
||||
ICR1 = PWM_MAX; // TOP = 320 → 16MHz / (2 * 320) = 25kHz
|
||||
pinMode(PWM_PIN_1, OUTPUT);
|
||||
pinMode(PWM_PIN_2, OUTPUT);
|
||||
OCR1A = 0;
|
||||
OCR1B = 0;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
char buff[BYTE_SIZE];
|
||||
if (Serial.available() >= BYTE_SIZE) {
|
||||
if (Serial.readBytes(buff, BYTE_SIZE) != BYTE_SIZE) return;
|
||||
union { SimWindData data; char bytes[BYTE_SIZE]; } u;
|
||||
memcpy(u.bytes, buff, BYTE_SIZE);
|
||||
velocity = u.data.velocity;
|
||||
fanpower = u.data.fanpower;
|
||||
}
|
||||
|
||||
int pwm = 0;
|
||||
if (velocity > SPEED_THRESHOLD) {
|
||||
// Square root scaling for slightly stronger sensation at lower speeds
|
||||
// fanpower (0-255) scales the overall intensity
|
||||
float powerScale = (float)fanpower / 255.0;
|
||||
pwm = (int)(sqrt((float)velocity / SPEED_MAX) * PWM_MAX * powerScale);
|
||||
pwm = constrain(pwm, 0, PWM_MAX);
|
||||
}
|
||||
|
||||
OCR1A = pwm;
|
||||
OCR1B = pwm;
|
||||
}
|
||||
@@ -13,8 +13,6 @@ set(devices_source_files
|
||||
tachdevice.c
|
||||
wheeldevice.h
|
||||
wheeldevice.c
|
||||
usbhapticdevice.h
|
||||
usbhapticdevice.c
|
||||
hapticeffect.h
|
||||
hapticeffect.c
|
||||
sound.h
|
||||
@@ -25,6 +23,8 @@ set(devices_source_files
|
||||
usb/cslelitev3.c
|
||||
usb/simagicp1000.h
|
||||
usb/simagicp1000.c
|
||||
usb/simnetpedals.h
|
||||
usb/simnetpedals.c
|
||||
usb/wheels/logitechg29.h
|
||||
usb/wheels/logitechg29.c
|
||||
usb/wheels/cammusc5.h
|
||||
@@ -42,6 +42,8 @@ set(devices_source_files
|
||||
serial/moza.c
|
||||
serial/moza_new.h
|
||||
serial/moza_new.c
|
||||
serial/moza_ks_pro_wheel.h
|
||||
serial/moza_ks_pro_wheel.c
|
||||
)
|
||||
|
||||
include_directories("." "usb" "sound" "serial")
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "usbhapticdevice.h"
|
||||
#include "simdevice.h"
|
||||
#include "../../helper/confighelper.h"
|
||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../../simulatorapi/simapi/simapi/simmapper.h"
|
||||
@@ -30,11 +31,11 @@ bool hasTyreDiameter(SimData* simdata)
|
||||
return true;
|
||||
}
|
||||
|
||||
int loadtyreconfig(SimData* simdata, char* configfile)
|
||||
int loadtyreconfig(SimData* simdata, char* configfile, bool setDiameters)
|
||||
{
|
||||
config_t cfg;
|
||||
config_init(&cfg);
|
||||
config_setting_t* config_cars = NULL;
|
||||
const config_setting_t* config_cars = NULL;
|
||||
|
||||
if (!config_read_file(&cfg, configfile))
|
||||
{
|
||||
@@ -53,8 +54,9 @@ int loadtyreconfig(SimData* simdata, char* configfile)
|
||||
}
|
||||
slogt("parsing diameters config file");
|
||||
|
||||
int cars = config_setting_length(config_cars);
|
||||
const int cars = config_setting_length(config_cars);
|
||||
|
||||
bool foundCar = false;
|
||||
int i = 0;
|
||||
while (i<cars)
|
||||
{
|
||||
@@ -94,10 +96,15 @@ int loadtyreconfig(SimData* simdata, char* configfile)
|
||||
if (strcicmp(car, simdata->car) == 0 && sim == simdata->simexe)
|
||||
{
|
||||
slogi("found saved car %s with tyre diameters %f %f %f %f", car, tyre0, tyre1, tyre2, tyre3);
|
||||
simdata->tyrediameter[0] = tyre0;
|
||||
simdata->tyrediameter[1] = tyre1;
|
||||
simdata->tyrediameter[2] = tyre2;
|
||||
simdata->tyrediameter[3] = tyre3;
|
||||
foundCar = true;
|
||||
if(setDiameters == true)
|
||||
{
|
||||
simdata->tyrediameter[0] = tyre0;
|
||||
simdata->tyrediameter[1] = tyre1;
|
||||
simdata->tyrediameter[2] = tyre2;
|
||||
simdata->tyrediameter[3] = tyre3;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +120,11 @@ int loadtyreconfig(SimData* simdata, char* configfile)
|
||||
|
||||
config_destroy(&cfg);
|
||||
|
||||
return 0;
|
||||
if(foundCar == true)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int savetyreconfig(SimData* simdata, char* configfile)
|
||||
@@ -184,9 +195,66 @@ void getTyreDiameter(SimData* simdata)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile)
|
||||
int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueSettings* ms)
|
||||
{
|
||||
|
||||
switch (hs->effect_type)
|
||||
{
|
||||
case (EFFECT_ENGINERPM):
|
||||
h->effecttype = EFFECT_ENGINERPM;
|
||||
slogi("Initializing haptic effect for engine vibrations.");
|
||||
break;
|
||||
case (EFFECT_GEARSHIFT):
|
||||
h->effecttype = EFFECT_GEARSHIFT;
|
||||
slogi("Initializing haptic effect for gear shift vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRESLIP):
|
||||
h->effecttype = EFFECT_TYRESLIP;
|
||||
slogi("Initializing haptic effect for tyre slip vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
h->effecttype = EFFECT_TYRELOCK;
|
||||
slogi("Initializing haptic effect for tyre lock vibrations.");
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
h->effecttype = EFFECT_ABSBRAKES;
|
||||
slogi("Initializing haptic effect for abs vibrations.");
|
||||
break;
|
||||
|
||||
case (EFFECT_SUSPENSION):
|
||||
h->effecttype = EFFECT_SUSPENSION;
|
||||
slogi("Initializing haptic effect for suspension vibrations.");
|
||||
break;
|
||||
}
|
||||
|
||||
h->tyre = hs->tyre;
|
||||
slogi("Haptic effect: %i %i, tyre %i %i", h->effecttype, hs->effect_type, h->tyre, hs->tyre);
|
||||
|
||||
h->threshold = hs->threshold;
|
||||
h->modulationType = hs->modulation;
|
||||
h->basefrequency = hs->frequency;
|
||||
h->frequencyMax = hs->frequencyMax;
|
||||
h->baseamplitude = hs->amplitude;
|
||||
h->amplitudeMax = hs->amplitudeMax;
|
||||
h->motorposition = hs->motorposition;
|
||||
h->duration = hs->duration;
|
||||
|
||||
slogt("haptic duration: %f", h->duration);
|
||||
slogt("haptic base frequency: %i", h->basefrequency);
|
||||
slogt("haptic base amplitude: %i", h->baseamplitude);
|
||||
slogt("haptic motorposition: %i", h->motorposition);
|
||||
|
||||
h->useconfig = ms->useconfig;
|
||||
h->configcheck = &ms->configcheck;
|
||||
h->tyrediameterconfig = ms->tyre_diameter_config;
|
||||
}
|
||||
|
||||
|
||||
double slipeffect(SimData* simdata, HapticEffect* h, int useconfig, int* configcheck, char* configfile)
|
||||
{
|
||||
int effecttype = h->effecttype;
|
||||
int tyre = h->tyre;
|
||||
double threshold = h->threshold;
|
||||
double play = 0;
|
||||
double wheelslip[4];
|
||||
wheelslip[0] = 0;
|
||||
@@ -194,80 +262,68 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
|
||||
wheelslip[2] = 0;
|
||||
wheelslip[3] = 0;
|
||||
|
||||
if(simdata->car == NULL || simdata->car[0] == 0)
|
||||
int sim_slip_ratio =0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
useconfig = 0;
|
||||
sim_slip_ratio = abs(simdata->tyreslipratio[i]);
|
||||
}
|
||||
|
||||
slogt("wheel vibration calculation with wheel config set to %i configchecked %i configfile %s car %s sim %i", useconfig, *configcheck, configfile, simdata->car, simdata->simexe);
|
||||
|
||||
switch (effecttype)
|
||||
if(sim_slip_ratio == 0)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
case (EFFECT_TYRELOCK):
|
||||
case (EFFECT_ABSBRAKES):
|
||||
//slogt("wheel vibration calculation with wheel config set to %i configchecked %i configfile %s car %s sim %i", useconfig, *configcheck, configfile, simdata->car, simdata->simexe);
|
||||
|
||||
if(useconfig == 1 && configfile != NULL)
|
||||
{
|
||||
// check for saved tyre diameter in config file
|
||||
// if not saved version exists get tyre diameter and save it
|
||||
// use config check variable to track if the config check has been performed
|
||||
// avoid many opens of the same file
|
||||
int error = 0;
|
||||
if(hasTyreDiameter(simdata)==false && *configcheck == 0)
|
||||
{
|
||||
slogi("attempting load of tyre diameter config");
|
||||
error = loadtyreconfig(simdata, configfile);
|
||||
*configcheck = 1;
|
||||
}
|
||||
switch (effecttype)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
case (EFFECT_TYRELOCK):
|
||||
case (EFFECT_ABSBRAKES):
|
||||
|
||||
if(hasTyreDiameter(simdata)==false)
|
||||
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
slogt("could not find tyre diameter in config file, attempting to calculate new");
|
||||
getTyreDiameter(simdata);
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
double Speedms = kmhtoms * simdata->velocity;
|
||||
slogt("attempting wheel slip calculation");
|
||||
if (Speedms > minspeedinms)
|
||||
{
|
||||
slogi("saving tyre config");
|
||||
error = savetyreconfig(simdata, configfile);
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
wheelslip[i] = (Speedms - simdata->tyrediameter[i] * simdata->tyreRPS[i] / 2) / Speedms;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
double Speedms = kmhtoms * simdata->velocity;
|
||||
slogt("attempting wheel slip calculation");
|
||||
if (Speedms > minspeedinms)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
else
|
||||
{
|
||||
wheelslip[i] = (Speedms - simdata->tyrediameter[i] * simdata->tyreRPS[i] / 2) / Speedms;
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
wheelslip[i] = 0;
|
||||
}
|
||||
}
|
||||
slogt("wheelslip values are %f %f %f %f", wheelslip[0], wheelslip[1], wheelslip[2], wheelslip[3]);
|
||||
slogt("velocities (x,y,z) are %f %f %f", simdata->Xvelocity, simdata->Yvelocity, simdata->Zvelocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
wheelslip[i] = 0;
|
||||
}
|
||||
}
|
||||
slogt("wheelslip values are %f %f %f %f", wheelslip[0], wheelslip[1], wheelslip[2], wheelslip[3]);
|
||||
slogt("velocities (x,y,z) are %f %f %f", simdata->Xvelocity, simdata->Yvelocity, simdata->Zvelocity);
|
||||
}
|
||||
break;
|
||||
case EFFECT_SUSPENSION:
|
||||
break;
|
||||
default:
|
||||
slogd("Unknown effect type");
|
||||
break;
|
||||
case EFFECT_SUSPENSION:
|
||||
break;
|
||||
default:
|
||||
slogw("Unknown effect type %i", effecttype);
|
||||
}
|
||||
if(simdata->Yvelocity <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(simdata->Zvelocity > 1 || simdata->Zvelocity < -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
wheelslip[i] = simdata->tyreslipratio[i];
|
||||
}
|
||||
slogt("wheelslip values from sim are %f %f %f %f", wheelslip[0], wheelslip[1], wheelslip[2], wheelslip[3]);
|
||||
}
|
||||
|
||||
if(simdata->Yvelocity <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(simdata->Zvelocity > 1 || simdata->Zvelocity < -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (effecttype)
|
||||
{
|
||||
|
||||
@@ -2,20 +2,55 @@
|
||||
#define _HAPTICEFFECT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HAPTIC_EFFECT_MODULATION_NONE = 0,
|
||||
HAPTIC_EFFECT_MODULATION_FREQUENCY = 1,
|
||||
HAPTIC_EFFECT_MODULATION_AMPLIFY = 2,
|
||||
}
|
||||
HapticEffectModulationType;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t curr_frequency;
|
||||
uint32_t curr_amplitude;
|
||||
double curr_duration;
|
||||
uint32_t last_gear;
|
||||
}
|
||||
CurrentEffectData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double threshold;
|
||||
VibrationEffectType effecttype;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
HapticEffectModulationType modulationType;
|
||||
|
||||
uint32_t volume;
|
||||
double duration;
|
||||
double threshold;
|
||||
uint32_t motorposition;
|
||||
uint32_t basefrequency;
|
||||
uint32_t frequencyMax;
|
||||
uint32_t baseamplitude;
|
||||
uint32_t amplitudeMax;
|
||||
|
||||
CurrentEffectData live_effect;
|
||||
|
||||
int useconfig;
|
||||
int* configcheck;
|
||||
char* tyrediameterconfig;
|
||||
}
|
||||
HapticEffect;
|
||||
|
||||
double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile);
|
||||
int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueSettings* ms);
|
||||
double slipeffect(SimData* simdata, HapticEffect* h, int useconfig, int* configcheck, char* configfile);
|
||||
bool hasTyreDiameter(SimData* simdata);
|
||||
int loadtyreconfig(SimData* simdata, char* configfile, bool setDiameters);
|
||||
int savetyreconfig(SimData* simdata, char* configfile);
|
||||
void getTyreDiameter(SimData* simdata);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -128,21 +128,20 @@ int GetNumberOfLeds(SerialDevice* serialdevice, int* numlights)
|
||||
|
||||
int arduino_init(SerialDevice* serialdevice, const char* portdev)
|
||||
{
|
||||
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
||||
return serialdevice->id;
|
||||
int id = monocoque_serial_open(serialdevice, portdev);
|
||||
if (id < 0) return id;
|
||||
serialdevice->id = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const char* luafile, bool uselights)
|
||||
{
|
||||
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
||||
|
||||
int error = arduino_init(serialdevice, portdev);
|
||||
|
||||
int numlights = 0;
|
||||
|
||||
monocoque_serial_device serialdev = monocoque_serial_devices[serialdevice->id];
|
||||
int error = 0;
|
||||
if(uselights == true)
|
||||
{
|
||||
error = GetNumberOfLeds(serialdevice, &numlights);
|
||||
@@ -179,7 +178,7 @@ int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const c
|
||||
|
||||
slogi("LUA config setup successful.");
|
||||
|
||||
return serialdevice->id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,39 @@ int simdata_to_lua(lua_State *L, SimData* simdata) {
|
||||
}
|
||||
lua_setfield(L, -2, "pd");
|
||||
|
||||
lua_pushnumber(L, simdata->gas);
|
||||
lua_setfield(L, -2, "gas");
|
||||
|
||||
lua_pushnumber(L, simdata->fuel);
|
||||
lua_setfield(L, -2, "fuel");
|
||||
|
||||
lua_pushnumber(L, simdata->turboboost);
|
||||
lua_setfield(L, -2, "turboboost");
|
||||
|
||||
lua_newtable(L);
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
lua_pushnumber(L, simdata->tyreRPS[i]);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
lua_setfield(L, -2, "tyreRPS");
|
||||
|
||||
lua_newtable(L);
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
lua_pushnumber(L, simdata->tyrediameter[i]);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
lua_setfield(L, -2, "tyrediameter");
|
||||
|
||||
lua_newtable(L);
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
lua_pushnumber(L, simdata->tyretemp[i]);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
lua_setfield(L, -2, "tyretemp");
|
||||
|
||||
return 0; // Return the table to Lua
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#ifndef _ARDUINOLEDLUA_H
|
||||
#define _ARDUINOLEDLUA_H
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
//#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
#ifdef USE_LUA_55
|
||||
/* open all libraries */
|
||||
#define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0)
|
||||
#endif
|
||||
|
||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ int moza_update(SerialDevice* serialdevice, unsigned short rpm, unsigned short m
|
||||
|
||||
int moza_init(SerialDevice* serialdevice, const char* portdev)
|
||||
{
|
||||
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
||||
return serialdevice->id;
|
||||
int id = monocoque_serial_open(serialdevice, portdev);
|
||||
if (id < 0) return id;
|
||||
serialdevice->id = id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "moza.h"
|
||||
#include "moza_ks_pro_wheel.h"
|
||||
#include "../serialadapter.h"
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
#define MOZA_TIMEOUT 1000
|
||||
#define MOZA_MAGIC_VALUE 0x0d
|
||||
#define MOZA_RPM_MASK_TEMPLATE {0x7e, 0x06, 0x3f, 0x17, 0x1a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
|
||||
#define MOZA_RPM_MASK_PAYLOAD_SIZE 11
|
||||
#define MOZA_RPM_COLOR_PAYLOAD_1 {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0xff, 0, 0, 4, 0xff, 0, 0, 0}
|
||||
#define MOZA_RPM_COLOR_PAYLOAD_2 {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 5, 0xff, 0, 0, 6, 0xff, 0, 0, 7, 0xff, 0, 0, 8, 0xff, 0, 0, 9, 0xff, 0, 0, 0}
|
||||
#define MOZA_RPM_COLOR_PAYLOAD_3 {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 10, 0xff, 0x7f, 0, 11, 0xff, 0x7f, 0, 12, 0xff, 0x7f, 0, 13, 0, 0, 0xff, 14, 0, 0, 0xff, 0}
|
||||
#define MOZA_BTN_COLOR_PAYLOAD_1 {0x7e, 0x16, 0x3f, 0x17, 0x19, 1, 0, 0xff, 0, 0, 1, 0xff, 0, 0, 2, 0xff, 0, 0, 3, 0xff, 0, 0, 4, 0xff, 0, 0, 0}
|
||||
#define MOZA_BTN_COLOR_PAYLOAD_2 {0x7e, 0x16, 0x3f, 0x17, 0x19, 1, 5, 0xff, 0, 0, 6, 0xff, 0, 0, 7, 0xff, 0, 0, 8, 0xff, 0, 0, 9, 0xff, 0, 0, 0}
|
||||
#define MOZA_COLOR_PAYLOAD_SIZE 27
|
||||
#define MOZA_FLAG_COLOR_YELLOW_LEFT {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 0, 0xff, 0xaa, 0, 1, 0xff, 0xaa, 0, 2, 0xff, 0xaa, 0, 0, 0xff, 0xaa, 0, 1, 0xff, 0xaa, 0, 0}
|
||||
#define MOZA_FLAG_COLOR_YELLOW_RIGHT {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 15, 0xff, 0xaa, 0, 16, 0xff, 0xaa, 0, 17, 0xff, 0xaa, 0, 15, 0xff, 0xaa, 0, 16, 0xff, 0xaa, 0, 0}
|
||||
#define MOZA_FLAG_COLOR_OFF_LEFT {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}
|
||||
#define MOZA_FLAG_COLOR_OFF_RIGHT {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 0}
|
||||
#define BIT(nr) (1UL << (nr))
|
||||
|
||||
int moza_ks_pro_wheel_update(SerialDevice* serialdevice, SimData* simData)
|
||||
{
|
||||
static uint8_t last_flag = 0xff;
|
||||
unsigned char bytes[] = MOZA_RPM_MASK_TEMPLATE;
|
||||
int size = MOZA_RPM_MASK_PAYLOAD_SIZE;
|
||||
float perctflt = ((float)simData->rpms/(float)simData->maxrpm)*100;
|
||||
int perct = round(perctflt);
|
||||
if (perct >= 98 && (simData->mtick >> 7) & 1 == 1) perct = 0;
|
||||
|
||||
|
||||
if (perct >= 75)
|
||||
bytes[6] |= BIT(3);
|
||||
|
||||
if (perct >= 77)
|
||||
bytes[6] |= BIT(4);
|
||||
|
||||
if (perct >= 79)
|
||||
bytes[6] |= BIT(5);
|
||||
|
||||
if (perct >= 81)
|
||||
bytes[6] |= BIT(6);
|
||||
|
||||
if (perct >= 83)
|
||||
bytes[6] |= BIT(7);
|
||||
|
||||
if (perct >= 85)
|
||||
bytes[7] |= BIT(0);
|
||||
|
||||
if (perct >= 87)
|
||||
bytes[7] |= BIT(1);
|
||||
|
||||
if (perct >= 89)
|
||||
bytes[7] |= BIT(2);
|
||||
|
||||
if (perct >= 91)
|
||||
bytes[7] |= BIT(3);
|
||||
|
||||
if (perct >= 93)
|
||||
bytes[7] |= BIT(4);
|
||||
|
||||
if (perct >= 95)
|
||||
bytes[7] |= BIT(5);
|
||||
|
||||
if (perct >= 97)
|
||||
bytes[7] |= BIT(6);
|
||||
|
||||
|
||||
if (simData->playerflag == SIMAPI_FLAG_YELLOW) {
|
||||
bytes[6] |= BIT(0) | BIT(1) | BIT(2); // left 3 flag LEDs (indices 0, 1, 2)
|
||||
bytes[7] |= BIT(7); // right flag LED (index 15)
|
||||
bytes[8] |= BIT(0) | BIT(1); // right flag LEDs (indices 16, 17)
|
||||
}
|
||||
|
||||
bytes[10] = moza_checksum(bytes, size);
|
||||
|
||||
int result = 1;
|
||||
if (serialdevice->port)
|
||||
{
|
||||
if (simData->playerflag != last_flag) {
|
||||
last_flag = simData->playerflag;
|
||||
if (simData->playerflag == SIMAPI_FLAG_YELLOW) {
|
||||
unsigned char fl[] = MOZA_FLAG_COLOR_YELLOW_LEFT;
|
||||
unsigned char fr[] = MOZA_FLAG_COLOR_YELLOW_RIGHT;
|
||||
fl[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(fl, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
fr[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(fr, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
monocoque_serial_write(serialdevice->id, fl, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, fr, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
} else {
|
||||
unsigned char fl[] = MOZA_FLAG_COLOR_OFF_LEFT;
|
||||
unsigned char fr[] = MOZA_FLAG_COLOR_OFF_RIGHT;
|
||||
fl[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(fl, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
fr[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(fr, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
monocoque_serial_write(serialdevice->id, fl, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, fr, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
slogd("copying %i bytes to moza device", MOZA_RPM_MASK_PAYLOAD_SIZE);
|
||||
slogt("writing bytes %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x from rpm %i maxrpm %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], bytes[9], bytes[10], simData->rpms, simData->maxrpm);
|
||||
result = monocoque_serial_write(serialdevice->id, bytes, size, MOZA_TIMEOUT);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int moza_ks_pro_wheel_init(SerialDevice* serialdevice, const char* portdev)
|
||||
{
|
||||
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
||||
if (serialdevice->id == -1) return serialdevice->id;
|
||||
|
||||
unsigned char p1[] = MOZA_RPM_COLOR_PAYLOAD_1;
|
||||
unsigned char p2[] = MOZA_RPM_COLOR_PAYLOAD_2;
|
||||
unsigned char p3[] = MOZA_RPM_COLOR_PAYLOAD_3;
|
||||
unsigned char p4[] = MOZA_BTN_COLOR_PAYLOAD_1;
|
||||
unsigned char p5[] = MOZA_BTN_COLOR_PAYLOAD_2;
|
||||
|
||||
p1[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p1, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
p2[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p2, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
p3[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p3, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
p4[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p4, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
p5[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p5, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
|
||||
monocoque_serial_write(serialdevice->id, p1, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p2, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p3, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p4, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p5, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
|
||||
unsigned char p6[] = MOZA_FLAG_COLOR_OFF_RIGHT;
|
||||
p6[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p6, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
monocoque_serial_write(serialdevice->id, p6, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
|
||||
return serialdevice->id;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _MOZA_KS_PRO_WHEEL_H
|
||||
#define _MOZA_KS_PRO_WHEEL_H
|
||||
|
||||
#include "../serialdevice.h"
|
||||
#include "../simdevice.h"
|
||||
|
||||
int moza_ks_pro_wheel_update(SerialDevice* serialdevice, SimData* simData);
|
||||
int moza_ks_pro_wheel_init(SerialDevice* serialdevice, const char* portdev);
|
||||
|
||||
#endif
|
||||
@@ -74,8 +74,9 @@ int moza_new_update(SerialDevice* serialdevice, SimData* simData)
|
||||
|
||||
int moza_new_init(SerialDevice* serialdevice, const char* portdev)
|
||||
{
|
||||
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
||||
if (serialdevice->id == -1) return serialdevice->id;
|
||||
int id = monocoque_serial_open(serialdevice, portdev);
|
||||
if (id < 0) return id;
|
||||
serialdevice->id = id;
|
||||
|
||||
unsigned char p1[] = MOZA_RPM_COLOR_PAYLOAD_1;
|
||||
unsigned char p2[] = MOZA_RPM_COLOR_PAYLOAD_2;
|
||||
@@ -87,10 +88,11 @@ int moza_new_init(SerialDevice* serialdevice, const char* portdev)
|
||||
p3[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p3, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
p4[MOZA_COLOR_PAYLOAD_SIZE-1] = moza_checksum(p4, MOZA_COLOR_PAYLOAD_SIZE);
|
||||
|
||||
monocoque_serial_write(serialdevice->id, p1, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p2, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p3, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
monocoque_serial_write(serialdevice->id, p4, MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
unsigned char* payloads[] = {p1, p2, p3, p4};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int result = monocoque_serial_write(serialdevice->id, payloads[i], MOZA_COLOR_PAYLOAD_SIZE, MOZA_TIMEOUT);
|
||||
if (result < 0) return result;
|
||||
}
|
||||
|
||||
return serialdevice->id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,13 @@ int check(enum sp_return result)
|
||||
error_message = sp_last_error_message();
|
||||
sloge("error: serial write failed: %s", error_message);
|
||||
sp_free_error_message(error_message);
|
||||
return result;
|
||||
case SP_ERR_SUPP:
|
||||
printf("Error: Not supported.\n");
|
||||
return result;
|
||||
case SP_ERR_MEM:
|
||||
printf("Error: Couldn't allocate memory.\n");
|
||||
return result;
|
||||
case SP_OK:
|
||||
default:
|
||||
return result;
|
||||
@@ -114,23 +117,30 @@ int monocoque_input_wait(uint8_t serialdevicenum)
|
||||
return sp_input_waiting(monocoque_serial_dev.port);
|
||||
}
|
||||
|
||||
int monocoque_serial_write(uint8_t serialdevicenum, void* data, size_t size, int timeout)
|
||||
// Helper function to get and validate device
|
||||
static monocoque_serial_device* monocoque_get_serial_device(uint8_t serialdevicenum)
|
||||
{
|
||||
monocoque_serial_device* dev = &monocoque_serial_devices[serialdevicenum];
|
||||
slogt("serial device id %i", serialdevicenum);
|
||||
monocoque_serial_device monocoque_serial_dev = monocoque_serial_devices[serialdevicenum];
|
||||
|
||||
slogt("port name: %s, busy %i, open %i, openfail %i", monocoque_serial_dev.portname, monocoque_serial_dev.busy, monocoque_serial_dev.open, monocoque_serial_dev.busy);
|
||||
|
||||
if(monocoque_serial_dev.port == NULL)
|
||||
slogt("port name: %s, busy %i, open %i, openfail %i", dev->portname, dev->busy, dev->open, dev->openfail);
|
||||
|
||||
if(dev->port == NULL)
|
||||
{
|
||||
sloge("port is null");
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
int monocoque_serial_write(uint8_t serialdevicenum, void* data, size_t size, int timeout)
|
||||
{
|
||||
monocoque_serial_device* dev = monocoque_get_serial_device(serialdevicenum);
|
||||
|
||||
int result = -1;
|
||||
if(monocoque_serial_dev.busy == false && monocoque_serial_dev.open == true)
|
||||
if(dev->busy == false && dev->open == true)
|
||||
{
|
||||
monocoque_serial_dev.busy = true;
|
||||
result = sp_blocking_write(monocoque_serial_dev.port, data, size, timeout);
|
||||
dev->busy = true;
|
||||
result = sp_blocking_write(dev->port, data, size, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -138,67 +148,51 @@ int monocoque_serial_write(uint8_t serialdevicenum, void* data, size_t size, int
|
||||
result = -1;
|
||||
}
|
||||
slogt("write result is %i", result);
|
||||
monocoque_serial_dev.busy = false;
|
||||
dev->busy = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
int monocoque_serial_write_block(uint8_t serialdevicenum, void* data, size_t size, int timeout)
|
||||
{
|
||||
slogt("serial device id %i", serialdevicenum);
|
||||
monocoque_serial_device monocoque_serial_dev = monocoque_serial_devices[serialdevicenum];
|
||||
|
||||
slogt("port name: %s, busy %i, open %i, openfail %i", monocoque_serial_dev.portname, monocoque_serial_dev.busy, monocoque_serial_dev.open, monocoque_serial_dev.busy);
|
||||
|
||||
if(monocoque_serial_dev.port == NULL)
|
||||
{
|
||||
sloge("port is null");
|
||||
}
|
||||
monocoque_serial_device* dev = monocoque_get_serial_device(serialdevicenum);
|
||||
|
||||
int result = -1;
|
||||
if(monocoque_serial_dev.open == true)
|
||||
if(dev->open == true)
|
||||
{
|
||||
while(monocoque_serial_dev.busy == true)
|
||||
while(dev->busy == true)
|
||||
{
|
||||
slogt("hopefully this doesn't happen long");
|
||||
continue;
|
||||
}
|
||||
|
||||
monocoque_serial_dev.busy = true;
|
||||
result = sp_blocking_write(monocoque_serial_dev.port, data, size, timeout);
|
||||
dev->busy = true;
|
||||
result = sp_blocking_write(dev->port, data, size, timeout);
|
||||
slogi("actually performed write");
|
||||
}
|
||||
|
||||
monocoque_serial_dev.busy = false;
|
||||
dev->busy = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
int monocoque_serial_read_block(uint8_t serialdevicenum, void* data, size_t size, int timeout)
|
||||
{
|
||||
slogt("serial device id %i", serialdevicenum);
|
||||
monocoque_serial_device monocoque_serial_dev = monocoque_serial_devices[serialdevicenum];
|
||||
|
||||
slogt("port name: %s, busy %i, open %i, openfail %i", monocoque_serial_dev.portname, monocoque_serial_dev.busy, monocoque_serial_dev.open, monocoque_serial_dev.busy);
|
||||
|
||||
if(monocoque_serial_dev.port == NULL)
|
||||
{
|
||||
sloge("port is null");
|
||||
}
|
||||
monocoque_serial_device* dev = monocoque_get_serial_device(serialdevicenum);
|
||||
|
||||
int result = -1;
|
||||
if(monocoque_serial_dev.open == true)
|
||||
if(dev->open == true)
|
||||
{
|
||||
while(monocoque_serial_dev.busy == true)
|
||||
while(dev->busy == true)
|
||||
{
|
||||
slogt("hopefully this doesn't happen long");
|
||||
continue;
|
||||
}
|
||||
|
||||
monocoque_serial_dev.busy = true;
|
||||
result = sp_blocking_read(monocoque_serial_dev.port, data, size, timeout);
|
||||
dev->busy = true;
|
||||
result = sp_blocking_read(dev->port, data, size, timeout);
|
||||
slogi("actually performed read");
|
||||
}
|
||||
|
||||
monocoque_serial_dev.busy = false;
|
||||
dev->busy = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "serial/arduino.h"
|
||||
#include "serial/moza.h"
|
||||
#include "serial/moza_new.h"
|
||||
#include "serial/moza_ks_pro_wheel.h"
|
||||
#include "../helper/parameters.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../slog/slog.h"
|
||||
@@ -26,6 +27,10 @@ int serial_wheel_update(SimDevice* this, SimData* simdata)
|
||||
moza_new_update(serialdevice, simdata);
|
||||
break;
|
||||
|
||||
case SERIALDEV__MOZA_KS_PRO_WHEEL:
|
||||
moza_ks_pro_wheel_update(serialdevice, simdata);
|
||||
break;
|
||||
|
||||
case SIMDEVSUBTYPE_MOZAR5:
|
||||
default:
|
||||
moza_update(serialdevice, simdata->rpms, simdata->maxrpm);
|
||||
@@ -118,8 +123,9 @@ int arduino_simwind_update(SimDevice* this, SimData* simdata)
|
||||
serialdevice->u.simwinddata.velocity = ceil(simdata->velocity*KPHTOMPH);
|
||||
|
||||
slogt("Updating arduino device speed to %i", serialdevice->u.simwinddata.velocity);
|
||||
// this can be added to the config, all config dependent can be added to init
|
||||
serialdevice->u.simwinddata.fanpower = (int)0.6 * 255;
|
||||
|
||||
serialdevice->u.simwinddata.fanpower = (int)(serialdevice->fanpower * 255);
|
||||
slogt("Sending fanpower: %i (from config: %f)", serialdevice->u.simwinddata.fanpower, serialdevice->fanpower);
|
||||
size_t size = sizeof(SimWindData);
|
||||
|
||||
arduino_update(serialdevice, &serialdevice->u.simwinddata, size);
|
||||
@@ -134,8 +140,12 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
|
||||
int result = 1;
|
||||
|
||||
slogt("arduino haptic device updating");
|
||||
serialdevice->u.simhapticdata.motor1 = 0;
|
||||
serialdevice->u.simhapticdata.motor2 = 0;
|
||||
serialdevice->u.simhapticdata.motor3 = 0;
|
||||
serialdevice->u.simhapticdata.motor4 = 0;
|
||||
|
||||
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
|
||||
double rplay = play;
|
||||
play = play * serialdevice->ampfactor;
|
||||
@@ -143,25 +153,27 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
play = 1.0;
|
||||
}
|
||||
int effectspeed = ceil(255 * play);
|
||||
uint8_t effectspeed = ceil(255 * play);
|
||||
|
||||
int motor = serialdevice->motorsposition;
|
||||
uint8_t motor = this->hapticeffect.motorposition;
|
||||
|
||||
if (play != serialdevice->state)
|
||||
if (play != serialdevice->hapticstate)
|
||||
{
|
||||
// motor 1
|
||||
if (motor == 0 || motor == 4 || motor == 7 || motor == 8 || motor == 10 || motor == 11 || motor == 13 || motor == 14)
|
||||
{
|
||||
serialdevice->u.simhapticdata.effect1 = effectspeed;
|
||||
serialdevice->u.simhapticdata.motor1 = 1;
|
||||
slogt("Updating arduino haptic device with effect type %i speed motor speed %i on motor %i from original effect %f with ampfactor %f", this->hapticeffect.effecttype, serialdevice->u.simhapticdata.effect3, serialdevice->motorsposition, rplay, serialdevice->ampfactor);
|
||||
slogt("Updating arduino haptic device with effect type %i speed motor speed %i on motor %i from original effect %f with ampfactor %f", this->hapticeffect.effecttype, serialdevice->u.simhapticdata.effect1, 1, rplay, serialdevice->ampfactor);
|
||||
}
|
||||
// motor 3
|
||||
if (motor == 2 || motor == 6 || motor == 8 || motor == 9 || motor == 10 || motor == 11 || motor == 12 || motor == 14)
|
||||
{
|
||||
serialdevice->u.simhapticdata.effect3 = effectspeed;
|
||||
serialdevice->u.simhapticdata.motor3 = 1;
|
||||
slogt("Updating arduino haptic device with effect type %i speed motor speed %i on motor %i from original effect %f with ampfactor %f", this->hapticeffect.effecttype, serialdevice->u.simhapticdata.effect3, serialdevice->motorsposition, rplay, serialdevice->ampfactor);
|
||||
slogt("Updating arduino haptic device with effect type %i speed motor speed %i on motor %i from original effect %f with ampfactor %f", this->hapticeffect.effecttype, serialdevice->u.simhapticdata.effect3, 3, rplay, serialdevice->ampfactor);
|
||||
}
|
||||
serialdevice->state = play;
|
||||
serialdevice->hapticstate = play;
|
||||
}
|
||||
|
||||
size_t size = sizeof(SimHapticData);
|
||||
@@ -185,7 +197,7 @@ int serialdev_free(SimDevice* this)
|
||||
serialdevice->u.simhapticdata.motor3 = 1;
|
||||
serialdevice->u.simhapticdata.effect4 = 0;
|
||||
serialdevice->u.simhapticdata.motor4 = 1;
|
||||
serialdevice->state = 0;
|
||||
serialdevice->hapticstate = 0;
|
||||
|
||||
size_t size = sizeof(SimHapticData);
|
||||
monocoque_serial_write_block(serialdevice->id, &serialdevice->u.simhapticdata, size, 9000);
|
||||
@@ -219,7 +231,7 @@ int serial_wheel_free(SimDevice* this)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
||||
int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds, SimInfo* siminfo)
|
||||
{
|
||||
slogi("initializing serial device on port %s to %i...", ds->serialdevsettings.portdev, ds->serialdevsettings.baud);
|
||||
int error = 0;
|
||||
@@ -239,6 +251,9 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
||||
case SERIALDEV__MOZA_NEW:
|
||||
error = moza_new_init(serialdevice, ds->serialdevsettings.portdev);
|
||||
break;
|
||||
case SERIALDEV__MOZA_KS_PRO_WHEEL:
|
||||
error = moza_ks_pro_wheel_init(serialdevice, ds->serialdevsettings.portdev);
|
||||
break;
|
||||
case ARDUINODEV__SIMLED__CUSTOM:
|
||||
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||
error = arduino_custom_init(serialdevice, ds->serialdevsettings.portdev, serialdevice->m.device_specific_config_file, true);
|
||||
@@ -276,7 +291,7 @@ static const vtable arduino_simwind_vtable = { &arduino_simwind_update, &seriald
|
||||
static const vtable arduino_simhaptic_vtable = { &arduino_simhaptic_update, &serialdev_free };
|
||||
static const vtable serialwheel_vtable = { &serial_wheel_update, &serial_wheel_free };
|
||||
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo) {
|
||||
|
||||
SerialDevice* this = (SerialDevice*) malloc(sizeof(SerialDevice));
|
||||
|
||||
@@ -285,6 +300,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
this->m.derived = this;
|
||||
this->m.vtable = &serial_simdevice_vtable;
|
||||
this->type = SERIALDEV_ARDUINO;
|
||||
int error = 0;
|
||||
|
||||
slogt("Attempting to configure arduino device with subtype: %i", ds->dev_subtype);
|
||||
switch (ds->dev_subtype) {
|
||||
@@ -317,7 +333,8 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
case (SIMDEVTYPE_SIMWIND):
|
||||
this->devicetype = ARDUINODEV__SIMWIND;
|
||||
this->m.vtable = &arduino_simwind_vtable;
|
||||
slogi("Initializing arduino devices for sim wind.");
|
||||
this->fanpower = ds->serialdevsettings.fanpower;
|
||||
slogi("Initializing arduino devices for sim wind with fanpower: %f", this->fanpower);
|
||||
break;
|
||||
case (SIMDEVTYPE_ARDUINOCUSTOM):
|
||||
this->devicetype = ARDUINODEV__CUSTOM;
|
||||
@@ -325,6 +342,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
slogi("Initializing custom arduino device.");
|
||||
break;
|
||||
case (SIMDEVTYPE_SERIALHAPTIC):
|
||||
if(siminfo->SimSupportsHapticEffects == false)
|
||||
{
|
||||
error = MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE;
|
||||
}
|
||||
this->devicetype = ARDUINODEV__HAPTIC;
|
||||
this->m.vtable = &arduino_simhaptic_vtable;
|
||||
this->u.simhapticdata.motor1 = 0;
|
||||
@@ -335,8 +356,9 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
this->u.simhapticdata.effect2 = 0;
|
||||
this->u.simhapticdata.effect3 = 0;
|
||||
this->u.simhapticdata.effect4 = 0;
|
||||
this->state = 0;
|
||||
this->hapticstate = 0;
|
||||
this->ampfactor = ds->serialdevsettings.ampfactor;
|
||||
this->fanpower = ds->serialdevsettings.fanpower;
|
||||
slogi("Initializing arduino device for haptic effects.");
|
||||
break;
|
||||
case (SIMDEVTYPE_SERIALWHEEL):
|
||||
@@ -349,6 +371,11 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
this->devicetype = SERIALDEV__MOZA_NEW;
|
||||
this->m.vtable = &serialwheel_vtable;
|
||||
break;
|
||||
case SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL:
|
||||
slogi("Initializing new firmware Moza serial wheel device.");
|
||||
this->devicetype = SERIALDEV__MOZA_KS_PRO_WHEEL;
|
||||
this->m.vtable = &serialwheel_vtable;
|
||||
break;
|
||||
case SIMDEVSUBTYPE_MOZAR5:
|
||||
default:
|
||||
//move this stuff to wheeldevice or it's own serial wheel device module
|
||||
@@ -359,21 +386,26 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
}
|
||||
}
|
||||
|
||||
if(this->devicetype == ARDUINODEV__HAPTIC)
|
||||
if(this->devicetype == ARDUINODEV__HAPTIC && error == 0)
|
||||
{
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.hapticeffect.effecttype = ds->effect_type;
|
||||
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.threshold = ds->hapticsettings.threshold;
|
||||
this->m.hapticeffect.effecttype = ds->hapticsettings.effect_type;
|
||||
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->hapticsettings.effect_type);
|
||||
this->m.hapticeffect.tyre = ds->hapticsettings.tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
}
|
||||
|
||||
int error = serialdev_init(this, ds);
|
||||
|
||||
if (error < 0)
|
||||
if(error == 0)
|
||||
{
|
||||
slogi("Starting serial device initialization");
|
||||
error = serialdev_init(this, ds, siminfo);
|
||||
}
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
slogw("Did not initialize serial device due to error code %i", error);
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ typedef enum
|
||||
ARDUINODEV__SIMLED = 4,
|
||||
ARDUINODEV__SIMLED__CUSTOM = 5,
|
||||
ARDUINODEV__CUSTOM = 6,
|
||||
SERIALDEV__MOZA_NEW = 7
|
||||
SERIALDEV__MOZA_NEW = 7,
|
||||
SERIALDEV__MOZA_KS_PRO_WHEEL = 8
|
||||
}
|
||||
SerialDeviceType;
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ int devupdate(SimDevice* this, SimData* simdata)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, MonocoqueSettings* ms)
|
||||
int devinit(SimDevice* simdevices, SimInfo* siminfo, int numdevices, DeviceSettings* ds, MonocoqueSettings* ms)
|
||||
{
|
||||
slogi("initializing simdevices...");
|
||||
slogi("initializing simdevices for simapi %i...", siminfo->simulatorapi);
|
||||
int devices = 0;
|
||||
|
||||
for (int j = 0; j < numdevices; j++)
|
||||
@@ -34,7 +34,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
||||
simdevices[j].initialized = false;
|
||||
|
||||
if (ds[j].dev_type == SIMDEV_USB) {
|
||||
USBDevice* sim = new_usb_device(&ds[j], ms);
|
||||
USBDevice* sim = new_usb_device(&ds[j], ms, siminfo);
|
||||
if (sim != NULL)
|
||||
{
|
||||
simdevices[j] = sim->m;
|
||||
@@ -56,7 +56,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
||||
}
|
||||
else
|
||||
{
|
||||
SoundDevice* sim = new_sound_device(&ds[j], ms);
|
||||
SoundDevice* sim = new_sound_device(&ds[j], ms, siminfo);
|
||||
if (sim != NULL)
|
||||
{
|
||||
|
||||
@@ -75,7 +75,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
||||
|
||||
if (ds[j].dev_type == SIMDEV_SERIAL) {
|
||||
|
||||
SerialDevice* sim = new_serial_device(&ds[j], ms);
|
||||
SerialDevice* sim = new_serial_device(&ds[j], ms, siminfo);
|
||||
if (sim != NULL)
|
||||
{
|
||||
simdevices[j] = sim->m;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include <lua.h>
|
||||
|
||||
#include "usbdevice.h"
|
||||
#include "sounddevice.h"
|
||||
@@ -66,7 +66,8 @@ typedef struct
|
||||
int endled;
|
||||
int baudrate;
|
||||
double ampfactor;
|
||||
double state;
|
||||
double fanpower;
|
||||
double hapticstate;
|
||||
union
|
||||
{
|
||||
SimWindData simwinddata;
|
||||
@@ -82,15 +83,15 @@ int arduino_simwind_update(SimDevice* this, SimData* simdata);
|
||||
int arduino_simhaptic_update(SimDevice* this, SimData* simdata);
|
||||
int serialdev_free(SimDevice* this);
|
||||
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo);
|
||||
|
||||
/********* USB HID Devices *****/
|
||||
typedef enum
|
||||
{
|
||||
USBDEV_UNKNOWN = 0,
|
||||
USBDEV_TACHOMETER = 1,
|
||||
USBDEV_GENERICHAPTIC = 2,
|
||||
USBDEV_WHEEL = 3
|
||||
USBDEV_UNKNOWN = 0,
|
||||
USBDEV_TACHOMETER = 1,
|
||||
USBDEV_GENERICHAPTIC = 2,
|
||||
USBDEV_WHEEL_OR_PEDALS = 3
|
||||
}
|
||||
USBType;
|
||||
|
||||
@@ -99,12 +100,14 @@ typedef struct
|
||||
SimDevice m;
|
||||
int id;
|
||||
hid_device* handle;
|
||||
FILE* filehandle;
|
||||
char* dev;
|
||||
double hapticstate;
|
||||
USBType type;
|
||||
union
|
||||
{
|
||||
TachDevice tachdevice;
|
||||
WheelDevice wheeldevice;
|
||||
USBGenericHapticDevice hapticdevice;
|
||||
} u;
|
||||
}
|
||||
USBDevice;
|
||||
@@ -112,7 +115,7 @@ USBDevice;
|
||||
int usbdev_update(SimDevice* this, SimData* simdata);
|
||||
int usbdev_free(SimDevice* this);
|
||||
|
||||
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo);
|
||||
|
||||
|
||||
/********* Sound Devices *****/
|
||||
@@ -121,7 +124,6 @@ typedef struct
|
||||
SimDevice m;
|
||||
int id;
|
||||
int configcheck;
|
||||
SoundEffectModulationType modulationType;
|
||||
SoundData sounddata;
|
||||
//#ifdef USE_PULSEAUDIO
|
||||
pa_stream *stream;
|
||||
@@ -137,7 +139,7 @@ int sounddev_gearshift_update(SimDevice* this, SimData* simdata);
|
||||
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata);
|
||||
int sounddev_free(SimDevice* this);
|
||||
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo);
|
||||
|
||||
/***** Generic Methods *********/
|
||||
|
||||
@@ -145,7 +147,7 @@ int update(SimDevice* simdevice, SimData* simdata);
|
||||
|
||||
int devupdate(SimDevice* simdevice, SimData* simdata);
|
||||
|
||||
int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
int devinit(SimDevice* simdevices, SimInfo* siminfo, int numdevices, DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
|
||||
int devfree(SimDevice* simdevices, int numdevices);
|
||||
|
||||
@@ -153,7 +155,8 @@ int simdevfree(SimDevice* this);
|
||||
|
||||
|
||||
/****** USB SubTypes ****************/
|
||||
int wheeldev_update(USBDevice* usbdevice, SimData* simdata);
|
||||
int wheelhapticdev_update(SimDevice* this, SimData* simdata);
|
||||
int wheeldev_update(SimDevice* this, SimData* simdata);
|
||||
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds);
|
||||
int wheeldev_free(USBDevice* usbdevice);
|
||||
|
||||
|
||||
@@ -19,10 +19,8 @@ int setupsound()
|
||||
slogi("connecting pulseaudio...");
|
||||
// Get a mainloop and its context
|
||||
mainloop = pa_threaded_mainloop_new();
|
||||
assert(mainloop);
|
||||
mainloop_api = pa_threaded_mainloop_get_api(mainloop);
|
||||
context = pa_context_new(mainloop_api, "Monocoque");
|
||||
assert(context);
|
||||
|
||||
pa_context_set_state_callback(context, &context_state_cb, mainloop);
|
||||
|
||||
@@ -30,13 +28,12 @@ int setupsound()
|
||||
pa_threaded_mainloop_lock(mainloop);
|
||||
|
||||
// Start the mainloop
|
||||
assert(pa_threaded_mainloop_start(mainloop) == 0);
|
||||
assert(pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0);
|
||||
pa_threaded_mainloop_start(mainloop);
|
||||
pa_context_connect(context, NULL, 0, NULL);
|
||||
|
||||
// Wait for the context to be ready
|
||||
for(;;) {
|
||||
pa_context_state_t context_state = pa_context_get_state(context);
|
||||
assert(PA_CONTEXT_IS_GOOD(context_state));
|
||||
if (context_state == PA_CONTEXT_READY) break;
|
||||
pa_threaded_mainloop_wait(mainloop);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ int patestCallbackGearShift(const void* inputBuffer,
|
||||
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||
if (data->curr_duration >= data->duration) {
|
||||
data->curr_duration = 0.0;
|
||||
data->curr_frequency = 0;
|
||||
data->curr_frequency = 0.0;
|
||||
}
|
||||
|
||||
*out++ = sample;
|
||||
|
||||
@@ -16,6 +16,15 @@
|
||||
#define M_PI (3.14159265)
|
||||
#endif
|
||||
|
||||
static double apply_noise(double base_freq, double noise_amount) {
|
||||
if (noise_amount > 0.0) {
|
||||
double r = (double) rand() / RAND_MAX * 2.0 - 1.0;
|
||||
return base_freq + r * noise_amount;
|
||||
} else {
|
||||
return base_freq;
|
||||
}
|
||||
}
|
||||
|
||||
void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||
|
||||
SoundData* data = (SoundData*)userdata;
|
||||
@@ -24,59 +33,75 @@ void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||
|
||||
|
||||
for (size_t i = 0; i < num_samples; i++) {
|
||||
static double t = 0.0;
|
||||
double sample = 0;
|
||||
if (data->frequency>0)
|
||||
{
|
||||
sample = ((double)data->curr_amplitude/100) * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * data->curr_duration);
|
||||
}
|
||||
|
||||
double sample = 0;
|
||||
|
||||
if (data->curr_frequency>0.0)
|
||||
{
|
||||
double t = data->phase;
|
||||
double a = (double)data->curr_amplitude/100;
|
||||
|
||||
// fade-out 5ms to prevent discontinuity
|
||||
static double fade_out_duration = 0.005;
|
||||
|
||||
double remaining = data->duration - data->curr_duration;
|
||||
if (remaining < fade_out_duration) {
|
||||
a *= remaining / fade_out_duration;
|
||||
}
|
||||
|
||||
sample = a * 32767.0 * sin(2.0 * M_PI * t);
|
||||
|
||||
double f = apply_noise(data->curr_frequency, data->noise);
|
||||
|
||||
t += f / SAMPLE_RATE;
|
||||
if (t >= 1.0) {
|
||||
t -= floor(t);
|
||||
}
|
||||
|
||||
data->phase = t;
|
||||
|
||||
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||
if (data->curr_duration >= data->duration) {
|
||||
data->curr_duration = 0.0;
|
||||
data->curr_frequency = 0.0;
|
||||
data->phase = 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
buffer[i] = (int16_t)sample;
|
||||
|
||||
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||
if (data->curr_duration >= data->duration) {
|
||||
data->curr_duration = 0.0;
|
||||
data->curr_frequency = 0;
|
||||
}
|
||||
}
|
||||
pa_stream_write(s, buffer, length, NULL, 0LL, PA_SEEK_RELATIVE);
|
||||
}
|
||||
|
||||
double get_closest_frequency(size_t num_samples, double input_frequency) {
|
||||
|
||||
double samples_per_cycle = SAMPLE_RATE / input_frequency;
|
||||
|
||||
double adjusted_frequency = SAMPLE_RATE / (num_samples / floor(num_samples/samples_per_cycle) );
|
||||
|
||||
return adjusted_frequency;
|
||||
}
|
||||
|
||||
void engine_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||
|
||||
SoundData* data = (SoundData*)userdata;
|
||||
double freq = data->curr_frequency;
|
||||
|
||||
size_t num_samples = length / sizeof(int16_t);
|
||||
freq = get_closest_frequency( num_samples, freq );
|
||||
|
||||
//size_t num_samples = (size_t) (DURATION * SAMPLE_RATE);
|
||||
int16_t buffer[num_samples];
|
||||
|
||||
//double t = 0;
|
||||
for (size_t i = 0; i < num_samples; i++) {
|
||||
|
||||
double t = data->phase;
|
||||
|
||||
double sample = ((double)data->curr_amplitude/100) * 32767.0 * sin( 2.0 * M_PI * freq * t );
|
||||
double sample = ((double)data->curr_amplitude/100) * 32767.0 * sin( 2.0 * M_PI * t );
|
||||
|
||||
buffer[i] = (int16_t)sample;
|
||||
|
||||
t += 1.0 / SAMPLE_RATE;
|
||||
if (t >= SAMPLE_RATE) {
|
||||
t = 0;
|
||||
double f = apply_noise(data->curr_frequency, data->noise);
|
||||
|
||||
t += f / SAMPLE_RATE;
|
||||
if (t >= 1.0) {
|
||||
t -= floor(t);
|
||||
}
|
||||
|
||||
data->phase = t;
|
||||
}
|
||||
data->phase = round(data->phase);
|
||||
|
||||
pa_stream_write(s, buffer, length, NULL, 0LL, PA_SEEK_RELATIVE);
|
||||
}
|
||||
@@ -166,7 +191,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||
// recommended settings, i.e. server uses sensible values
|
||||
pa_buffer_attr buffer_attr;
|
||||
buffer_attr.maxlength = (uint32_t) 32767;
|
||||
buffer_attr.tlength = (uint32_t) -1;
|
||||
buffer_attr.tlength = (uint32_t) 2048;
|
||||
buffer_attr.prebuf = (uint32_t) -1;
|
||||
buffer_attr.minreq = (uint32_t) -1;
|
||||
|
||||
@@ -182,14 +207,14 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||
// for now i'm only supporting playing on one specified channel which is the concept you should build your setups around
|
||||
cv.values[pan] = channel_volume;
|
||||
|
||||
assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
|
||||
pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL);
|
||||
//pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL);
|
||||
|
||||
// Wait for the stream to be ready
|
||||
for(;;)
|
||||
{
|
||||
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
||||
assert(PA_STREAM_IS_GOOD(stream_state));
|
||||
PA_STREAM_IS_GOOD(stream_state);
|
||||
//PA_STREAM_IS_GOOD(stream_state);
|
||||
if (stream_state == PA_STREAM_READY) break;
|
||||
pa_threaded_mainloop_wait(mainloop);
|
||||
|
||||
@@ -15,42 +15,46 @@
|
||||
#include "../helper/parameters.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
||||
int gear_sound_set(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
|
||||
{
|
||||
//sounddevice->sounddata.gear_sound_data = 3.14;
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
|
||||
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
|
||||
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
sounddevice->sounddata.last_gear = simdata->gear;
|
||||
|
||||
slogt("set gear frequency to %i", sounddevice->sounddata.curr_frequency);
|
||||
slogt("set gear frequency to %f", sounddevice->sounddata.curr_frequency);
|
||||
}
|
||||
|
||||
|
||||
double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulationType modulation)
|
||||
double modulate(SimDevice* this, double raw_effect, HapticEffectModulationType modulation)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
double modulated_effect = raw_effect;
|
||||
switch (modulation)
|
||||
{
|
||||
case SOUND_EFFECT_MODULATION_FREQUENCY:
|
||||
modulated_effect = ((sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect) + sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_frequency = trunc(modulated_effect);
|
||||
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
|
||||
slogt("set curr frequency to %i from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, sounddevice->sounddata.frequency);
|
||||
case HAPTIC_EFFECT_MODULATION_FREQUENCY:
|
||||
modulated_effect = ((this->hapticeffect.frequencyMax - this->hapticeffect.basefrequency) * raw_effect) + this->hapticeffect.basefrequency;
|
||||
sounddevice->sounddata.curr_frequency = modulated_effect;
|
||||
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
|
||||
slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, this->hapticeffect.basefrequency);
|
||||
break;
|
||||
case SOUND_EFFECT_MODULATION_AMPLIFY:
|
||||
modulated_effect = ((sounddevice->sounddata.amplitudeMax - sounddevice->sounddata.amplitude) * raw_effect) + sounddevice->sounddata.amplitude;
|
||||
case HAPTIC_EFFECT_MODULATION_AMPLIFY:
|
||||
modulated_effect = ((this->hapticeffect.amplitudeMax - this->hapticeffect.baseamplitude) * raw_effect) + this->hapticeffect.baseamplitude;
|
||||
sounddevice->sounddata.curr_amplitude = modulated_effect;
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, sounddevice->sounddata.amplitude);
|
||||
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
|
||||
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, this->hapticeffect.baseamplitude);
|
||||
break;
|
||||
case SOUND_EFFECT_MODULATION_NONE:
|
||||
case HAPTIC_EFFECT_MODULATION_NONE:
|
||||
default:
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
|
||||
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
|
||||
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -64,23 +68,23 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
||||
|
||||
double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60);
|
||||
slogt("Set base effect of %f from rpms of %i", effect, simdata->rpms);
|
||||
modulate(sounddevice, effect, sounddevice->modulationType);
|
||||
modulate(this, effect, this->hapticeffect.modulationType);
|
||||
}
|
||||
|
||||
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
slogt("Updating sound device frequency from original tyre slip effect %f", effect);
|
||||
double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
slogt("Updating sound device frequency from original %i tyre slip effect %f", this->hapticeffect.effecttype, effect);
|
||||
|
||||
if (effect > 0)
|
||||
{
|
||||
modulate(sounddevice, effect, sounddevice->modulationType);
|
||||
modulate(this, effect, this->hapticeffect.modulationType);
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -91,16 +95,16 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
slogt("Updating sound device frequency from original tyre lock effect %f", play);
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
modulate(sounddevice, play, sounddevice->modulationType);
|
||||
modulate(this, play, this->hapticeffect.modulationType);
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -109,16 +113,16 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
|
||||
int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
slogt("Updating sound device frequency from original abs effect %f", play);
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
modulate(sounddevice, play, sounddevice->modulationType);
|
||||
modulate(this, play, this->hapticeffect.modulationType);
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -128,17 +132,17 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
effect = effect * 10;
|
||||
slogt("Updating sound device output from original suspension travel effect %f", effect);
|
||||
|
||||
if (effect > 0)
|
||||
{
|
||||
effect = modulate(sounddevice, effect, sounddevice->modulationType);
|
||||
effect = modulate(this, effect, this->hapticeffect.modulationType);
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
@@ -147,9 +151,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
|
||||
|
||||
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
gear_sound_set(sounddevice, simdata);
|
||||
gear_sound_set(this, simdata);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,33 +165,24 @@ int sounddev_free(SimDevice* this)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreIdentifier tyre, SoundDeviceSettings sds)
|
||||
int sounddev_init(SoundDevice* sounddevice, const char* devname, SoundDeviceSettings sds)
|
||||
{
|
||||
slogi("initializing standalone sound device...");
|
||||
|
||||
|
||||
slogi("volume is: %i", sds.volume);
|
||||
slogi("Modulation type: %i", sds.modulation);
|
||||
slogi("frequency is: %i", sds.frequency);
|
||||
slogi("frequency Max is: %i", sds.frequencyMax);
|
||||
slogi("amplitude is: %i", sds.amplitude);
|
||||
slogi("amplitude Max is: %i", sds.amplitudeMax);
|
||||
slogi("pan is: %i", sds.pan);
|
||||
slogi("channels is: %i", sds.channels);
|
||||
slogi("duration is: %f", sds.duration);
|
||||
slogi("noise is: %i", sds.noise);
|
||||
|
||||
|
||||
sounddevice->modulationType = sds.modulation;
|
||||
sounddevice->sounddata.frequency = sds.frequency;
|
||||
sounddevice->sounddata.frequencyMax = sds.frequencyMax;
|
||||
sounddevice->sounddata.amplitude = sds.amplitude;
|
||||
sounddevice->sounddata.amplitudeMax = sds.amplitudeMax;
|
||||
sounddevice->sounddata.noise = (double)sds.noise;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
|
||||
sounddevice->sounddata.phase = 0;
|
||||
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0;
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
|
||||
|
||||
const char* streamname= "Engine";
|
||||
@@ -229,88 +222,71 @@ static const vtable tyrelock_sound_simdevice_vtable = { &sounddev_tyrelock_updat
|
||||
static const vtable absbrakes_sound_simdevice_vtable = { &sounddev_absbrakes_update, &sounddev_free };
|
||||
static const vtable suspension_sound_simdevice_vtable = { &sounddev_suspension_update, &sounddev_free };
|
||||
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo) {
|
||||
|
||||
SoundDevice* this = (SoundDevice*) malloc(sizeof(SoundDevice));
|
||||
|
||||
this->m.update = &update;
|
||||
this->m.free = &simdevfree;
|
||||
this->m.derived = this;
|
||||
int error = 0;
|
||||
|
||||
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type);
|
||||
switch (ds->effect_type) {
|
||||
case (EFFECT_ENGINERPM):
|
||||
this->m.hapticeffect.effecttype = EFFECT_ENGINERPM;
|
||||
this->m.vtable = &engine_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for engine vibrations.");
|
||||
break;
|
||||
case (EFFECT_GEARSHIFT):
|
||||
this->m.hapticeffect.effecttype = EFFECT_GEARSHIFT;
|
||||
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for gear shift vibrations.");
|
||||
break;
|
||||
switch (ds->hapticsettings.effect_type)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
this->m.hapticeffect.effecttype = EFFECT_TYRESLIP;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
|
||||
this->m.vtable = &tyreslip_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre slip vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
this->m.hapticeffect.effecttype = EFFECT_TYRELOCK;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
|
||||
this->m.vtable = &tyrelock_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre slip vibrations.");
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
this->m.hapticeffect.effecttype = EFFECT_ABSBRAKES;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
|
||||
this->m.vtable = &absbrakes_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for abs vibrations.");
|
||||
break;
|
||||
|
||||
case (EFFECT_SUSPENSION):
|
||||
this->m.hapticeffect.effecttype = EFFECT_SUSPENSION;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
slogt("Haptic effect: %i %i on tyre %i", this->m.hapticeffect.effecttype, ds->effect_type, ds->tyre);
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
|
||||
this->m.vtable = &suspension_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for suspension vibrations.");
|
||||
break;
|
||||
if(siminfo->SimSupportsHapticEffects == false)
|
||||
{
|
||||
slogw("Skipping sound effect setup because sim does not support haptic effects");
|
||||
error = MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE;
|
||||
}
|
||||
defaut:
|
||||
error = 0;
|
||||
}
|
||||
|
||||
slogt("Attempting to use sound device %s", ds->sounddevsettings.dev);
|
||||
|
||||
int error = sounddev_init(this, ds->sounddevsettings.dev, ds->tyre, ds->sounddevsettings);
|
||||
if(error == 0)
|
||||
{
|
||||
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
|
||||
slogt("Attempting to configure sound device with subtype: %i", ds->hapticsettings.effect_type);
|
||||
switch (ds->hapticsettings.effect_type)
|
||||
{
|
||||
case (EFFECT_ENGINERPM):
|
||||
this->m.vtable = &engine_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for engine vibrations.");
|
||||
break;
|
||||
case (EFFECT_GEARSHIFT):
|
||||
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for gear shift vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRESLIP):
|
||||
this->m.vtable = &tyreslip_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre slip vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
this->m.vtable = &tyrelock_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre lock vibrations.");
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
this->m.vtable = &absbrakes_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for abs vibrations.");
|
||||
break;
|
||||
|
||||
case (EFFECT_SUSPENSION):
|
||||
this->m.vtable = &suspension_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for suspension vibrations.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(error == 0)
|
||||
{
|
||||
slogt("Attempting to use sound device %s", ds->sounddevsettings.dev);
|
||||
error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings);
|
||||
}
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
free(this);
|
||||
|
||||
@@ -8,28 +8,17 @@
|
||||
//#endif
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SOUND_EFFECT_MODULATION_NONE = 0,
|
||||
SOUND_EFFECT_MODULATION_FREQUENCY = 1,
|
||||
SOUND_EFFECT_MODULATION_AMPLIFY = 2,
|
||||
}
|
||||
SoundEffectModulationType;
|
||||
|
||||
#define MAX_TABLE_SIZE (6000)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t last_gear;
|
||||
int volume;
|
||||
uint32_t frequency;
|
||||
uint32_t frequencyMax;
|
||||
uint32_t amplitude;
|
||||
uint32_t amplitudeMax;
|
||||
double duration;
|
||||
uint32_t curr_frequency;
|
||||
double curr_frequency;
|
||||
uint32_t curr_amplitude;
|
||||
double curr_duration;
|
||||
double phase;
|
||||
double noise;
|
||||
}
|
||||
SoundData;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "usbhapticdevice.h"
|
||||
#include "cslelitev3.h"
|
||||
|
||||
#include "../../helper/confighelper.h"
|
||||
#include "../slog/slog.h"
|
||||
@@ -11,7 +11,7 @@
|
||||
const char* SYSFSRUMBLEPATH = "/sys/module/hid_fanatec/drivers/hid:f*/0003:0EB7:183B.*/rumble";
|
||||
|
||||
|
||||
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play)
|
||||
int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
@@ -33,26 +33,25 @@ int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, i
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fprintf(usbhapticdevice->filehandle, "%i\n", value);
|
||||
fflush(usbhapticdevice->filehandle);
|
||||
fprintf(usbdevice->filehandle, "%i\n", value);
|
||||
fflush(usbdevice->filehandle);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice)
|
||||
int cslelitev3_free(USBDevice* usbdevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
free(usbhapticdevice->dev);
|
||||
free(usbdevice->dev);
|
||||
|
||||
fflush(usbhapticdevice->filehandle);
|
||||
fclose(usbhapticdevice->filehandle);
|
||||
fflush(usbdevice->filehandle);
|
||||
fclose(usbdevice->filehandle);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
int cslelitev3_init(USBDevice* usbdevice)
|
||||
{
|
||||
slogi("initializing CSL Elite V3 Pedals...");
|
||||
|
||||
@@ -75,7 +74,7 @@ int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
usbhapticdevice->dev = strdup(globlist.gl_pathv[i]);
|
||||
usbdevice->dev = strdup(globlist.gl_pathv[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -91,9 +90,9 @@ int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
return res;
|
||||
}
|
||||
|
||||
usbhapticdevice->filehandle = fopen(usbhapticdevice->dev, "w");
|
||||
usbdevice->filehandle = fopen(usbdevice->dev, "w");
|
||||
|
||||
if (!usbhapticdevice->filehandle)
|
||||
if (!usbdevice->filehandle)
|
||||
{
|
||||
sloge("Could not open pedal device...");
|
||||
return res;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef _CSLELITEV3_H
|
||||
#define _CSLELITEV3_H
|
||||
|
||||
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play);
|
||||
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice);
|
||||
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice);
|
||||
#include "../wheeldevice.h"
|
||||
#include "../simdevice.h"
|
||||
|
||||
int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play);
|
||||
int cslelitev3_init(USBDevice* usbdevice);
|
||||
int cslelitev3_free(USBDevice* usbdevice);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "usbhapticdevice.h"
|
||||
#include "simagicp1000.h"
|
||||
|
||||
#include "../../helper/confighelper.h"
|
||||
#include "../slog/slog.h"
|
||||
@@ -14,12 +14,12 @@
|
||||
const size_t SIMAGIC_P1000_BUFSIZE = 49;
|
||||
const char* SIMAGICP1000DEVSTRING = "SIMAGIC P1000 Pedals";
|
||||
|
||||
int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, size_t bufsize)
|
||||
int senddevreport(USBDevice* usbdevice, unsigned char* buf, size_t bufsize)
|
||||
{
|
||||
int res = 0;
|
||||
if (usbhapticdevice->handle)
|
||||
if (usbdevice->handle)
|
||||
{
|
||||
res = hid_send_feature_report(usbhapticdevice->handle, buf, SIMAGIC_P1000_BUFSIZE);
|
||||
res = hid_send_feature_report(usbdevice->handle, buf, SIMAGIC_P1000_BUFSIZE);
|
||||
slogd("sent %i bytes to %s", bufsize, SIMAGICP1000DEVSTRING);
|
||||
slogt("sent bytes %02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, s
|
||||
return res != bufsize;
|
||||
}
|
||||
|
||||
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play)
|
||||
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
@@ -54,17 +54,17 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
bytes[2] = 0x02;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
bytes[2] = 0x01;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
bytes[2] = 0x02;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x01;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -72,19 +72,19 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
|
||||
{
|
||||
bytes[0] = 241;
|
||||
bytes[2] = 0x01;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x02;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
|
||||
int simagicp1000_free(USBDevice* usbdevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(usbhapticdevice->handle);
|
||||
hid_close(usbdevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
return res;
|
||||
@@ -92,7 +92,7 @@ int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
|
||||
return res;
|
||||
}
|
||||
|
||||
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
int simagicp1000_init(USBDevice* usbdevice)
|
||||
{
|
||||
slogi("initializing %s...", SIMAGICP1000DEVSTRING);
|
||||
|
||||
@@ -100,9 +100,9 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
|
||||
res = hid_init();
|
||||
|
||||
usbhapticdevice->handle = hid_open(SIMAGIC_VENDOR_ID, SIMAGIC_PRODUCT_ID_P1000, NULL);
|
||||
usbdevice->handle = hid_open(SIMAGIC_VENDOR_ID, SIMAGIC_PRODUCT_ID_P1000, NULL);
|
||||
|
||||
if (!usbhapticdevice->handle)
|
||||
if (!usbdevice->handle)
|
||||
{
|
||||
sloge("Could not find attached %s", SIMAGICP1000DEVSTRING);
|
||||
res = hid_exit();
|
||||
@@ -123,7 +123,7 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
bytes[5] = 0x00;
|
||||
bytes[6] = 0x01;
|
||||
bytes[7] = 0x02;
|
||||
res = senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
res = senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
slogd("Initialization returned %i", res);
|
||||
if(res != 0)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#ifndef _SIMAGICP1000_H
|
||||
#define _SIMAGICP1000_H
|
||||
|
||||
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play);
|
||||
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice);
|
||||
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice);
|
||||
#include "../wheeldevice.h"
|
||||
#include "../simdevice.h"
|
||||
|
||||
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play);
|
||||
int simagicp1000_init(USBDevice* usbdevice);
|
||||
int simagicp1000_free(USBDevice* usbdevice);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "simnetpedals.h"
|
||||
|
||||
#include "../../helper/confighelper.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
#define SIMNETPEDALS_BUFSIZE 64
|
||||
|
||||
//Byte[0] : 0x01 (fixed) = Report ID
|
||||
//Byte[1] : 0x00 (fixed)
|
||||
//Byte[2] : motor number (0x01, 0x2 or 0x4)
|
||||
//Byte[3]: motor 1 frequency in hz
|
||||
//Byte[4] : motor 1 amplitude (0 to 100%)
|
||||
//Byte[5] : motor 2 frequency in hz
|
||||
//Byte[6]: motor 2 amplitude (0 to 100%)
|
||||
//Byte[7]: motor 3 frequency in hz
|
||||
//Byte[8]: motor 3 amplitude (0 to 100%)
|
||||
|
||||
|
||||
int simnetpedals_update(USBDevice* usbdevice, int effecttype, int play, int motorposition, int frequency, int amplitude)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
|
||||
unsigned char bytes[SIMNETPEDALS_BUFSIZE];
|
||||
for (int x = 0; x < SIMNETPEDALS_BUFSIZE; x++)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
}
|
||||
bytes[0] = 0x01;
|
||||
bytes[1] = 0x00;
|
||||
bytes[2] = motorposition;
|
||||
uint8_t motormultiple = motorposition - 1;
|
||||
if(motorposition == 0x04)
|
||||
{
|
||||
motormultiple = 2;
|
||||
}
|
||||
if(play > 0)
|
||||
{
|
||||
bytes[3 + (motormultiple * 2)] = frequency;
|
||||
bytes[4 + (motormultiple * 2)] = amplitude;
|
||||
}
|
||||
|
||||
|
||||
if (usbdevice->handle)
|
||||
{
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02xx%02xx%02xx%02xx%02x", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8]);
|
||||
res = hid_write(usbdevice->handle, bytes, SIMNETPEDALS_BUFSIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
slogd("no handle");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int simnetpedals_free(USBDevice* usbdevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(usbdevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int simnetpedals_init(USBDevice* usbdevice)
|
||||
{
|
||||
slogi("initializing simnet pedals...");
|
||||
|
||||
int res = 0;
|
||||
|
||||
res = hid_init();
|
||||
|
||||
usbdevice->handle = hid_open(0xcafe, 0xa301, NULL);
|
||||
|
||||
if (!usbdevice->handle)
|
||||
{
|
||||
sloge("Could not find attached Simnet Pedals");
|
||||
res = hid_exit();
|
||||
return 1;
|
||||
}
|
||||
slogd("Found Simnet Pedals handle %i...", usbdevice->handle);
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef _SIMNETPEDALS_H
|
||||
#define _SIMNETPEDALS_H
|
||||
|
||||
#include "../wheeldevice.h"
|
||||
#include "../simdevice.h"
|
||||
|
||||
int simnetpedals_update(USBDevice* usbdevice, int effecttype, int play, int motorposition, int frequency, int amplitude);
|
||||
int simnetpedals_init(USBDevice* usbdevice);
|
||||
int simnetpedals_free(USBDevice* usbdevice);
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,6 @@
|
||||
#define _CAMMUSC12_H
|
||||
|
||||
#include "../../wheeldevice.h"
|
||||
|
||||
#include "../../simdevice.h"
|
||||
|
||||
int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
|
||||
@@ -19,11 +19,9 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
||||
case USBDEV_TACHOMETER :
|
||||
tachdev_update(usbdevice, simdata);
|
||||
break;
|
||||
case USBDEV_WHEEL :
|
||||
wheeldev_update(usbdevice, simdata);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
case USBDEV_WHEEL_OR_PEDALS :
|
||||
// this should be directed via vtable to wheeldevice.c
|
||||
//wheeldev_update(usbdevice, simdata);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -41,12 +39,9 @@ int usbdev_free(SimDevice* this)
|
||||
case USBDEV_TACHOMETER :
|
||||
tachdev_free(usbdevice);
|
||||
break;
|
||||
case USBDEV_WHEEL :
|
||||
case USBDEV_WHEEL_OR_PEDALS :
|
||||
wheeldev_free(usbdevice);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
free(usbdevice);
|
||||
@@ -54,7 +49,7 @@ int usbdev_free(SimDevice* this)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||
int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds, SimInfo* siminfo)
|
||||
{
|
||||
slogi("initializing usb device...");
|
||||
int error = 0;
|
||||
@@ -66,56 +61,60 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||
case USBDEV_TACHOMETER :
|
||||
error = tachdev_init(usbdevice, ds);
|
||||
break;
|
||||
case USBDEV_WHEEL :
|
||||
case USBDEV_WHEEL_OR_PEDALS :
|
||||
error = wheeldev_init(usbdevice, ds);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static const vtable usb_simdevice_vtable = { &usbdev_update, &usbdev_free };
|
||||
|
||||
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
static const vtable usb_simdevice_vtable = { &usbdev_update, &usbdev_free };
|
||||
static const vtable usb_wheeldevice_vtable = { &wheeldev_update, &usbdev_free };
|
||||
static const vtable usb_wheelhaptic_vtable = { &wheelhapticdev_update, &usbdev_free };
|
||||
|
||||
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo) {
|
||||
|
||||
USBDevice* this = (USBDevice*) malloc(sizeof(USBDevice));
|
||||
int error = 0;
|
||||
|
||||
this->m.update = &update;
|
||||
this->m.free = &simdevfree;
|
||||
this->m.derived = this;
|
||||
this->m.vtable = &usb_simdevice_vtable;
|
||||
|
||||
|
||||
|
||||
// TODO: turn this into a switch when we get more devices
|
||||
this->type = USBDEV_TACHOMETER;
|
||||
if(ds->dev_subtype == SIMDEVTYPE_USBWHEEL)
|
||||
{
|
||||
this->type = USBDEV_WHEEL;
|
||||
this->type = USBDEV_WHEEL_OR_PEDALS;
|
||||
this->m.vtable = &usb_wheeldevice_vtable;
|
||||
}
|
||||
|
||||
|
||||
// really generic haptic isn't and shouldn't be it's own type
|
||||
// it's an attribute that is added to a device via composition
|
||||
// same if that haptic device is a serial device
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
|
||||
if(ds->has_haptic_effects == true)
|
||||
{
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.hapticeffect.effecttype = ds->effect_type;
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
this->type = USBDEV_GENERICHAPTIC;
|
||||
if(siminfo->SimSupportsHapticEffects == false)
|
||||
{
|
||||
// if the user added haptic effects to the config and the sim does not support it, but still wishes to use features
|
||||
// just remove the haptic effect from the config?
|
||||
slogi("This sim does not support haptic effects");
|
||||
error = MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
int error = 0;
|
||||
this->type = USBDEV_WHEEL_OR_PEDALS;
|
||||
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
|
||||
this->m.vtable = &usb_wheelhaptic_vtable;
|
||||
}
|
||||
}
|
||||
|
||||
int error = usbdev_init(this, ds);
|
||||
error = usbdev_init(this, ds, siminfo);
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
slogw("Did not initialize usb device due to error code %i", error);
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "hapticeffect.h"
|
||||
#include "usb/cslelitev3.h"
|
||||
#include "usb/simagicp1000.h"
|
||||
#include "usb/simnetpedals.h"
|
||||
|
||||
#include "../../helper/confighelper.h"
|
||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||
@@ -16,7 +17,7 @@
|
||||
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata, int tyre, int useconfig, int* configcheck, char* configfile)
|
||||
{
|
||||
|
||||
double play = slipeffect(simdata, usbhapticdevice->effecttype, tyre, usbhapticdevice->threshold, useconfig, configcheck, configfile);
|
||||
double play = slipeffect(simdata, this->hapticeffect.effecttype, tyre, this->hapticeffect.threshold, useconfig, configcheck, configfile);
|
||||
|
||||
if (play != usbhapticdevice->state)
|
||||
{
|
||||
@@ -27,10 +28,13 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
|
||||
switch ( usbhapticdevice->type )
|
||||
{
|
||||
case USBHAPTIC_CSLELITEV3PEDALS:
|
||||
cslelitev3_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
|
||||
cslelitev3_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case USBHAPTIC_SIMAGICP1000PEDALS:
|
||||
simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
|
||||
simagicp1000_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case USBHAPTIC_SIMNETPEDALS:
|
||||
simnetpedals_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -39,10 +43,13 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
|
||||
switch ( usbhapticdevice->type )
|
||||
{
|
||||
case USBHAPTIC_CSLELITEV3PEDALS:
|
||||
cslelitev3_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
|
||||
cslelitev3_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case USBHAPTIC_SIMAGICP1000PEDALS:
|
||||
simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
|
||||
simagicp1000_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case USBHAPTIC_SIMNETPEDALS:
|
||||
simnetpedals_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -62,33 +69,24 @@ int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
|
||||
case USBHAPTIC_SIMAGICP1000PEDALS:
|
||||
simagicp1000_free(usbhapticdevice);
|
||||
break;
|
||||
case USBHAPTIC_SIMNETPEDALS:
|
||||
simnetpedals_free(usbhapticdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* ds)
|
||||
int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* ds, SimInfo* siminfo)
|
||||
{
|
||||
int error = 0;
|
||||
usbhapticdevice->state = 0;
|
||||
usbhapticdevice->value0 = ds->usbdevsettings.value0;
|
||||
usbhapticdevice->value1 = ds->usbdevsettings.value1;
|
||||
usbhapticdevice->state = usbhapticdevice->value0;
|
||||
usbhapticdevice->effecttype = ds->effect_type;
|
||||
usbhapticdevice->threshold = ds->threshold;
|
||||
if(siminfo->SimSupportsHapticEffects == false)
|
||||
{
|
||||
slogi("This sim does not support haptic effects");
|
||||
return MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE;
|
||||
}
|
||||
|
||||
if(ds->effect_type == EFFECT_TYRESLIP)
|
||||
{
|
||||
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
|
||||
}
|
||||
if(ds->effect_type == EFFECT_TYRELOCK)
|
||||
{
|
||||
usbhapticdevice->effecttype = EFFECT_TYRELOCK;
|
||||
}
|
||||
if(ds->effect_type == EFFECT_ABSBRAKES)
|
||||
{
|
||||
usbhapticdevice->effecttype = EFFECT_ABSBRAKES;
|
||||
}
|
||||
int error = 0;
|
||||
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
|
||||
|
||||
slogi("initializing standalone usb haptic device...");
|
||||
// detection of usb device model
|
||||
@@ -101,6 +99,10 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
||||
usbhapticdevice->type = USBHAPTIC_CSLELITEV3PEDALS;
|
||||
error = cslelitev3_init(usbhapticdevice);
|
||||
break;
|
||||
case (SIMDEVSUBTYPE_SIMNETPEDALS):
|
||||
usbhapticdevice->type = USBHAPTIC_SIMNETPEDALS;
|
||||
error = simnetpedals_init(usbhapticdevice);
|
||||
break;
|
||||
default:
|
||||
slogw("Possibly unknown device");
|
||||
}
|
||||
|
||||
@@ -10,19 +10,14 @@ typedef enum
|
||||
{
|
||||
USBHAPTIC_UNKNOWN = 0,
|
||||
USBHAPTIC_CSLELITEV3PEDALS = 1,
|
||||
USBHAPTIC_SIMAGICP1000PEDALS = 2
|
||||
USBHAPTIC_SIMAGICP1000PEDALS = 2,
|
||||
USBHAPTIC_SIMNETPEDALS = 3
|
||||
}
|
||||
HapticType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
HapticType type;
|
||||
double state;
|
||||
double threshold;
|
||||
int value0;
|
||||
int value1;
|
||||
VibrationEffectType effecttype;
|
||||
FILE* filehandle;
|
||||
hid_device* handle;
|
||||
char* dev;
|
||||
@@ -31,7 +26,7 @@ USBGenericHapticDevice;
|
||||
|
||||
|
||||
int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata, int tyre, int useconfig, int* configcheck, char* configfile);
|
||||
int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds);
|
||||
int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds, SimInfo* siminfo);
|
||||
int usbhapticdev_free(USBGenericHapticDevice* hapticdevice);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,20 +2,73 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "usb/wheels/logitechg29.h"
|
||||
#include "usb/wheels/cammusc5.h"
|
||||
#include "usb/wheels/cammusc12.h"
|
||||
#include "usb/wheels/gtneo.h"
|
||||
#include "serial/moza.h"
|
||||
|
||||
|
||||
#include "usb/cslelitev3.h"
|
||||
#include "usb/simagicp1000.h"
|
||||
#include "usb/simnetpedals.h"
|
||||
|
||||
#include "simdevice.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
int wheeldev_update(USBDevice* usbdevice, SimData* simdata)
|
||||
int wheelhapticdev_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
USBDevice* usbdevice = (void *) this->derived;
|
||||
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||
|
||||
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
|
||||
if (play != usbdevice->hapticstate)
|
||||
{
|
||||
int rplay = 0;
|
||||
if(play > 0)
|
||||
{
|
||||
rplay = 1;
|
||||
switch ( wheeldevice->type )
|
||||
{
|
||||
case WHEELDEV_CSLELITEV3PEDALS:
|
||||
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case WHEELDEV_SIMAGICP1000PEDALS:
|
||||
simagicp1000_update(usbdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case WHEELDEV_SIMNETPEDALS:
|
||||
simnetpedals_update(usbdevice, this->hapticeffect.effecttype, rplay, this->hapticeffect.motorposition, this->hapticeffect.basefrequency, this->hapticeffect.baseamplitude);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( wheeldevice->type )
|
||||
{
|
||||
case WHEELDEV_CSLELITEV3PEDALS:
|
||||
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case WHEELDEV_SIMAGICP1000PEDALS:
|
||||
simagicp1000_update(usbdevice, this->hapticeffect.effecttype, rplay);
|
||||
break;
|
||||
case WHEELDEV_SIMNETPEDALS:
|
||||
simnetpedals_update(usbdevice, this->hapticeffect.effecttype, rplay, this->hapticeffect.motorposition, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
usbdevice->hapticstate = play;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wheeldev_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
USBDevice* usbdevice = (void *) this->derived;
|
||||
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||
|
||||
switch ( wheeldevice->type )
|
||||
{
|
||||
case WHEELDEV_UNKNOWN :
|
||||
@@ -72,6 +125,15 @@ int wheeldev_free(USBDevice* usbdevice)
|
||||
free(usbdevice->m.device_specific_config_file);
|
||||
}
|
||||
break;
|
||||
case WHEELDEV_CSLELITEV3PEDALS:
|
||||
cslelitev3_free(usbdevice);
|
||||
break;
|
||||
case WHEELDEV_SIMAGICP1000PEDALS:
|
||||
simagicp1000_free(usbdevice);
|
||||
break;
|
||||
case WHEELDEV_SIMNETPEDALS:
|
||||
simnetpedals_free(usbdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -79,8 +141,9 @@ int wheeldev_free(USBDevice* usbdevice)
|
||||
|
||||
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||
{
|
||||
slogi("initializing wheel device...");
|
||||
slogi("initializing wheel or pedals device...");
|
||||
int error = 0;
|
||||
usbdevice->hapticstate = 0;
|
||||
// detection of wheel model
|
||||
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||
switch (ds->dev_subsubtype) {
|
||||
@@ -138,11 +201,21 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||
error = -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
wheeldevice->type = WHEELDEV_UNKNOWN;
|
||||
slogw("Unknown cammus wheel detected, trying C5");
|
||||
error = cammusc5_init(usbdevice);
|
||||
case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS):
|
||||
wheeldevice->type = WHEELDEV_SIMAGICP1000PEDALS;
|
||||
error = simagicp1000_init(usbdevice);
|
||||
break;
|
||||
case (SIMDEVSUBTYPE_CSLELITEV3PEDALS):
|
||||
slogi("Attempting to initialize CSL Elite V3 Pedals");
|
||||
wheeldevice->type = WHEELDEV_CSLELITEV3PEDALS;
|
||||
error = cslelitev3_init(usbdevice);
|
||||
break;
|
||||
case (SIMDEVSUBTYPE_SIMNETPEDALS):
|
||||
wheeldevice->type = WHEELDEV_SIMNETPEDALS;
|
||||
error = simnetpedals_init(usbdevice);
|
||||
break;
|
||||
default:
|
||||
slogw("Possibly unknown wheel device");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WHEELDEV_UNKNOWN = 0,
|
||||
WHEELDEV_CAMMUSC5 = 1,
|
||||
WHEELDEV_CAMMUSC12 = 2,
|
||||
WHEELDEV_MOZAR5 = 3,
|
||||
WHEELDEV_SIMAGICGTNEO = 4,
|
||||
WHEELDEV_LOGITECHG29 = 5
|
||||
WHEELDEV_UNKNOWN = 0,
|
||||
WHEELDEV_CAMMUSC5 = 1,
|
||||
WHEELDEV_CAMMUSC12 = 2,
|
||||
WHEELDEV_MOZAR5 = 3,
|
||||
WHEELDEV_SIMAGICGTNEO = 4,
|
||||
WHEELDEV_LOGITECHG29 = 5,
|
||||
WHEELDEV_CSLELITEV3PEDALS = 6,
|
||||
WHEELDEV_SIMAGICP1000PEDALS = 7,
|
||||
WHEELDEV_SIMNETPEDALS = 8
|
||||
}
|
||||
WheelType;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "loopdata.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../devices/simdevice.h"
|
||||
#include "../devices/hapticeffect.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../simulatorapi/simapi/simapi/simmapper.h"
|
||||
#include "../slog/slog.h"
|
||||
@@ -28,6 +29,7 @@ uv_idle_t idler;
|
||||
uv_timer_t datachecktimer;
|
||||
uv_timer_t showstatstimer;
|
||||
uv_timer_t datamaptimer;
|
||||
uv_timer_t tyrediametertimer;
|
||||
uv_udp_t recv_socket;
|
||||
|
||||
bool doui = false;
|
||||
@@ -36,8 +38,18 @@ int appstate = 0;
|
||||
void shmdatamapcallback(uv_timer_t* handle);
|
||||
void showstatscallback(uv_timer_t* handle);
|
||||
void datacheckcallback(uv_timer_t* handle);
|
||||
void tyrediametercheckcallback(uv_timer_t* handle);
|
||||
void startdatalogger(MonocoqueSettings* ms, loop_data* l);
|
||||
|
||||
static void close_walk_cb(uv_handle_t* handle, void* arg)
|
||||
{
|
||||
if (!uv_is_closing(handle))
|
||||
{
|
||||
uv_close(handle, NULL);
|
||||
}
|
||||
}
|
||||
#define ASSERT(expr) expr
|
||||
|
||||
int showstats(SimData* simdata)
|
||||
{
|
||||
printf("\r");
|
||||
@@ -215,26 +227,67 @@ void devicetimercallback(uv_timer_t* handle)
|
||||
SimData* simdata = f->simdata;
|
||||
SimDevice* device = f->simdevice;
|
||||
device->update(device, simdata);
|
||||
}
|
||||
|
||||
|
||||
void tyrediametercheckcallback(uv_timer_t* handle)
|
||||
{
|
||||
void* b = uv_handle_get_data((uv_handle_t*) handle);
|
||||
device_loop_data* f = (device_loop_data*) b;
|
||||
SimData* simdata = f->simdata;
|
||||
|
||||
if(simdata->car != NULL || simdata->car[0] != 0)
|
||||
{
|
||||
slogi("car is %s", simdata->car);
|
||||
// check for saved tyre diameter in config file
|
||||
// if not saved version exists get tyre diameter and save it
|
||||
// use config check variable to track if the config check has been performed
|
||||
// avoid many opens of the same file
|
||||
int error = 0;
|
||||
if(hasTyreDiameter(simdata)==false && f->ms->configcheck == 0)
|
||||
{
|
||||
slogi("attempting load of tyre diameter config");
|
||||
error = loadtyreconfig(simdata, f->ms->tyre_diameter_config, true);
|
||||
f->ms->configcheck = 1;
|
||||
}
|
||||
|
||||
if(hasTyreDiameter(simdata)==false)
|
||||
{
|
||||
slogt("could not find tyre diameter in config file, attempting to calculate new");
|
||||
getTyreDiameter(simdata);
|
||||
// if this successfully calculates data the diameters will be saved to the file after the
|
||||
// sim stops actively mapping data
|
||||
}
|
||||
}
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
int a = loadtyreconfig(simdata, f->ms->tyre_diameter_config, false);
|
||||
if(a < 0)
|
||||
{
|
||||
slogi("saving new tyre diameter config for car %s");
|
||||
savetyreconfig(simdata, f->ms->tyre_diameter_config);
|
||||
}
|
||||
uv_timer_stop(handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||
{
|
||||
|
||||
if (doui == true)
|
||||
{
|
||||
slogi("looking for ui config %s pass 1", ms->config_str);
|
||||
int confignum = getconfigtouse2(ms->config_str, simdata->car, f->sim);
|
||||
slogi("looking for ui config %s pass 1 simapi %i", ms->config_str, f->siminfo.simulatorapi);
|
||||
int confignum = getconfigtouse2(ms->config_str, simdata->car, f->siminfo.simulatorapi);
|
||||
slogi("first pass finished");
|
||||
if(confignum == -1)
|
||||
{
|
||||
slogi("looking for ui config %s pass 2", ms->config_str);
|
||||
confignum = getconfigtouse1(ms->config_str, simdata->car, f->sim);
|
||||
confignum = getconfigtouse1(ms->config_str, simdata->car, f->siminfo.simulatorapi);
|
||||
}
|
||||
if(confignum == -1)
|
||||
{
|
||||
slogi("looking for ui config %s pass 3", ms->config_str);
|
||||
confignum = getconfigtouse(ms->config_str, simdata->car, f->sim);
|
||||
confignum = getconfigtouse(ms->config_str, simdata->car, f->siminfo.simulatorapi);
|
||||
}
|
||||
|
||||
int configureddevices;
|
||||
@@ -249,7 +302,8 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||
}
|
||||
|
||||
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
|
||||
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
|
||||
int initdevices = devinit(f->simdevices, &f->siminfo, configureddevices, ds, ms);
|
||||
slogi("initialized %i devices", initdevices);
|
||||
|
||||
for( int i = 0; i < configureddevices; i++)
|
||||
{
|
||||
@@ -261,6 +315,7 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||
SimDevice* devices = f->simdevices;
|
||||
f->device_timers = (uv_timer_t*) (malloc(uv_handle_size(UV_TIMER) * numdevices));
|
||||
f->device_batons = (device_loop_data*) (malloc(sizeof(device_loop_data) * numdevices));
|
||||
f->started_tyre_calc_thread = false;
|
||||
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
@@ -275,10 +330,26 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||
int interval = 1000/devices[x].fps;
|
||||
uv_timer_start(dt, devicetimercallback, 0, interval);
|
||||
slogi("starting device type %i at id at %i fps: %i (%i ms ticks)", devices[x].type, x, devices[x].fps, interval);
|
||||
}
|
||||
else
|
||||
{
|
||||
slogw("skipped id %i", x);
|
||||
|
||||
SimInfo siminfo = f->siminfo;
|
||||
if(f->started_tyre_calc_thread == false)
|
||||
{
|
||||
if(devices[x].hapticeffect.effecttype == EFFECT_TYRELOCK || devices[x].hapticeffect.effecttype == EFFECT_TYRESLIP || devices[x].hapticeffect.effecttype == EFFECT_ABSBRAKES)
|
||||
{
|
||||
if(siminfo.SimCalculatesTyreDiameter == false && siminfo.SimSupportsHapticEffects == true && siminfo.SimCalculatesSlipRatio == false && f->ms->useconfig == 1 && f->ms->tyre_diameter_config != NULL)
|
||||
{
|
||||
slogi("Starting thread to calculate tyre diameters and save to config file");
|
||||
f->started_tyre_calc_thread = true;
|
||||
|
||||
f->tyrebaton = (device_loop_data*) malloc(sizeof(device_loop_data));
|
||||
f->tyrebaton->simdata = simdata;
|
||||
f->tyrebaton->ms = f->ms;
|
||||
|
||||
uv_handle_set_data((uv_handle_t*) &tyrediametertimer, (void*) f->tyrebaton);
|
||||
uv_timer_start(&tyrediametertimer, tyrediametercheckcallback, 0, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,19 +357,6 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||
uv_timer_start(&showstatstimer, showstatscallback, 0, 100);
|
||||
doui = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//showstats(simdata);
|
||||
//SimDevice* devices = f->simdevices;
|
||||
//int numdevices = f->numdevices;
|
||||
//for (int x = 0; x < numdevices; x++)
|
||||
//{
|
||||
// if (devices[x].initialized == true && devices[x].type == 2)
|
||||
// {
|
||||
// devices[x].update(&devices[x], simdata);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
void showstatscallback(uv_timer_t* handle)
|
||||
@@ -314,14 +372,30 @@ void showstatscallback(uv_timer_t* handle)
|
||||
|
||||
void releaseloop(loop_data* f, SimData* simdata, SimMap* simmap)
|
||||
{
|
||||
|
||||
slogi("release loop");
|
||||
if(f->releasing == false)
|
||||
{
|
||||
f->releasing = true;
|
||||
uv_udp_recv_stop(&recv_socket);
|
||||
uv_timer_stop(&datamaptimer);
|
||||
uv_timer_stop(&showstatstimer);
|
||||
if (uv_is_active((uv_handle_t*)&recv_socket))
|
||||
{
|
||||
uv_udp_recv_stop(&recv_socket);
|
||||
}
|
||||
// Close the socket handle so it can be reinitialized with a different port
|
||||
//if (!uv_is_closing((uv_handle_t*)&recv_socket))
|
||||
//{
|
||||
// uv_close((uv_handle_t*)&recv_socket, NULL);
|
||||
//}
|
||||
slogi("releasing devices, please wait");
|
||||
|
||||
//attempt tyre diameter saving
|
||||
uv_timer_stop(&tyrediametertimer);
|
||||
if(f->started_tyre_calc_thread == true)
|
||||
{
|
||||
free(f->tyrebaton);
|
||||
}
|
||||
|
||||
f->uion = false;
|
||||
SimDevice* devices = f->simdevices;
|
||||
int numdevices = f->numdevices;
|
||||
@@ -362,7 +436,7 @@ void releaseloop(loop_data* f, SimData* simdata, SimMap* simmap)
|
||||
}
|
||||
free(devices);
|
||||
|
||||
int r = simfree(simdata, simmap, f->map);
|
||||
int r = simapi_sim_clear(simdata, simmap, false);
|
||||
slogd("simfree returned %i", r);
|
||||
f->numdevices = 0;
|
||||
slogi("stopped mapping data, press q again to quit");
|
||||
@@ -371,7 +445,8 @@ void releaseloop(loop_data* f, SimData* simdata, SimMap* simmap)
|
||||
|
||||
if(appstate > 0)
|
||||
{
|
||||
uv_timer_start(&datachecktimer, datacheckcallback, 3000, 1000);
|
||||
slogi("restarting checking for data...");
|
||||
uv_timer_start(&datachecktimer, datacheckcallback, 0, 1000);
|
||||
}
|
||||
f->releasing = false;
|
||||
if(appstate > 1)
|
||||
@@ -391,11 +466,11 @@ void shmdatamapcallback(uv_timer_t* handle)
|
||||
//appstate = 2;
|
||||
if (appstate == 2)
|
||||
{
|
||||
simdatamap(simdata, simmap, NULL, f->map, false, NULL);
|
||||
simapi_datamap(simdata, simmap, f->siminfo.mapapi, false, NULL);
|
||||
looprun(ms, f, simdata);
|
||||
}
|
||||
|
||||
if (f->simstate == false || simdata->simstatus <= 1 || appstate <= 1)
|
||||
if (f->siminfo.isSimOn == false || simdata->simstatus <= 1 || appstate <= 1)
|
||||
{
|
||||
releaseloop(f, simdata, simmap);
|
||||
}
|
||||
@@ -428,11 +503,11 @@ static void on_udp_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
|
||||
|
||||
if (appstate == 2)
|
||||
{
|
||||
simdatamap(simdata, simmap, NULL, f->map, true, a);
|
||||
simapi_datamap(simdata, simmap, f->siminfo.mapapi, true, a);
|
||||
looprun(ms, f, simdata);
|
||||
}
|
||||
|
||||
if (f->simstate == false || simdata->simstatus <= 1 || appstate <= 1)
|
||||
if (f->siminfo.isSimOn == false || simdata->simstatus <= 1 || appstate <= 1)
|
||||
{
|
||||
releaseloop(f, simdata, simmap);
|
||||
}
|
||||
@@ -443,7 +518,7 @@ static void on_udp_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
|
||||
|
||||
int startudp(int port)
|
||||
{
|
||||
uv_udp_init(uv_default_loop(), &recv_socket);
|
||||
|
||||
struct sockaddr_in recv_addr;
|
||||
uv_ip4_addr("0.0.0.0", port, &recv_addr);
|
||||
int err = uv_udp_bind(&recv_socket, (const struct sockaddr *) &recv_addr, UV_UDP_REUSEADDR);
|
||||
@@ -456,8 +531,7 @@ void udpstart(MonocoqueSettings* sms, loop_data* f, SimData* simdata, SimMap* si
|
||||
{
|
||||
if (appstate == 2)
|
||||
{
|
||||
fprintf(stderr, "udpstart\n");
|
||||
simdatamap(simdata, simmap, NULL, f->sim, true, NULL);
|
||||
simapi_datamap(simdata, simmap, f->siminfo.simulatorapi, true, NULL);
|
||||
if (doui == true)
|
||||
{
|
||||
looprun(sms, f, simdata);
|
||||
@@ -474,19 +548,14 @@ void datacheckcallback(uv_timer_t* handle)
|
||||
|
||||
if ( appstate == 1 )
|
||||
{
|
||||
SimInfo si = getSim(simdata, simmap, f->ms->force_udp_mode, startudp, false);
|
||||
//TODO: move all this to a siminfo struct in loop_data
|
||||
f->simstate = si.isSimOn;
|
||||
f->sim = si.simulatorapi;
|
||||
f->map = si.mapapi;
|
||||
f->use_udp = si.SimUsesUDP;
|
||||
f->siminfo = simapi_get_sim(simdata, simmap, f->ms->force_udp_mode, startudp, false);
|
||||
|
||||
if(f->ms->force_udp_mode == true)
|
||||
{
|
||||
f->use_udp = true;
|
||||
}
|
||||
}
|
||||
if (f->simstate == true && simdata->simstatus >= 2)
|
||||
if (f->siminfo.isSimOn == true && simdata->simstatus >= 2)
|
||||
{
|
||||
if ( appstate == 1 )
|
||||
{
|
||||
@@ -497,7 +566,7 @@ void datacheckcallback(uv_timer_t* handle)
|
||||
simdata->tyrediameter[2] = -1;
|
||||
simdata->tyrediameter[3] = -1;
|
||||
|
||||
if(f->use_udp == true)
|
||||
if(f->use_udp == true || f->siminfo.SimUsesUDP == true)
|
||||
{
|
||||
slogt("starting udp receive loop");
|
||||
udpstart(f->ms, f, simdata, simmap);
|
||||
@@ -510,12 +579,11 @@ void datacheckcallback(uv_timer_t* handle)
|
||||
slogd("starting telemetry mapping at %i fps (%i ms ticks)", f->ms->fps, interval);
|
||||
uv_timer_start(&datamaptimer, shmdatamapcallback, 2000, interval);
|
||||
}
|
||||
//uv_timer_stop(handle);
|
||||
}
|
||||
if(appstate == 2)
|
||||
{
|
||||
SimInfo si = getSim(simdata, simmap, f->ms->force_udp_mode, NULL, false);
|
||||
if(si.isSimOn == false)
|
||||
f->siminfo = simapi_get_sim(simdata, simmap, f->ms->force_udp_mode, NULL, false);
|
||||
if(f->siminfo.isSimOn == false)
|
||||
{
|
||||
appstate = 1;
|
||||
releaseloop(f, simdata, simmap);
|
||||
@@ -525,7 +593,7 @@ void datacheckcallback(uv_timer_t* handle)
|
||||
|
||||
if (appstate == 0)
|
||||
{
|
||||
slogi("stopping checking for data");
|
||||
slogi("stopped checking for data");
|
||||
uv_timer_stop(handle);
|
||||
}
|
||||
}
|
||||
@@ -550,6 +618,10 @@ void cb(uv_poll_t* handle, int status, int events)
|
||||
if (appstate == 0)
|
||||
{
|
||||
slogi("Monocoque is exiting...");
|
||||
uv_udp_recv_stop(&recv_socket);
|
||||
uv_timer_stop(&datamaptimer);
|
||||
uv_timer_stop(&showstatstimer);
|
||||
// at this point these below should be the only active threads
|
||||
uv_timer_stop(&datachecktimer);
|
||||
uv_poll_stop(handle);
|
||||
}
|
||||
@@ -561,7 +633,7 @@ int monocoque_mainloop(MonocoqueSettings* ms)
|
||||
{
|
||||
|
||||
SimData* simdata = malloc(sizeof(SimData));
|
||||
SimMap* simmap = createSimMap();
|
||||
SimMap* simmap = simapi_simmap_create();
|
||||
|
||||
struct termios newsettings, canonicalmode;
|
||||
tcgetattr(0, &canonicalmode);
|
||||
@@ -579,48 +651,57 @@ int monocoque_mainloop(MonocoqueSettings* ms)
|
||||
baton->simmap = simmap;
|
||||
baton->simdata = simdata;
|
||||
baton->ms = ms;
|
||||
baton->simstate = false;
|
||||
baton->uion = false;
|
||||
baton->releasing = false;
|
||||
baton->sim = 0;
|
||||
baton->use_udp = false;
|
||||
baton->req.data = (void*) baton;
|
||||
uv_handle_set_data((uv_handle_t*) &datachecktimer, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) &datamaptimer, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) &showstatstimer, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) &recv_socket, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) poll, (void*) baton);
|
||||
appstate = 1;
|
||||
slogd("setting initial app state");
|
||||
uv_timer_init(uv_default_loop(), &datachecktimer);
|
||||
uv_timer_init(uv_default_loop(), &showstatstimer);
|
||||
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||
uv_timer_start(&datachecktimer, datacheckcallback, 1000, 1000);
|
||||
|
||||
set_simapi_log_info(simapilib_loginfo);
|
||||
set_simapi_log_debug(simapilib_logdebug);
|
||||
set_simapi_log_trace(simapilib_logtrace);
|
||||
|
||||
simapi_set_log_info(simapilib_loginfo);
|
||||
simapi_set_log_debug(simapilib_logdebug);
|
||||
simapi_set_log_trace(simapilib_logtrace);
|
||||
|
||||
if (0 != uv_poll_init(uv_default_loop(), poll, 0))
|
||||
{
|
||||
return 1;
|
||||
};
|
||||
|
||||
uv_udp_init(uv_default_loop(), &recv_socket);
|
||||
uv_timer_init(uv_default_loop(), &datachecktimer);
|
||||
uv_timer_init(uv_default_loop(), &showstatstimer);
|
||||
uv_timer_init(uv_default_loop(), &datamaptimer);
|
||||
uv_timer_init(uv_default_loop(), &tyrediametertimer);
|
||||
slogd("setting initial app state");
|
||||
appstate = 1;
|
||||
|
||||
uv_handle_set_data((uv_handle_t*) &datachecktimer, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) &datamaptimer, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) &showstatstimer, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) &recv_socket, (void*) baton);
|
||||
uv_handle_set_data((uv_handle_t*) poll, (void*) baton);
|
||||
|
||||
if (0 != uv_poll_start(poll, UV_READABLE, cb))
|
||||
{
|
||||
return 2;
|
||||
};
|
||||
uv_timer_start(&datachecktimer, datacheckcallback, 1000, 1000);
|
||||
|
||||
|
||||
uv_timer_init(uv_default_loop(), &datamaptimer);
|
||||
|
||||
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
|
||||
uv_stop(uv_default_loop());
|
||||
//uv_walk(uv_default_loop(), close_walk_cb, NULL);
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
uv_loop_close(uv_default_loop());
|
||||
uv_library_shutdown();
|
||||
slogi("All threads stopped...");
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||
|
||||
free(baton);
|
||||
free(simdata);
|
||||
freesimmap(simmap, false);
|
||||
free(simmap);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -656,11 +737,43 @@ int tester(SimDevice* devices, int numdevices)
|
||||
simdata->tyrediameter[1] = -1;
|
||||
simdata->tyrediameter[2] = -1;
|
||||
simdata->tyrediameter[3] = -1;
|
||||
simdata->tyreslipratio[0] = 0;
|
||||
simdata->tyreslipratio[1] = 0;
|
||||
simdata->tyreslipratio[2] = 0;
|
||||
simdata->tyreslipratio[3] = 0;
|
||||
simdata->Xvelocity = 0;
|
||||
simdata->Yvelocity = 100;
|
||||
simdata->Zvelocity = 0;
|
||||
|
||||
sleep(3);
|
||||
sleep(1);
|
||||
|
||||
fprintf(stdout, "Revving rpm from 1000 to 8000 and back\n");
|
||||
// TODO: look into this, my serial leds make this hang
|
||||
for (int r = 0; r < 8000; r += 3)
|
||||
{
|
||||
simdata->rpms = 1000 + r;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
for (int r = 0; r < 8000; r += 3)
|
||||
{
|
||||
simdata->rpms = 9000 - r;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
fprintf(stdout, "Setting rpms to 1000\n");
|
||||
simdata->rpms = 1000;
|
||||
|
||||
@@ -10,27 +10,33 @@
|
||||
|
||||
typedef struct device_loop_data
|
||||
{
|
||||
// these are all pointers to pointers and freed independently, usually in releaseloop
|
||||
uv_work_t req;
|
||||
SimData* simdata;
|
||||
SimDevice* simdevice;
|
||||
MonocoqueSettings* ms;
|
||||
SimInfo siminfo;
|
||||
} device_loop_data;
|
||||
|
||||
typedef struct loop_data
|
||||
{
|
||||
uv_work_t req;
|
||||
SimulatorAPI sim;
|
||||
SimulatorAPI map;
|
||||
bool use_udp;
|
||||
bool simstate;
|
||||
bool uion;
|
||||
bool releasing;
|
||||
bool started_tyre_calc_thread;
|
||||
int numdevices;
|
||||
SimInfo siminfo;
|
||||
// monocoque settings is a pointer from monocoque.c and freed there
|
||||
MonocoqueSettings* ms;
|
||||
// these are freed at the end of the main gameloop
|
||||
SimData* simdata;
|
||||
SimMap* simmap;
|
||||
// these all get malloced in looprun and freed in releaseloop
|
||||
SimDevice* simdevices;
|
||||
uv_timer_t* device_timers;
|
||||
device_loop_data* device_batons;
|
||||
device_loop_data* tyrebaton;
|
||||
} loop_data;
|
||||
|
||||
|
||||
|
||||
+156
-113
@@ -37,35 +37,35 @@ int strtoeffecttype(const char* effect, DeviceSettings* ds)
|
||||
if (strcicmp(effect, "Engine") == 0)
|
||||
{
|
||||
ds->is_valid = true;
|
||||
ds->effect_type = EFFECT_ENGINERPM;
|
||||
ds->hapticsettings.effect_type = EFFECT_ENGINERPM;
|
||||
}
|
||||
if (strcicmp(effect, "Gear") == 0)
|
||||
{
|
||||
ds->is_valid = true;
|
||||
ds->effect_type = EFFECT_GEARSHIFT;
|
||||
ds->hapticsettings.effect_type = EFFECT_GEARSHIFT;
|
||||
}
|
||||
if (strcicmp(effect, "Suspension") == 0)
|
||||
{
|
||||
ds->is_valid = true;
|
||||
ds->effect_type = EFFECT_SUSPENSION;
|
||||
ds->hapticsettings.effect_type = EFFECT_SUSPENSION;
|
||||
}
|
||||
if (strcicmp(effect, "ABS") == 0)
|
||||
{
|
||||
ds->is_valid = true;
|
||||
slogt("found abas effect set");
|
||||
ds->effect_type = EFFECT_ABSBRAKES;
|
||||
ds->hapticsettings.effect_type = EFFECT_ABSBRAKES;
|
||||
}
|
||||
if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0))
|
||||
{
|
||||
ds->is_valid = true;
|
||||
slogt("found tyreslip effect set");
|
||||
ds->effect_type = EFFECT_TYRESLIP;
|
||||
ds->hapticsettings.effect_type = EFFECT_TYRESLIP;
|
||||
}
|
||||
if ((strcicmp(effect, "LOCK") == 0) || (strcicmp(effect, "TYRELOCK") == 0) || (strcicmp(effect, "TIRELOCK") == 0))
|
||||
{
|
||||
ds->is_valid = true;
|
||||
slogt("found tyreslock effect set");
|
||||
ds->effect_type = EFFECT_TYRELOCK;
|
||||
ds->hapticsettings.effect_type = EFFECT_TYRELOCK;
|
||||
}
|
||||
|
||||
if (ds->is_valid == false)
|
||||
@@ -113,11 +113,26 @@ int strtodevsubsubtype(const char* device_subsubtype, DeviceSettings* ds)
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_MOZAR5;
|
||||
devfound = true;
|
||||
}
|
||||
if (strcicmp(device_subsubtype, "MozaR3") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_MOZAR5;
|
||||
devfound = true;
|
||||
}
|
||||
if (strcicmp(device_subsubtype, "MozaKSProWheel") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL;
|
||||
devfound = true;
|
||||
}
|
||||
if (strcicmp(device_subsubtype, "CSLELITEV3PEDALS") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_CSLELITEV3PEDALS;
|
||||
devfound = true;
|
||||
}
|
||||
if (strcicmp(device_subsubtype, "SIMNETPEDALS") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_SIMNETPEDALS;
|
||||
devfound = true;
|
||||
}
|
||||
if (strcicmp(device_subsubtype, "SIMAGICP1000PEDALS") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_SIMAGICP1000PEDALS;
|
||||
@@ -576,31 +591,31 @@ int gettyre(config_setting_t* device_settings, DeviceSettings* ds) {
|
||||
const char* temp;
|
||||
int found = config_setting_lookup_string(device_settings, "tyre", &temp);
|
||||
|
||||
ds->tyre = ALLFOUR;
|
||||
ds->hapticsettings.tyre = ALLFOUR;
|
||||
|
||||
if (strcicmp(temp, "FRONTS") == 0)
|
||||
{
|
||||
ds->tyre = FRONTS;
|
||||
ds->hapticsettings.tyre = FRONTS;
|
||||
}
|
||||
if (strcicmp(temp, "REARS") == 0)
|
||||
{
|
||||
ds->tyre = REARS;
|
||||
ds->hapticsettings.tyre = REARS;
|
||||
}
|
||||
if (strcicmp(temp, "FRONTLEFT") == 0)
|
||||
{
|
||||
ds->tyre = FRONTLEFT;
|
||||
ds->hapticsettings.tyre = FRONTLEFT;
|
||||
}
|
||||
if (strcicmp(temp, "FRONTRIGHT") == 0)
|
||||
{
|
||||
ds->tyre = FRONTRIGHT;
|
||||
ds->hapticsettings.tyre = FRONTRIGHT;
|
||||
}
|
||||
if (strcicmp(temp, "REARLEFT") == 0)
|
||||
{
|
||||
ds->tyre = REARLEFT;
|
||||
ds->hapticsettings.tyre = REARLEFT;
|
||||
}
|
||||
if (strcicmp(temp, "REARRIGHT") == 0)
|
||||
{
|
||||
ds->tyre = REARRIGHT;
|
||||
ds->hapticsettings.tyre = REARRIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -710,108 +725,15 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_subtype == SIMDEVTYPE_USBWHEEL)
|
||||
if (ds->dev_type == SIMDEV_USB)
|
||||
{
|
||||
// logic for different devices
|
||||
int b = 0;
|
||||
|
||||
const char* temp;
|
||||
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
|
||||
if(temp != NULL && found > 0)
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
b = strtodevsubsubtype(temp, ds);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
|
||||
{
|
||||
slogt("analysing haptic effect settings");
|
||||
const char* effect;
|
||||
config_setting_lookup_string(device_settings, "effect", &effect);
|
||||
strtoeffecttype(effect, ds);
|
||||
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES || ds->effect_type == EFFECT_SUSPENSION )
|
||||
{
|
||||
gettyre(device_settings, ds);
|
||||
ds->threshold = 0;
|
||||
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
|
||||
}
|
||||
|
||||
if (ds->dev_type == SIMDEV_SOUND)
|
||||
{
|
||||
slogi("reading configured sound device settings");
|
||||
ds->sounddevsettings.frequency = 0;
|
||||
ds->sounddevsettings.frequencyMax = 0;
|
||||
ds->sounddevsettings.amplitude = 50;
|
||||
ds->sounddevsettings.amplitudeMax = 50;
|
||||
ds->sounddevsettings.volume = 0;
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.channels = 1;
|
||||
ds->sounddevsettings.duration = 2.0;
|
||||
if (ds->effect_type == EFFECT_GEARSHIFT)
|
||||
const char* temp;
|
||||
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
|
||||
if(temp != NULL && found > 0)
|
||||
{
|
||||
ds->sounddevsettings.duration = .125;
|
||||
}
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
|
||||
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
|
||||
config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency);
|
||||
config_setting_lookup_int(device_settings, "frequencyMax", &ds->sounddevsettings.frequencyMax);
|
||||
config_setting_lookup_int(device_settings, "amplitude", &ds->sounddevsettings.amplitude);
|
||||
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->sounddevsettings.amplitudeMax);
|
||||
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
|
||||
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
|
||||
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||
|
||||
const char* temp = NULL;
|
||||
int found = 0;
|
||||
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
||||
if (found == CONFIG_FALSE)
|
||||
{
|
||||
ds->sounddevsettings.dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(temp != NULL)
|
||||
{
|
||||
ds->sounddevsettings.dev = strdup(temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
found = config_setting_lookup_string(device_settings, "modulation", &temp);
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
|
||||
if (found == 0)
|
||||
{
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
|
||||
slogd("Effect modulation not found, set to none");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strcicmp(temp, "FREQUENCY") == 0)
|
||||
{
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_FREQUENCY;
|
||||
if(ds->sounddevsettings.frequencyMax == 0 || ds->sounddevsettings.frequencyMax < ds->sounddevsettings.frequency)
|
||||
{
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
|
||||
slogw("Falling back to no frequency modulation since frequencyMax is either not set or set below target frequency");
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("Effect modulation found, set to FREQUENCY");
|
||||
}
|
||||
}
|
||||
else if(strcicmp(temp, "AMPLIFY") == 0)
|
||||
{
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_AMPLIFY;
|
||||
slogi("Effect modulation found, set to AMPLIFY");
|
||||
}
|
||||
else
|
||||
{
|
||||
slogw("%s is not a valid modulation type, falling back to no effect modulation");
|
||||
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
|
||||
}
|
||||
}
|
||||
strtodevsubsubtype(temp, ds);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -859,7 +781,128 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||
found = config_setting_lookup_float(device_settings, "ampfactor", &factor);
|
||||
ds->serialdevsettings.ampfactor = ampfactor;
|
||||
|
||||
slogt("set port baud rate to %i, ampfactor %f", baud, ampfactor);
|
||||
double fanpower = 0.6;
|
||||
config_setting_lookup_float(device_settings, "fanpower", &fanpower);
|
||||
ds->serialdevsettings.fanpower = fanpower;
|
||||
|
||||
slogt("set port baud rate to %i, ampfactor %f, fanpower %f", baud, ampfactor, fanpower);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_subtype == SIMDEVTYPE_USBWHEEL || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
|
||||
{
|
||||
slogt("analysing haptic effect settings");
|
||||
ds->has_haptic_effects = true;
|
||||
const char* effect;
|
||||
config_setting_lookup_string(device_settings, "effect", &effect);
|
||||
strtoeffecttype(effect, ds);
|
||||
if (ds->hapticsettings.effect_type == EFFECT_TYRESLIP || ds->hapticsettings.effect_type == EFFECT_TYRELOCK || ds->hapticsettings.effect_type == EFFECT_ABSBRAKES || ds->hapticsettings.effect_type == EFFECT_SUSPENSION )
|
||||
{
|
||||
gettyre(device_settings, ds);
|
||||
ds->threshold = 0;
|
||||
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
|
||||
}
|
||||
|
||||
slogi("reading configured haptic effect settings");
|
||||
ds->hapticsettings.frequency = 0;
|
||||
ds->hapticsettings.frequencyMax = 0;
|
||||
ds->hapticsettings.amplitude = 50;
|
||||
ds->hapticsettings.amplitudeMax = 50;
|
||||
ds->hapticsettings.volume = 0;
|
||||
if (ds->hapticsettings.effect_type == EFFECT_GEARSHIFT)
|
||||
{
|
||||
ds->hapticsettings.duration = .125;
|
||||
}
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
|
||||
config_setting_lookup_int(device_settings, "volume", &ds->hapticsettings.volume);
|
||||
config_setting_lookup_int(device_settings, "frequency", &ds->hapticsettings.frequency);
|
||||
config_setting_lookup_int(device_settings, "frequencyMax", &ds->hapticsettings.frequencyMax);
|
||||
config_setting_lookup_int(device_settings, "amplitude", &ds->hapticsettings.amplitude);
|
||||
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->hapticsettings.amplitudeMax);
|
||||
|
||||
const char* temp = NULL;
|
||||
int found = 0;
|
||||
found = config_setting_lookup_string(device_settings, "modulation", &temp);
|
||||
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
|
||||
if (found == 0)
|
||||
{
|
||||
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
|
||||
slogd("Effect modulation not found, set to none");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strcicmp(temp, "FREQUENCY") == 0)
|
||||
{
|
||||
ds->hapticsettings.modulation = EFFECT_MODULATION_FREQUENCY;
|
||||
if(ds->hapticsettings.frequencyMax == 0 || ds->hapticsettings.frequencyMax < ds->hapticsettings.frequency)
|
||||
{
|
||||
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
|
||||
slogw("Falling back to no frequency modulation since frequencyMax is either not set or set below target frequency");
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("Effect modulation found, set to FREQUENCY");
|
||||
}
|
||||
}
|
||||
else if(strcicmp(temp, "AMPLIFY") == 0)
|
||||
{
|
||||
ds->hapticsettings.modulation = EFFECT_MODULATION_AMPLIFY;
|
||||
slogi("Effect modulation found, set to AMPLIFY");
|
||||
}
|
||||
else
|
||||
{
|
||||
slogw("%s is not a valid modulation type, falling back to no effect modulation");
|
||||
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
ds->hapticsettings.motorposition = 0;
|
||||
int motorposition = 1;
|
||||
config_setting_lookup_int(device_settings, "motors", &motorposition);
|
||||
ds->hapticsettings.motorposition = motorposition;
|
||||
}
|
||||
|
||||
if (ds->dev_type == SIMDEV_SOUND)
|
||||
{
|
||||
slogi("reading configured sound device settings");
|
||||
ds->sounddevsettings.volume = 0;
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.channels = 1;
|
||||
ds->sounddevsettings.noise = 0;
|
||||
if (ds->hapticsettings.effect_type == EFFECT_GEARSHIFT)
|
||||
{
|
||||
ds->sounddevsettings.duration = .125;
|
||||
}
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
|
||||
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
|
||||
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
|
||||
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
|
||||
config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise);
|
||||
|
||||
const char* temp = NULL;
|
||||
int found = 0;
|
||||
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
||||
if (found == CONFIG_FALSE)
|
||||
{
|
||||
ds->sounddevsettings.dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(temp != NULL)
|
||||
{
|
||||
ds->sounddevsettings.dev = strdup(temp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ typedef enum
|
||||
SIMDEVSUBTYPE_SIMAGICP1000PEDALS = 5,
|
||||
SIMDEVSUBTYPE_SIMAGICGTNEO = 6,
|
||||
SIMDEVSUBTYPE_MOZA_NEW = 7,
|
||||
SIMDEVSUBTYPE_LOGITECH_G29 = 8
|
||||
SIMDEVSUBTYPE_LOGITECH_G29 = 8,
|
||||
SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL = 9,
|
||||
SIMDEVSUBTYPE_SIMNETPEDALS = 10
|
||||
}
|
||||
DeviceSubSubType;
|
||||
|
||||
@@ -72,6 +74,14 @@ typedef enum
|
||||
}
|
||||
VibrationEffectType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EFFECT_MODULATION_NONE = 0,
|
||||
EFFECT_MODULATION_FREQUENCY = 1,
|
||||
EFFECT_MODULATION_AMPLIFY = 2,
|
||||
}
|
||||
EffectModulationType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MOTOR_1 = 0,
|
||||
@@ -109,12 +119,13 @@ MonocoqueGear;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MONOCOQUE_ERROR_NONE = 0,
|
||||
MONOCOQUE_ERROR_UNKNOWN = 1,
|
||||
MONOCOQUE_ERROR_INVALID_SIM = 2,
|
||||
MONOCOQUE_ERROR_INVALID_DEV = 3,
|
||||
MONOCOQUE_ERROR_NODATA = 4,
|
||||
MONOCOQUE_ERROR_UNKNOWN_DEV = 5
|
||||
MONOCOQUE_ERROR_NONE = 0,
|
||||
MONOCOQUE_ERROR_UNKNOWN = 1,
|
||||
MONOCOQUE_ERROR_INVALID_SIM = 2,
|
||||
MONOCOQUE_ERROR_INVALID_DEV = 3,
|
||||
MONOCOQUE_ERROR_NODATA = 4,
|
||||
MONOCOQUE_ERROR_UNKNOWN_DEV = 5,
|
||||
MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE = 6,
|
||||
}
|
||||
MonocoqueError;
|
||||
|
||||
@@ -167,31 +178,42 @@ typedef struct
|
||||
int startled;
|
||||
int endled;
|
||||
float ampfactor;
|
||||
float fanpower;
|
||||
int baud;
|
||||
}
|
||||
SerialDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t frequency;
|
||||
uint32_t volume;
|
||||
int lowbound_frequency;
|
||||
int upperbound_frequency;
|
||||
uint32_t frequencyMax;
|
||||
uint32_t amplitudeMax;
|
||||
uint32_t amplitude;
|
||||
int pan;
|
||||
int channels;
|
||||
double duration;
|
||||
char* dev;
|
||||
SoundEffectModulationType modulation;
|
||||
int noise;
|
||||
}
|
||||
SoundDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int value0;
|
||||
int value1;
|
||||
uint32_t frequency;
|
||||
uint32_t amplitude;
|
||||
uint32_t volume;
|
||||
uint32_t frequencyMax;
|
||||
uint32_t amplitudeMax;
|
||||
|
||||
double threshold;
|
||||
double duration;
|
||||
|
||||
MotorPosition motorposition;
|
||||
VibrationEffectType effect_type;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
EffectModulationType modulation;
|
||||
}
|
||||
HapticEffectSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* dev;
|
||||
}
|
||||
USBDeviceSettings;
|
||||
@@ -203,14 +225,15 @@ typedef struct
|
||||
DeviceType dev_type;
|
||||
DeviceSubType dev_subtype;
|
||||
DeviceSubSubType dev_subsubtype;
|
||||
bool has_haptic_effects;
|
||||
// to get really fancy move the effect information to it's own structure that would be a member of
|
||||
// any device settings member structure that can carry an effect
|
||||
VibrationEffectType effect_type;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
|
||||
double threshold;
|
||||
bool has_config;
|
||||
char* specific_config_file;
|
||||
// union?
|
||||
HapticEffectSettings hapticsettings;
|
||||
TachometerSettings tachsettings;
|
||||
SerialDeviceSettings serialdevsettings;
|
||||
SoundDeviceSettings sounddevsettings;
|
||||
|
||||
@@ -67,10 +67,10 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
struct arg_file* arg_log = arg_filen("l", "log", "<log_file>", 0, 1, NULL);
|
||||
struct arg_str* arg_confdir = arg_str1(NULL, NULL, "configdir", "<config_dir>");
|
||||
struct arg_int* arg_fps = arg_int0("f", "fps", "fps", "main data refresh rate");
|
||||
struct arg_lit* help = arg_litn(NULL,"help", 0, 1, "print this help and exit");
|
||||
struct arg_lit* help1 = arg_litn(NULL,"help", 0, 1, "print this help and exit");
|
||||
struct arg_lit* vers = arg_litn(NULL,"version", 0, 1, "print version information and exit");
|
||||
struct arg_end* end1 = arg_end(20);
|
||||
void* argtable1[] = {cmd1,arg_log,arg_conf,arg_fps,arg_udp,arg_audio1,arg_verbosity1,help,vers,end1};
|
||||
void* argtable1[] = {cmd1,arg_log,arg_conf,arg_fps,arg_udp,arg_audio1,arg_verbosity1,help1,vers,end1};
|
||||
int nerrors1;
|
||||
|
||||
struct arg_rex* cmd2a = arg_rex1(NULL, NULL, "config", NULL, REG_ICASE, NULL);
|
||||
@@ -121,6 +121,14 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
|
||||
if (nerrors1==0)
|
||||
{
|
||||
if (help1->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end1,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable1,"\n");
|
||||
exitcode = E_SUCCESS_AND_EXIT;
|
||||
goto cleanup;
|
||||
}
|
||||
p->program_action = A_PLAY;
|
||||
p->verbosity_count = arg_verbosity1->count;
|
||||
|
||||
@@ -154,64 +162,75 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
}
|
||||
exitcode = E_SUCCESS_AND_DO;
|
||||
}
|
||||
else
|
||||
if (nerrors2==0)
|
||||
else if (nerrors2==0)
|
||||
{
|
||||
if (help2->count > 0)
|
||||
{
|
||||
p->program_action = A_CONFIG_TACH;
|
||||
p->max_revs = arg_max_revs->ival[0];
|
||||
p->granularity = 1;
|
||||
if (arg_granularity->ival[0] > 0 && arg_granularity->ival[0] < 5 && arg_granularity->ival[0] != 3)
|
||||
{
|
||||
p->granularity=arg_granularity->ival[0];
|
||||
}
|
||||
p->save_file = *arg_save->filename;
|
||||
p->verbosity_count = arg_verbosity2->count;
|
||||
exitcode = E_SUCCESS_AND_DO;
|
||||
}
|
||||
else if (nerrors3==0)
|
||||
{
|
||||
p->program_action = A_TEST;
|
||||
p->verbosity_count = arg_verbosity3->count;
|
||||
if (arg_audio2->count > 0)
|
||||
{
|
||||
p->disable_audio = true;
|
||||
}
|
||||
exitcode = E_SUCCESS_AND_DO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cmd1->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end1,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable1,"\n");
|
||||
}
|
||||
else
|
||||
if (cmd2a->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end2,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable2,"\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (help->count==0 && vers->count==0)
|
||||
{
|
||||
printf("%s: missing <play|config|test> command.\n",progname);
|
||||
printf("Usage 1: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable1,"\n");
|
||||
printf("Usage 2: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable2,"\n");
|
||||
printf("Usage 3: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable3,"\n");
|
||||
}
|
||||
}
|
||||
arg_print_errors(stdout,end2,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable2,"\n");
|
||||
exitcode = E_SUCCESS_AND_EXIT;
|
||||
goto cleanup;
|
||||
}
|
||||
p->program_action = A_CONFIG_TACH;
|
||||
p->max_revs = arg_max_revs->ival[0];
|
||||
p->granularity = 1;
|
||||
if (arg_granularity->ival[0] > 0 && arg_granularity->ival[0] < 5 && arg_granularity->ival[0] != 3)
|
||||
{
|
||||
p->granularity=arg_granularity->ival[0];
|
||||
}
|
||||
p->save_file = *arg_save->filename;
|
||||
p->verbosity_count = arg_verbosity2->count;
|
||||
exitcode = E_SUCCESS_AND_DO;
|
||||
}
|
||||
else if (nerrors3==0)
|
||||
{
|
||||
if (help3->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end3,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable3,"\n");
|
||||
exitcode = E_SUCCESS_AND_EXIT;
|
||||
goto cleanup;
|
||||
}
|
||||
p->program_action = A_TEST;
|
||||
p->verbosity_count = arg_verbosity3->count;
|
||||
if (arg_audio2->count > 0)
|
||||
{
|
||||
p->disable_audio = true;
|
||||
}
|
||||
exitcode = E_SUCCESS_AND_DO;
|
||||
}
|
||||
else
|
||||
{
|
||||
// hit this if you typed wrong parameters
|
||||
if (cmd1->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end1,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable1,"\n");
|
||||
exitcode = E_SUCCESS_AND_EXIT;
|
||||
goto cleanup;
|
||||
}
|
||||
if (cmd2a->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end2,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable2,"\n");
|
||||
exitcode = E_SUCCESS_AND_EXIT;
|
||||
goto cleanup;
|
||||
}
|
||||
if (cmd3->count > 0)
|
||||
{
|
||||
arg_print_errors(stdout,end3,progname);
|
||||
printf("Usage: %s ", progname);
|
||||
arg_print_syntax(stdout,argtable3,"\n");
|
||||
exitcode = E_SUCCESS_AND_EXIT;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
// interpret some special cases before we go through trouble of reading the config file
|
||||
if (help->count > 0)
|
||||
if (help0->count > 0 || (cmd3->count == 0 && cmd1->count == 0 && cmd2a->count == 0))
|
||||
{
|
||||
printf("Usage: %s\n", progname);
|
||||
printf("Usage 1: %s ", progname);
|
||||
|
||||
@@ -173,7 +173,8 @@ int main(int argc, char** argv)
|
||||
config_setting_t* config_devices = NULL;
|
||||
if (!config_read_file(&cfg, ms->config_str))
|
||||
{
|
||||
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
||||
sloge("Issue with monocoque config file: %s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
||||
fprintf(stderr, "Issue with monocoque config file: %s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
|
||||
config_destroy(&cfg);
|
||||
slog_destroy();
|
||||
goto cleanup_final;
|
||||
@@ -192,6 +193,8 @@ int main(int argc, char** argv)
|
||||
SimDevice* tachdev = malloc(sizeof(SimDevice));
|
||||
tachdev->initialized = false;
|
||||
SimData* sdata = malloc(sizeof(SimData));
|
||||
SimInfo* siminfo = malloc(sizeof(SimInfo));
|
||||
simapi_set_faux_siminfo(siminfo);
|
||||
DeviceSettings* ds = malloc(sizeof(DeviceSettings));
|
||||
|
||||
error = devsetup("USB", "Tachometer", "None", ms, ds, NULL);
|
||||
@@ -204,7 +207,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
int devices = 0;
|
||||
|
||||
devices = devinit(tachdev, 1, ds, ms);
|
||||
devices = devinit(tachdev, siminfo, 1, ds, ms);
|
||||
if(devices < 1)
|
||||
{
|
||||
error = MONOCOQUE_ERROR_INVALID_DEV;
|
||||
@@ -287,7 +290,9 @@ int main(int argc, char** argv)
|
||||
|
||||
int numdevices = uiloadconfig(ms->config_str, confignum, configureddevices, ms, ds);
|
||||
SimDevice* simdevices = malloc(numdevices * sizeof(SimDevice));
|
||||
int initdevices = devinit(simdevices, configureddevices, ds, ms);
|
||||
SimInfo* siminfo = malloc(sizeof(SimInfo));
|
||||
simapi_set_faux_siminfo(siminfo);
|
||||
int initdevices = devinit(simdevices, siminfo, configureddevices, ds, ms);
|
||||
for( int i = 0; i < configureddevices; i++)
|
||||
{
|
||||
settingsfree(ds[i]);
|
||||
|
||||
@@ -9,6 +9,11 @@ set(simulatorapi_source_files
|
||||
simapi/include/dirt2data.h
|
||||
simapi/include/scs2data.h
|
||||
simapi/include/outgauge.h
|
||||
simapi/include/f12018.h
|
||||
simapi/include/rbrdata.h
|
||||
simapi/include/r3e.h
|
||||
simapi/include/wreckfest2data.h
|
||||
simapi/include/forza.h
|
||||
simapi/simmap/basicmap.h
|
||||
simapi/simmap/mapacdata.c
|
||||
simapi/simmap/mapacdata.h
|
||||
@@ -18,14 +23,23 @@ set(simulatorapi_source_files
|
||||
simapi/simapi/pcars2.h
|
||||
simapi/simapi/scs2.h
|
||||
simapi/simapi/outgauge.h
|
||||
simapi/simapi/wreckfest2.h
|
||||
simapi/simapi/f1.h
|
||||
simapi/simapi/rbr.h
|
||||
simapi/simapi/forzadef.h
|
||||
simapi/simapi/r3edef.h
|
||||
simapi/simapi/mapping/acmapper.c
|
||||
simapi/simapi/mapping/rf2mapper.c
|
||||
simapi/simapi/mapping/r3emapper.c
|
||||
simapi/simapi/mapping/pcars2mapper.c
|
||||
simapi/simapi/mapping/dirt2mapper.c
|
||||
simapi/simapi/mapping/scs2mapper.c
|
||||
simapi/simapi/mapping/outgaugemapper.c
|
||||
simapi/simapi/mapping/f12018mapper.c
|
||||
simapi/simapi/mapping/rbrmapper.c
|
||||
simapi/simapi/mapping/wreckfest2mapper.c
|
||||
simapi/simapi/mapping/forzamapper.c
|
||||
simapi/simapi/getpid.c
|
||||
simapi/simapi/getpid.h
|
||||
)
|
||||
|
||||
add_library(simulatorapi STATIC ${simulatorapi_source_files})
|
||||
|
||||
Submodule src/monocoque/simulatorapi/simapi updated: 3410864cc9...50fd181681
@@ -0,0 +1,8 @@
|
||||
Package: monocoque
|
||||
Version: 1
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: Paul Jones <paul@spacefreak18.xyz>
|
||||
Description: Racing Simulator Device Manager
|
||||
Depends: libpulse0,libconfig11,libargtable2-0,liblua5.4-0,libuv1t64,libserialport0,libxml2,libxdg-basedir1,libhidapi-hidraw0
|
||||
@@ -0,0 +1,8 @@
|
||||
Package: monocoque
|
||||
Version: 1
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: Paul Jones <paul@spacefreak18.xyz>
|
||||
Description: Racing Simulator Device Manager
|
||||
Depends: libpulse0,libconfig9,libargtable2-0,liblua5.4-0,libuv1t64,libserialport0,libxml2,libxdg-basedir1,libhidapi-hidraw0
|
||||
@@ -0,0 +1,256 @@
|
||||
#!/bin/bash
|
||||
# Monocoque Distrobox Installer
|
||||
# For immutable Linux distributions (Bazzite, Silverblue, etc.)
|
||||
# where native package managers are unavailable.
|
||||
#
|
||||
# Installs monocoque and dependencies inside an Arch Linux distrobox container,
|
||||
# with wrapper scripts on the host for transparent access.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_VERSION="1.0.0"
|
||||
CONTAINER="simracing"
|
||||
INSTALL_DIR="$HOME/.local/share/simracing"
|
||||
BIN_DIR="$HOME/.local/bin"
|
||||
CONFIG_DIR="$HOME/.config/monocoque"
|
||||
|
||||
# Color output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo ""
|
||||
echo "╔══════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Monocoque Distrobox Installer v${SCRIPT_VERSION} ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# --- Main ---
|
||||
|
||||
print_header
|
||||
|
||||
# Check ~/.local/bin is in PATH
|
||||
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
|
||||
log_error "$BIN_DIR is not in your PATH."
|
||||
log_info "Add this to your shell config:"
|
||||
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check distrobox is available
|
||||
if ! command -v distrobox &>/dev/null; then
|
||||
log_error "distrobox is not installed."
|
||||
log_info "Install distrobox first: https://distrobox.it/#installation"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure dialout group exists and user is a member
|
||||
log_info "Checking serial device access (dialout group)..."
|
||||
if ! grep -q '^dialout:' /etc/group 2>/dev/null; then
|
||||
if grep -q '^dialout:' /usr/lib/group 2>/dev/null; then
|
||||
log_info "Adding dialout group to /etc/group (Fedora Atomic fix)..."
|
||||
grep -E '^dialout:' /usr/lib/group | sudo tee -a /etc/group >/dev/null
|
||||
else
|
||||
log_info "Creating dialout group..."
|
||||
sudo groupadd dialout
|
||||
fi
|
||||
fi
|
||||
if ! groups | grep -qw dialout; then
|
||||
log_info "Adding $USER to the dialout group for serial device access..."
|
||||
sudo usermod -aG dialout "$USER"
|
||||
log_warn "You will need to REBOOT after setup completes for serial access to work."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Prevent ModemManager from grabbing Moza serial devices
|
||||
UDEV_RULE="/etc/udev/rules.d/99-moza-serial.rules"
|
||||
if [ ! -f "$UDEV_RULE" ]; then
|
||||
if systemctl is-active --quiet ModemManager 2>/dev/null; then
|
||||
echo ""
|
||||
log_warn "ModemManager is running on your system."
|
||||
echo " Moza wheel bases use USB serial devices that ModemManager may claim,"
|
||||
echo " preventing monocoque from communicating with the wheel."
|
||||
echo ""
|
||||
echo " A udev rule can tell ModemManager to ignore Moza devices (vendor 346e)."
|
||||
echo " This only affects Moza USB devices — other modems will work normally."
|
||||
echo ""
|
||||
read -rp "Install udev rule to prevent ModemManager from grabbing Moza devices? [Y/n]: " mm_confirm
|
||||
if [[ "$mm_confirm" =~ ^[Nn]$ ]]; then
|
||||
echo ""
|
||||
log_info "Skipped udev rule. If monocoque can't talk to your wheel, run:"
|
||||
echo " sudo tee $UDEV_RULE <<< 'ACTION==\"add|change\", SUBSYSTEM==\"usb\", ATTR{idVendor}==\"346e\", ENV{ID_MM_DEVICE_IGNORE}=\"1\"'"
|
||||
echo " sudo udevadm control --reload-rules && sudo udevadm trigger"
|
||||
echo ""
|
||||
else
|
||||
log_info "Installing udev rule..."
|
||||
echo 'ACTION=="add|change", SUBSYSTEM=="usb", ATTR{idVendor}=="346e", ENV{ID_MM_DEVICE_IGNORE}="1"' | sudo tee "$UDEV_RULE" >/dev/null
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
log_success "ModemManager udev rule installed"
|
||||
fi
|
||||
else
|
||||
# ModemManager not running — install the rule silently
|
||||
echo 'ACTION=="add|change", SUBSYSTEM=="usb", ATTR{idVendor}=="346e", ENV{ID_MM_DEVICE_IGNORE}="1"' | sudo tee "$UDEV_RULE" >/dev/null
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create the Arch Linux distrobox container
|
||||
if ! distrobox list 2>/dev/null | grep -q "$CONTAINER"; then
|
||||
log_info "Creating Arch Linux container '$CONTAINER'..."
|
||||
distrobox create \
|
||||
--image docker.io/library/archlinux:latest \
|
||||
--name "$CONTAINER" \
|
||||
--root \
|
||||
--additional-flags "--privileged --security-opt seccomp=unconfined" \
|
||||
--pre-init-hooks "sed -i 's/^SigLevel.*/SigLevel = Never/' /etc/pacman.conf && pacman -Sy --noconfirm archlinux-keyring && pacman-key --init && pacman-key --populate archlinux && sed -i 's/^SigLevel.*/SigLevel = Required DatabaseOptional/' /etc/pacman.conf"
|
||||
log_success "Container '$CONTAINER' created"
|
||||
else
|
||||
log_info "Container '$CONTAINER' already exists, skipping creation."
|
||||
fi
|
||||
|
||||
# Install packages inside the container
|
||||
log_info "Installing packages inside container (this may take a few minutes)..."
|
||||
distrobox enter --root "$CONTAINER" -- bash -c '
|
||||
set -euo pipefail
|
||||
|
||||
# Install build dependencies
|
||||
echo "Installing build dependencies..."
|
||||
sudo pacman -Syu --needed --noconfirm base-devel git mingw-w64-gcc
|
||||
|
||||
# Install yay (AUR helper) if not present
|
||||
if ! command -v yay &>/dev/null; then
|
||||
echo "Installing yay AUR helper..."
|
||||
TMPDIR=$(mktemp -d)
|
||||
git clone https://aur.archlinux.org/yay-bin.git "$TMPDIR/yay-bin"
|
||||
cd "$TMPDIR/yay-bin"
|
||||
makepkg -si --noconfirm
|
||||
cd /
|
||||
rm -rf "$TMPDIR"
|
||||
fi
|
||||
|
||||
# Install AUR packages sequentially (simd depends on simapi, monocoque depends on both)
|
||||
echo "Installing AUR packages..."
|
||||
yay -S --needed --noconfirm simapi-git
|
||||
yay -S --needed --noconfirm simd-git
|
||||
yay -S --needed --noconfirm monocoque-git
|
||||
|
||||
# Build simshmbridge (not on AUR)
|
||||
INSTALL_DIR="$HOME/.local/share/simracing"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cd "$INSTALL_DIR"
|
||||
if [ ! -d "simshmbridge" ]; then
|
||||
echo "Cloning simshmbridge..."
|
||||
git clone --recurse-submodules "https://github.com/Spacefreak18/simshmbridge.git"
|
||||
else
|
||||
echo "simshmbridge already cloned, pulling latest..."
|
||||
cd simshmbridge && git pull && git submodule update --init --recursive && cd ..
|
||||
fi
|
||||
echo "Building simshmbridge..."
|
||||
cd "$INSTALL_DIR/simshmbridge"
|
||||
git submodule update --init --recursive
|
||||
make clean 2>/dev/null || true
|
||||
make -j$(nproc)
|
||||
|
||||
echo ""
|
||||
echo "All components built successfully inside container."
|
||||
'
|
||||
|
||||
# Install wrapper scripts to ~/.local/bin
|
||||
log_info "Installing wrapper scripts..."
|
||||
mkdir -p "$BIN_DIR"
|
||||
|
||||
cat > "$BIN_DIR/start-simd" << 'EOF'
|
||||
#!/usr/bin/env bash
|
||||
exec distrobox enter --root simracing -- simd "$@"
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/start-simd"
|
||||
|
||||
cat > "$BIN_DIR/start-monocoque" << 'EOF'
|
||||
#!/usr/bin/env bash
|
||||
exec distrobox enter --root simracing -- monocoque play "$@"
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/start-monocoque"
|
||||
|
||||
cat > "$BIN_DIR/test-monocoque" << 'EOF'
|
||||
#!/usr/bin/env bash
|
||||
exec distrobox enter --root simracing -- monocoque test -vv "$@"
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/test-monocoque"
|
||||
|
||||
log_success "Wrapper scripts installed"
|
||||
|
||||
# Setup monocoque config
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
if [ ! -f "$CONFIG_DIR/monocoque.config" ]; then
|
||||
log_info "Creating monocoque config template..."
|
||||
cat > "$CONFIG_DIR/monocoque.config" << 'EOF'
|
||||
configs = (
|
||||
{
|
||||
sim = "default";
|
||||
car = "default";
|
||||
devices = (
|
||||
{
|
||||
device = "Serial";
|
||||
type = "Wheel";
|
||||
subtype = "MozaNew";
|
||||
devpath = "/dev/serial/by-id/CHANGE_ME_TO_YOUR_MOZA_BASE";
|
||||
baud = 115200;
|
||||
});
|
||||
}
|
||||
);
|
||||
EOF
|
||||
log_success "Config created at $CONFIG_DIR/monocoque.config"
|
||||
else
|
||||
log_info "Config already exists, skipping"
|
||||
fi
|
||||
|
||||
# Done
|
||||
echo ""
|
||||
echo "╔══════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Installation Complete! ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
log_success "Monocoque (distrobox) installed!"
|
||||
echo ""
|
||||
echo " Installed:"
|
||||
echo " AUR packages: simapi-git, simd-git, monocoque-git (in '$CONTAINER' container)"
|
||||
echo " Bridge: $INSTALL_DIR/simshmbridge/"
|
||||
echo " Config: $CONFIG_DIR/monocoque.config"
|
||||
echo " Commands: start-simd, start-monocoque, test-monocoque"
|
||||
echo ""
|
||||
echo " Next steps:"
|
||||
echo " 1. Set your device path in $CONFIG_DIR/monocoque.config"
|
||||
echo " (replace CHANGE_ME_TO_YOUR_MOZA_BASE with your device from /dev/serial/by-id/)"
|
||||
echo " 2. Test with: test-monocoque"
|
||||
echo " 3. Set Steam launch options for your games to start the telemetry stack automatically:"
|
||||
echo " In Steam > Game Properties > Launch Options, add:"
|
||||
echo " start-simd & start-monocoque & <bridge_path> %command%"
|
||||
echo " For example, for Assetto Corsa:"
|
||||
echo " start-simd & start-monocoque & $INSTALL_DIR/simshmbridge/assets/acbridge.exe %command%"
|
||||
echo ""
|
||||
echo " For tools that automate steps 1 and 3 (Moza auto-detection, Steam launch"
|
||||
echo " option configuration, unified game launcher), visit:"
|
||||
echo " https://github.com/cescofry/simracing-utilities"
|
||||
echo ""
|
||||
@@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
# Monocoque Distrobox Uninstaller
|
||||
# Removes the distrobox-based monocoque installation.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
CONTAINER="simracing"
|
||||
BIN_DIR="$HOME/.local/bin"
|
||||
INSTALL_DIR="$HOME/.local/share/simracing"
|
||||
CONFIG_DIR="$HOME/.config/monocoque"
|
||||
UDEV_RULE="/etc/udev/rules.d/99-moza-serial.rules"
|
||||
|
||||
# Color output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo ""
|
||||
echo "╔══════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Monocoque Distrobox Uninstaller ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
}
|
||||
|
||||
print_header
|
||||
|
||||
log_warn "This will remove:"
|
||||
echo " - Distrobox container '$CONTAINER'"
|
||||
echo " - Wrapper scripts ($BIN_DIR/start-simd, start-monocoque, test-monocoque)"
|
||||
echo " - simshmbridge source ($INSTALL_DIR)"
|
||||
echo ""
|
||||
echo "This will NOT remove:"
|
||||
echo " - Configuration files ($CONFIG_DIR)"
|
||||
echo " - Convenience scripts (simracing-launch, configure-moza, etc.)"
|
||||
echo ""
|
||||
|
||||
read -rp "Continue with uninstallation? [y/N]: " confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
log_info "Uninstallation cancelled"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Remove wrapper scripts
|
||||
log_info "Removing wrapper scripts..."
|
||||
rm -f "$BIN_DIR/start-simd"
|
||||
rm -f "$BIN_DIR/start-monocoque"
|
||||
rm -f "$BIN_DIR/test-monocoque"
|
||||
log_success "Wrapper scripts removed"
|
||||
|
||||
# Remove simshmbridge source
|
||||
if [ -d "$INSTALL_DIR" ]; then
|
||||
log_info "Removing simshmbridge source..."
|
||||
rm -rf "$INSTALL_DIR"
|
||||
log_success "simshmbridge source removed"
|
||||
fi
|
||||
|
||||
# Remove distrobox container
|
||||
if distrobox list --root 2>/dev/null | grep -q "$CONTAINER"; then
|
||||
log_info "Removing distrobox container '$CONTAINER'..."
|
||||
distrobox rm --root --force "$CONTAINER"
|
||||
log_success "Container '$CONTAINER' removed"
|
||||
else
|
||||
log_info "Container '$CONTAINER' not found, skipping"
|
||||
fi
|
||||
|
||||
# Optionally remove udev rule
|
||||
if [ -f "$UDEV_RULE" ]; then
|
||||
echo ""
|
||||
read -rp "Remove ModemManager udev rule ($UDEV_RULE)? [y/N]: " remove_udev
|
||||
if [[ "$remove_udev" =~ ^[Yy]$ ]]; then
|
||||
sudo rm -f "$UDEV_RULE"
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger
|
||||
log_success "udev rule removed"
|
||||
else
|
||||
log_info "Keeping udev rule"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
log_success "Uninstallation complete!"
|
||||
echo ""
|
||||
log_info "Config files preserved at $CONFIG_DIR"
|
||||
echo " To remove those too: rm -rf $CONFIG_DIR"
|
||||
echo ""
|
||||
@@ -1,4 +1,4 @@
|
||||
#dnf install pulseaudio-libs-devel argtable-devel libconfig-devel hidapi-devel libserialport-devel lua-devel libuv-devel libxdg-basedir-devel libxml2-devel
|
||||
#dnf install pulseaudio-libs-devel argtable-devel libconfig-devel hidapi-devel libserialport-devel lua-devel libuv-devel libxdg-basedir-devel libxml2-devel procps-ng-devel
|
||||
Summary: A device manager for racing sims
|
||||
Name: monocoque
|
||||
Version: 0.0.5
|
||||
@@ -10,7 +10,7 @@ URL: https://spacefreak18.github.io/simapi
|
||||
Distribution: Fedora Linux
|
||||
Vendor: spacefreak18
|
||||
Packager: Paul Jones <paul@spacefreak18.xyz>
|
||||
Requires: pulseaudio-libs argtable libconfig hidapi libserialport libuv libxdg-basedir lua-libs libxml2
|
||||
Requires: pulseaudio-libs argtable libconfig hidapi libserialport libuv libxdg-basedir lua-libs libxml2 procps-ng
|
||||
|
||||
%description
|
||||
A device manager for Racing sims
|
||||
|
||||
Reference in New Issue
Block a user