Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
722cc4eb4e | ||
|
|
48baedf202 | ||
|
|
fdbae6198b | ||
|
|
1f81a6bc96 | ||
|
|
89e33cf196 | ||
|
|
7924ef474e | ||
|
|
d8c85bdc95 | ||
|
|
19c5afa329 | ||
|
|
27aea767d8 | ||
|
|
062a4e77ce | ||
|
|
68b273376d | ||
|
|
698ed02987 | ||
|
|
ecaf41265a | ||
|
|
dd93098f39 | ||
|
|
6d4567facf | ||
|
|
7f52462b68 | ||
|
|
945a04ee66 | ||
|
|
4a30a9735e | ||
|
|
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 | ||
|
|
37c8fb94d4 | ||
|
|
ec1690b49d | ||
|
|
7478e4e010 | ||
|
|
bcb633e774 | ||
|
|
ac6c996602 | ||
|
|
fb0ab4b96b | ||
|
|
7cde3b39fa | ||
|
|
270bf256b7 | ||
|
|
70f0ca1b50 | ||
|
|
6091e5f9dc | ||
|
|
b968dccd28 | ||
|
|
fe644ea6bd | ||
|
|
d18a420449 | ||
|
|
9983149d0e | ||
|
|
e3fde9b71e | ||
|
|
59da0dd7e3 | ||
|
|
1f236737f2 | ||
|
|
4fd4654909 | ||
|
|
4ba6dec508 | ||
|
|
3bea423613 | ||
|
|
1ee07edcc5 | ||
|
|
b09acd5bf0 | ||
|
|
410e197723 | ||
|
|
4ed5ed50c4 | ||
|
|
38120c0ea6 | ||
|
|
e738261512 | ||
|
|
d8d747a168 | ||
|
|
cd084f183b | ||
|
|
30e704a6b1 | ||
|
|
49844dce11 | ||
|
|
2e4286233d | ||
|
|
4ba4dce451 | ||
|
|
c8f2010c8e | ||
|
|
a379c32e7a | ||
|
|
46becd1cee | ||
|
|
94968c3d4c | ||
|
|
20ee6b7446 | ||
|
|
1c4f20d7a7 | ||
|
|
9fe8d0871d | ||
|
|
1f5823bce0 | ||
|
|
582c031755 | ||
|
|
9ce8a615a2 | ||
|
|
6bc921c955 | ||
|
|
dc32dd2062 | ||
|
|
220646cfe5 | ||
|
|
f7f4c00beb | ||
|
|
7a91d3d0a1 | ||
|
|
9e2ed33bfb | ||
|
|
9ef8c5c1ee | ||
|
|
187521a905 | ||
|
|
871a2b9a80 | ||
|
|
7687a95025 | ||
|
|
df49e8a3cc | ||
|
|
c5b4f872d3 | ||
|
|
5ac70779d7 | ||
|
|
0b2685ac3f | ||
|
|
42efd815df | ||
|
|
8aadf53dc0 | ||
|
|
09e200f16c | ||
|
|
7e0ce63e26 | ||
|
|
5bb1f1715c | ||
|
|
b96c6006ed | ||
|
|
e32596d723 | ||
|
|
ac04fd8e0a | ||
|
|
2a86e3b2f9 | ||
|
|
989ccc5459 | ||
|
|
5fcb7f128d | ||
|
|
90fb8969d4 | ||
|
|
4b94e68d6c | ||
|
|
7271a26e23 | ||
|
|
6b5e16f59d | ||
|
|
e0337125d3 | ||
|
|
638c7d29c3 | ||
|
|
edde4e2cad | ||
|
|
ae8904b7cf | ||
|
|
b484d7e5da | ||
|
|
96a5e689ff | ||
|
|
7926706ea1 | ||
|
|
fce4d8e33c | ||
|
|
5fcea3ad88 | ||
|
|
e22a8911b8 | ||
|
|
29c6ebe7a2 | ||
|
|
fc21669d81 | ||
|
|
03b1654112 | ||
|
|
40bb0b2929 | ||
|
|
e13faeabc7 | ||
|
|
f66af0d424 | ||
|
|
477fcd9c6c | ||
|
|
f853cd9f79 | ||
|
|
924354afa1 | ||
|
|
409a6b7707 | ||
|
|
d59e46cc64 | ||
|
|
ba4c96a3f0 | ||
|
|
f5a2b38ee2 | ||
|
|
59d2ff935f | ||
|
|
34b258ab1b | ||
|
|
9261123491 | ||
|
|
73c59f5b29 | ||
|
|
aaf0e4b6bc | ||
|
|
6d5b34f4b9 | ||
|
|
e5cee3c228 | ||
|
|
9edd275984 | ||
|
|
af060ff574 | ||
|
|
ab956af9cb | ||
|
|
f81588a2a5 | ||
|
|
808be1aec0 | ||
|
|
3733261647 | ||
|
|
1a1ede9f4b | ||
|
|
a3d0cbcb43 | ||
|
|
c0680515ae | ||
|
|
cd5be23235 | ||
|
|
af37299d25 | ||
|
|
8a2ce50187 | ||
|
|
dbe6908386 | ||
|
|
51cc376eb9 | ||
|
|
415526c4d3 | ||
|
|
52f5c824f8 | ||
|
|
ce200b8d21 | ||
|
|
e110ac50d2 | ||
|
|
d589147552 | ||
|
|
d9cdd18bf9 | ||
|
|
4db0f6dff1 | ||
|
|
a290a346cb | ||
|
|
4fd2658a98 | ||
|
|
79f0ceff28 | ||
|
|
fdd5f0b7ba | ||
|
|
0d29fd7005 | ||
|
|
b68af9c8b9 | ||
|
|
12570f5caf | ||
|
|
4a0c33d5a5 | ||
|
|
831a9d00e1 | ||
|
|
2b2ae31907 | ||
|
|
593a415cd9 | ||
|
|
a4acbf5cc7 | ||
|
|
e92ba3dd25 | ||
|
|
e78fa76e1b | ||
|
|
22da3b405c | ||
|
|
8c1298e7f3 | ||
|
|
988468d746 | ||
|
|
3b1f2e46f3 | ||
|
|
97d935c037 | ||
|
|
2660394ccf | ||
|
|
18f6dc290a | ||
|
|
db081513db | ||
|
|
8157aa1258 | ||
|
|
4d1d43821c | ||
|
|
ab3152e9e4 | ||
|
|
ac17b24cf6 | ||
|
|
97d69bec9c | ||
|
|
e4b32f1843 | ||
|
|
a6353d3469 | ||
|
|
5ef7b2f683 | ||
|
|
025f88f559 | ||
|
|
0fb2571848 | ||
|
|
d185314a31 | ||
|
|
5bc02c012d | ||
|
|
6ed403e4d5 | ||
|
|
9a23eef998 | ||
|
|
4e0deaf695 | ||
|
|
fd0b28e66f | ||
|
|
34cefb5aa7 | ||
|
|
d846305114 | ||
|
|
a35354be5b | ||
|
|
5cc8a1fb1a | ||
|
|
7711c1939b | ||
|
|
5d055fd1ad |
@@ -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[@]}"
|
||||
@@ -0,0 +1,116 @@
|
||||
name: Make Packages
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: [ "*" ]
|
||||
|
||||
jobs:
|
||||
build-monocoque-debs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, debian-latest, debian-stable]
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Checkout submodules
|
||||
run: git submodule update --init --recursive
|
||||
- name: Update apt
|
||||
run: sudo apt update
|
||||
- name: Install Dependencies
|
||||
run: sudo apt install -y libgtk-3-dev libuv1-dev libargtable2-dev libserialport-dev libconfig-dev libhidapi-dev liblua5.4-dev libxdg-basedir-dev libxml2-dev libpulse-dev libproc2-dev libcurl4-openssl-dev libglu1-mesa-dev
|
||||
- name: Set build dir
|
||||
id: strings
|
||||
shell: bash
|
||||
run: |
|
||||
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
|
||||
github_sha_hash=${{ github.sha }}
|
||||
echo "github-sha-short=${github_sha_hash:0:7}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Configure CMake
|
||||
run: >
|
||||
cmake -B ${{ steps.strings.outputs.build-output-dir }}
|
||||
-DBUILD_GUI=on
|
||||
-DCMAKE_CXX_COMPILER=g++
|
||||
-DCMAKE_C_COMPILER=gcc
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-S ${{ github.workspace }}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Release
|
||||
|
||||
- name: Create directories in package
|
||||
run: |
|
||||
mkdir PKG_SOURCE
|
||||
mkdir -p PKG_SOURCE/DEBIAN
|
||||
mkdir -p PKG_SOURCE/usr/bin/
|
||||
mkdir -p PKG_SOURCE/usr/share/applications
|
||||
mkdir -p PKG_SOURCE/usr/share/pixmaps
|
||||
mkdir -p PKG_SOURCE/usr/share/icons/hicolor/scalable/apps
|
||||
- name: Download xpm icon
|
||||
run: |
|
||||
curl -sSL https://repo.spacefreak18.xyz/monocoque/icons/monocoque.xpm -o PKG_SOURCE/usr/share/pixmaps/monocoque.xpm
|
||||
- name: Download svg icon
|
||||
run: |
|
||||
curl -sSL https://repo.spacefreak18.xyz/monocoque/icons/monocoque.svg -o PKG_SOURCE/usr/share/icons/hicolor/scalable/apps/monocoque.svg
|
||||
- name: Copy script files around to stop .github from being added to the package then build the package
|
||||
run: |
|
||||
cp ./tools/distro/debian/dpkg/${{ matrix.os }}/control ./PKG_SOURCE/DEBIAN/control
|
||||
cp ./tools/distro/debian/dpkg/copyright ./PKG_SOURCE/DEBIAN/copyright
|
||||
cp ./build/monocoque ./PKG_SOURCE/usr/bin/monocoque
|
||||
cp ./build/gmonocoque ./PKG_SOURCE/usr/bin/gmonocoque
|
||||
cp ./tools/monocoque.desktop ./PKG_SOURCE/usr/share/applications/monocoque.desktop
|
||||
dpkg-deb --build PKG_SOURCE monocoque-${{ matrix.os }}.deb
|
||||
|
||||
- name: Release the Package
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: monocoque-${{ matrix.os }}.deb
|
||||
|
||||
|
||||
build-monocoque-rpms:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [fedora-43]
|
||||
runs-on: ${{ matrix.os }}
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
|
||||
- name: create rpmbuild dirs
|
||||
run: mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
|
||||
- name: get spec file
|
||||
run: curl -o ~/fedora.spec https://raw.githubusercontent.com/Spacefreak18/monocoque/refs/heads/master/tools/distro/fedora/rpm/fedora.spec
|
||||
- name: run spec file
|
||||
run: rpmbuild -ba ~/fedora.spec
|
||||
- name: rename file
|
||||
run: cp ~/rpmbuild/RPMS/x86_64/monocoque-0.0.5-1.x86_64.rpm $GITHUB_WORKSPACE/monocoque-${{ matrix.os }}.rpm
|
||||
- name: Release the Package
|
||||
uses: softprops/action-gh-release@v1
|
||||
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
|
||||
@@ -2,3 +2,6 @@
|
||||
path = src/monocoque/simulatorapi/simapi
|
||||
url = https://github.com/spacefreak18/simapi
|
||||
# url = git@github.com:spacefreak18/simapi # ssh is better but Microsoft requires an account
|
||||
[submodule "src/monocoque/mgui/nappgui_src"]
|
||||
path = src/monocoque/mgui/nappgui_src
|
||||
url = https://github.com/frang75/nappgui_src
|
||||
|
||||
+11
@@ -1,3 +1,4 @@
|
||||
# small known issue with argtable2
|
||||
{
|
||||
argtable arg_parse
|
||||
Memcheck:Leak
|
||||
@@ -119,3 +120,13 @@
|
||||
...
|
||||
obj:*/lib*/lib*.so.*
|
||||
}
|
||||
{
|
||||
nappgui_gbind_uninitialized
|
||||
Memcheck:Cond
|
||||
fun:_gbind_update_control
|
||||
}
|
||||
{
|
||||
gtk_pango_uninitialized
|
||||
Memcheck:Cond
|
||||
fun:_pango_is_Vowel_Dependent
|
||||
}
|
||||
|
||||
+82
-26
@@ -1,7 +1,4 @@
|
||||
|
||||
# minimum CMake version required for C++20 support, among other things
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
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)
|
||||
@@ -13,6 +10,9 @@ endif()
|
||||
SET_SOURCE_FILES_PROPERTIES( src/monocoque.c PROPERTIES LANGUAGE C)
|
||||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
option(BUILD_GUI "Build GUI support" OFF)
|
||||
option(BUILD_SHARED "Build monocoque shared library" OFF)
|
||||
|
||||
|
||||
project(monocoque)
|
||||
|
||||
@@ -20,6 +20,26 @@ 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)
|
||||
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}
|
||||
# PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}
|
||||
@@ -33,17 +53,40 @@ set(LIBXML_INCLUDE_DIR /usr/include/libxml2)
|
||||
set(HIDAPI_WITH_LIBUSB FALSE) # surely will be used only on Linux
|
||||
set(BUILD_SHARED_LIBS TRUE) # HIDAPI as static library on all platforms
|
||||
|
||||
add_executable(monocoque src/monocoque/monocoque.c)
|
||||
if(USE_PULSEAUDIO)
|
||||
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)
|
||||
if(BUILD_SHARED)
|
||||
add_library(monocoque SHARED src/monocoque/monocoque.c)
|
||||
else()
|
||||
message("Using portaudio backend...")
|
||||
target_link_libraries(monocoque m hidapi-hidraw portaudio serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir)
|
||||
add_library(monocoque STATIC src/monocoque/monocoque.c)
|
||||
endif()
|
||||
add_executable(monocoque-cli src/monocoque/monocoque-cli.c)
|
||||
set_target_properties(monocoque-cli PROPERTIES OUTPUT_NAME monocoque)
|
||||
if(BUILD_GUI)
|
||||
add_executable(monocoque-gui src/monocoque/monocoque-gui.c)
|
||||
set_target_properties(monocoque-gui PROPERTIES OUTPUT_NAME gmonocoque)
|
||||
endif()
|
||||
|
||||
target_include_directories(monocoque PUBLIC config ${LIBXML_INCLUDE_DIR})
|
||||
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)
|
||||
|
||||
add_subdirectory(src/monocoque/gameloop)
|
||||
add_subdirectory(src/monocoque/simulatorapi)
|
||||
@@ -51,6 +94,19 @@ add_subdirectory(src/monocoque/helper)
|
||||
add_subdirectory(src/monocoque/devices)
|
||||
add_subdirectory(src/monocoque/slog)
|
||||
|
||||
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} ${LUA_INCLUDE_DIR})
|
||||
target_link_libraries(monocoque-cli m hidapi-hidraw pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir Lua::Lua proc2)
|
||||
target_include_directories(monocoque-cli PUBLIC config ${LIBXML_INCLUDE_DIR} ${LUA_INCLUDE_DIR})
|
||||
if(BUILD_GUI)
|
||||
add_subdirectory(src/monocoque/mgui)
|
||||
target_link_libraries(monocoque-gui m hidapi-hidraw pulse serialport xml2 argtable2 config mgui gameloop helper devices slog simulatorapi uv xdg-basedir Lua::Lua proc2)
|
||||
target_include_directories(monocoque-gui PUBLIC config ${LIBXML_INCLUDE_DIR} ${LUA_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
|
||||
#add_executable(listusb tests/testlibusb.c)
|
||||
#target_include_directories(listusb PUBLIC)
|
||||
#target_link_libraries(listusb portaudio hidapi-hidraw)
|
||||
@@ -76,15 +132,15 @@ add_subdirectory(src/monocoque/slog)
|
||||
#target_link_libraries(parserevburnerxml portaudio xml2)
|
||||
#add_test(parserevburnerxml parserevburnerxml)
|
||||
#
|
||||
#add_executable(setmem tests/setmem.c)
|
||||
#target_include_directories(setmem PUBLIC)
|
||||
#target_link_libraries(setmem)
|
||||
#add_test(setmem setmem)
|
||||
#
|
||||
#add_executable(getmem tests/getmem.c)
|
||||
#target_include_directories(getmem PUBLIC)
|
||||
#target_link_libraries(getmem)
|
||||
#add_test(getmem getmem)
|
||||
add_executable(setmem tests/setmem.c)
|
||||
target_include_directories(setmem PUBLIC)
|
||||
target_link_libraries(setmem)
|
||||
add_test(setmem setmem)
|
||||
|
||||
add_executable(getmem tests/getmem.c)
|
||||
target_include_directories(getmem PUBLIC)
|
||||
target_link_libraries(getmem)
|
||||
add_test(getmem getmem)
|
||||
#
|
||||
#add_executable(setsimdata tests/setsimdata.c)
|
||||
#target_include_directories(setsimdata PUBLIC)
|
||||
@@ -96,10 +152,10 @@ add_subdirectory(src/monocoque/slog)
|
||||
#target_link_libraries(hidtest hidapi-hidraw)
|
||||
#add_test(hidtest hidtest)
|
||||
#
|
||||
#add_executable(simlighttest tests/simlighttest.c)
|
||||
#target_include_directories(simlighttest PUBLIC)
|
||||
#target_link_libraries(simlighttest serialport)
|
||||
#add_test(simlighttest simlighttest)
|
||||
add_executable(simlighttest tests/simlighttest.c)
|
||||
target_include_directories(simlighttest PUBLIC)
|
||||
target_link_libraries(simlighttest serialport)
|
||||
add_test(simlighttest simlighttest)
|
||||
|
||||
|
||||
# used for enabling additional compiler options if supported
|
||||
@@ -133,7 +189,7 @@ else() # GCC/Clang warning option
|
||||
|
||||
if(analyze)
|
||||
message("-- Analyzer is on")
|
||||
target_compile_options(monocoque PRIVATE -fanalyzer -Wno-analyzer-possible-null-argument -Wno-analyzer-possible-null-dereference)
|
||||
target_compile_options(monocoque PRIVATE -fanalyzer -Wno-analyzer-possible-null-argument -Wno-analyzer-possible-null-dereference -fsanitize=address -g -fno-omit-frame-pointer)
|
||||
endif()
|
||||
|
||||
enable_cxx_compiler_flag_if_supported("-Wall")
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Monocoque User Setup Guide
|
||||
|
||||
## Required Packages / Software
|
||||
* build [monocoque](https://github.com/Spacefreak18/monocoque) e.g. in `~/monocoque` - follow instructions from repo
|
||||
* build [simd](https://github.com/Spacefreak18/simapi/tree/master/simd) e.g. in `~/simapi/simd` - follow instructions from repo
|
||||
* build [simshmbridge](https://github.com/spacefreak18/simshmbridge) e.g. in `~/simshmbridge` - follow instructions from repo
|
||||
|
||||
## Configure SIMD & Monocoque
|
||||
* Create a `simd` Config in `~/.config/simd/simd.config` - [use example](https://github.com/Spacefreak18/simapi/blob/master/simd/conf/simd.config)
|
||||
* no changes required to the example file
|
||||
* create Monocoque config in `~/.config/monocque/monocoque.config` - [example](https://github.com/Spacefreak18/monocoque/blob/master/conf/monocoque.config)
|
||||
* Adapt the config to your needs, remove unused entries
|
||||
* [Documentation for Bass Shaker Config](https://spacefreak18.github.io/simapi/shakers)
|
||||
* Test your config as described in the [README](README.md#testing)
|
||||
## Steam & Game Config
|
||||
### Steam
|
||||
* Adapt Steam Launch Commands from [simshbridge](https://github.com/spacefreak18/simshmbridge?tab=readme-ov-file#basic-mapping-examples)
|
||||
* to use with `simd` you need to `SIMD_BRIDGE_EXE` to the launch command like `SIMD_BRIDGE_EXE=~/git/simshmbridge/assets/pcars2bridge.exe %command% & sleep 5 && ~/.steam/steam/steamapps/common/Proton\ 6.3/proton run ~/git/simshmbridge/assets/pcars2bridge.exe`
|
||||
|
||||
### Game specific settings
|
||||
#### Automobilista 2 (AMS2)
|
||||
* In Games like `Automobilista 2` activate the `Shared Memory` Setting and make sure to set the Protocal to `Project CARS 2`.  <img src="https://docs.simucube.com/Tuner/games/assets/automobilista2_telemetry_2.png" alt="Shared Memory Settings in AMS2" width="65%">
|
||||
* Restart the Game after changing these Settings!
|
||||
#### Assetto Corsa & Assetto Corsa Competizione (ACC)
|
||||
* Assetto Corsa & ACC do not need any additional settings and should work out of the box
|
||||
|
||||
## Run everything, but in the right order
|
||||
* first start `simd` like `~/simapi/simd/build/simd --no-daemon -vv`
|
||||
* this will likely fail, so you'll need to add `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib` or `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64` in front of the command like `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64 ~/simapi/simd/build/simd --no-daemon -vv`
|
||||
* now start `monocoque` like `~/monocoque/build/monocoque play`
|
||||
* finally start the Game you want to play from Steam
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
* make sure `simd` is running and after you start a game, the CLI output confirms the game is detected
|
||||
* make sure the bridge application starts e.g. with `ps aux|grep pcars2bridge.exe` before the game starts
|
||||
* see if you have the path `/dev/shm/acpmf_physics` (for ACC) and/or `/dev/shm/$pcars2$` for AMS2
|
||||
* when `simd` recognizes the game, see if `monocoque` shows `RPM, Gear..` and other Car Metrics once you start a game
|
||||
* if `simd` recognozies the game, but `monocoque` does not show any data, doublecheck the [Game Settings](#steam--game-config) to see if `Shared Memory` is activated
|
||||
@@ -8,37 +8,70 @@ _ / / / / /_/ / / / / /_/ / /__ / /_/ / /_/ // /_/ // __/
|
||||
```
|
||||
Cross Platform device manager for driving and flight simulators, for use with common simulator software titles.
|
||||
|
||||
📚 **Usage Documentation:** [spacefreak18.github.io/simapi/](https://spacefreak18.github.io/simapi/)
|
||||
|
||||
## Features
|
||||
- Updates at 60 frames per seconds.
|
||||
- Modular design for support with various titles and devices.
|
||||
- Supports bass shakers, tachometers, several wheels, simlights, simwind etc, through usb and arduino serial.
|
||||
- Supports bass shakers, tachometers, several wheels and pedals, simlights, simwind etc, through usb and arduino serial.
|
||||
- Tachometer support is currently limited to the Revburner model. Supports existing revburner xml configuration files.
|
||||
- Includes utility to configure revburner tachometer
|
||||
- Can send data to any serial device. So far only tested with arduino. Includes sample arduino sketch for sim lights, simwind, and simhaptic effects for motors.
|
||||
- Can send data to any serial device. So far only tested with arduino. and ESP32. Includes sample arduino sketch for sim lights, simwind, and simhaptic effects for motors.
|
||||
- Support for custom arduino (or any serial) device, with a [custom lua format](https://spacefreak18.github.io/simapi/serial_custom) for sending data
|
||||
- Convincing shaker effects for noise tranducers for wheel slip, wheel lock, and abs, as well as engine rpm and gear shifts.
|
||||
- Choice of Portaudio or Pulseaudio (libpulse) backend.
|
||||
- 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.
|
||||
|
||||
## Supported Games ( see [simapi](https://github.com/spacefreak18/simapi) for more details of what is supported from each sim )
|
||||
- Using [SimSHMBridge](https://github.com/spacefreak18/simshmbridge)
|
||||
- Asseto Corsa
|
||||
- Assetto Corsa Competizione
|
||||
- Project Cars 2 (untested)
|
||||
- Automobilista 2
|
||||
|
||||
- Using [scs-sdk-plugin](https://github.com/jackz314/scs-sdk-plugin/releases)
|
||||
- Euro Truck Simuator 2
|
||||
- American Truck Simulator
|
||||
## 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/
|
||||
|
||||
- Using [rfactor 2 plugin](https://github.com/schlegp/rF2SharedMemoryMapPlugin_Wine)
|
||||
- RFactor 2
|
||||
## Quick Install
|
||||
|
||||
- Using UDP
|
||||
- Automobilista 2
|
||||
- Project Cars 2 (untested)
|
||||
**One-Line Installation:**
|
||||
```bash
|
||||
curl -fsSL https://raw.githubusercontent.com/Spacefreak18/monocoque/master/install.sh | bash
|
||||
```
|
||||
***AUR Package following git master:***
|
||||
```https://aur.archlinux.org/packages/monocoque-git```
|
||||
|
||||
## Dependencies
|
||||
**Or download and review first:**
|
||||
```bash
|
||||
wget https://raw.githubusercontent.com/Spacefreak18/monocoque/master/install.sh
|
||||
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
|
||||
monocoque-manager
|
||||
```
|
||||
|
||||
**Supported Games**
|
||||
[Supported Sims](https://spacefreak18.github.io/simapi/supportedsims)
|
||||
***please note on Linux some titles will require a compatibility exe from simshmbridge to be setup. Please follow the linked Documentation
|
||||
for installation instructions***
|
||||
|
||||
|
||||
## Building
|
||||
|
||||
### Dependencies (static dependencies are linked as to show their respective copyright and licenses)
|
||||
- libserialport - arduino serial devices
|
||||
- hidapi - usb hid devices
|
||||
- hidapi - usb hid devices (hidraw)
|
||||
- portaudio - sound devices (haptic bass shakers)
|
||||
- libpulse - sound devices (haptic bass shakers)
|
||||
- libuv base event loop
|
||||
@@ -46,14 +79,18 @@ Cross Platform device manager for driving and flight simulators, for use with co
|
||||
- argtable2
|
||||
- libconfig
|
||||
- xdg-basedir
|
||||
- [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.
|
||||
- lua
|
||||
- libproc2
|
||||
- [simapi](https://github.com/spacefreak18/simapi)
|
||||
- [slog](https://github.com/kala13x/slog) (static)
|
||||
- [nappgui](https://github.com/frang75/nappgui_src) (static) (for GUI)
|
||||
(sorta optional)
|
||||
- [simshmbridge](https://github.com/spacefreak18/simshmbridge) - for sims that need shared memory mapping like AC and Project Cars related.
|
||||
|
||||
```
|
||||
pacman -Syu git cmake pulse-native-provider libxdg-basedir libserialport libconfig libuv argtable hidapi
|
||||
pacman -Syu git cmake pulse-native-provider libxdg-basedir libserialport libconfig libuv argtable hidapi lua libproc2
|
||||
```
|
||||
|
||||
## Building
|
||||
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:
|
||||
```
|
||||
git submodule sync --recursive
|
||||
@@ -67,74 +104,17 @@ cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
to use the pulseaudio backend use this cmake command
|
||||
```
|
||||
cmake -DUSE_PULSEAUDIO=YES ..
|
||||
```
|
||||
## Bass Shaker Sound Devices
|
||||
|
||||
When using pulseaudio it is necesarry to provide a devid in the configuration. This command should list available sound cards with the "Name" being the "devid" needed in the monocoque config.
|
||||
```
|
||||
pactl list sinks | grep -E -i 'index:|name:' -A 4
|
||||
```
|
||||
One can generate sample sine waves at specific frequency on a specific channel on a specific sound card with this command (change -d to the Name of your desired target card and change 440 to any frequency)
|
||||
```
|
||||
ffmpeg -f lavfi -i "sine=f=440" -af "pan=7.1|c1=c0" -f wav pipe:1 | paplay --no-remap --no-remix -d alsa_output.pci-0000_00_1b.0.analog-stereo --volume=65536 -n "Monocoque" --stream-name="Haptic Test"
|
||||
```
|
||||
(BE CAREFUL!!! AS THIS SETS THE MAXIMUM STREAM VOLUME!!! the -n and --stream-name are optional but it helps you identify the stream in pavucontrol)
|
||||
The channel map from the pactl command is the order of channels. Change c1 in this above command to the desired output channel.
|
||||
|
||||
The effects generated by monocoque should match the effects generated by this ffmpeg command. The frequency will differ slightly due to having to [fit in the buffer size](https://stackoverflow.com/questions/40078417/how-to-calculate-minimum-cycles-of-sine-wave-to-have-integer-n-cycles-in-a-buffe)
|
||||
(monocoque lowers the target frequency until it fits in the audio buffer).
|
||||
|
||||
## Using Arduino Devices
|
||||
|
||||
Currently Monocoque supports simwind and shiftlights through the included arduino sketches which have been tested on Uno boards. The simwind controller requires a Motor shield.
|
||||
|
||||
There are included Makefiles for each controller. For now, the makefiles expect the device to be attached at /dev/ttyACM0. So unplug both controllers, and then plug in just the
|
||||
controller you're updating to ensure the correct controller is at /dev/ttyACM0.
|
||||
|
||||
To compile and upload these sketches, the Makefiles use arduino-cli. Unfortunately it seems some distributions such as debian do not include this in the repositories. If this is
|
||||
the case follow the install instructions here:
|
||||
```
|
||||
https://arduino.github.io/arduino-cli/0.35/installation/
|
||||
```
|
||||
You may have to download the core libraries, it will prompt you to do so if you do not have them and you go further
|
||||
```
|
||||
arduino-cli core install arduino:avr
|
||||
```
|
||||
Then for shiftlights navigate to included shiftlight directory ( be sure only the shiftlight controller is plugged into the machine and is available at /dev/ttyACM0 ) and
|
||||
|
||||
```
|
||||
arduino-cli lib install FastLED
|
||||
make
|
||||
```
|
||||
Then for simwind navigate to the included simwind directory ( be sure only the simwind controller is plugged into the machine and is available at /dev/ttyACM0 ) and
|
||||
```
|
||||
ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library.git
|
||||
ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/adafruit/Adafruit_BusIO.git
|
||||
make
|
||||
```
|
||||
|
||||
### Uploading sketch to Arduino Uno
|
||||
```
|
||||
cd ../src/arduino/{simwind/shiftlights/simhaptic} # Depending on the controller you have.
|
||||
make # Make sure serial connection is the same as on the host pc and it have the right group permission to access the device without root
|
||||
```
|
||||
|
||||
### SimHaptic Ardunio Motor Connection
|
||||
- Acc Pedal Motor to be connected to M1
|
||||
- Brake Pedal Motor to be connected to M3
|
||||
- you can actually connect the motors how you wish, but you'd have to make the appropriate changes to the config and to the arduino sketch.
|
||||
|
||||
## Getting car tyre diameter for rumbles to work
|
||||
- User needs to start monocoque and drive the new car straight at 70 kmph and then stop steering, acc or brake input
|
||||
## User Setup Guide
|
||||
See the dedicated [How To](HOW-TO-USE.md) for detailed instructions to set up and run 'monocoque`
|
||||
|
||||
## Testing
|
||||
```
|
||||
./monocoque test -vv # Make sure that ~/.config/monocque/monocoque.config only contains the devices you have connected.
|
||||
```
|
||||
|
||||
### Logs file location
|
||||
`~/.cache/monocoque/*.log`
|
||||
|
||||
### Static Analysis
|
||||
```
|
||||
mkdir build; cd build
|
||||
@@ -149,15 +129,10 @@ make # Make sure serial connection is the same as on the host pc and it have th
|
||||
valgrind -v --leak-check=full --show-leak-kinds=all --suppressions=../.valgrindrc ./monocoque play
|
||||
```
|
||||
|
||||
### Logs file location
|
||||
`~/.cache/monocoque/*.log`
|
||||
|
||||
## Join the Discussion
|
||||
[Sim Racing Matrix Space](https://matrix.to/#/#simracing:matrix.org)
|
||||
|
||||
## ToDo
|
||||
- add option to specify frame rate
|
||||
- add ability to set frame rate per effect
|
||||
- add frequency cap (low pass filter) to sound haptic effects
|
||||
- add road and kerb sound haptic effects
|
||||
- windows port
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
-- start led, end led, color
|
||||
-- set_led_range_to_color(1, 5, YELLOW);
|
||||
|
||||
-- led, color
|
||||
-- set_led_to_color(3, ORANGE);
|
||||
|
||||
-- current colors
|
||||
-- RED
|
||||
-- GREEN
|
||||
-- BLUE
|
||||
-- YELLOW
|
||||
-- ORANGE
|
||||
|
||||
if simdata.rpm >= simdata.maxrpm-500 then
|
||||
set_led_range_to_color(1, 6, RED)
|
||||
elseif simdata.rpm >= 4000 then
|
||||
set_led_range_to_color(1, 4, YELLOW)
|
||||
elseif simdata.rpm >= 3000 then
|
||||
set_led_range_to_color(1, 3, GREEN)
|
||||
elseif simdata.rpm >= 2000 then
|
||||
set_led_range_to_rgb_color(1, 2, 0, 255, 0)
|
||||
-- set_led_to_rgb_color also available
|
||||
elseif simdata.rpm >= 1000 then
|
||||
set_led_to_color(1, GREEN)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
-- configuration
|
||||
-- set these accordingly
|
||||
right_leds_start = 7
|
||||
right_num_leds = 42
|
||||
left_leds_start = 49
|
||||
left_num_leds = 42
|
||||
--
|
||||
|
||||
max_radius = 10 -- radius is hardcoded in simapi
|
||||
proxcars = simdata.proxcars -- also hard coded in simapi
|
||||
|
||||
rightsideset = false
|
||||
leftsideset = false
|
||||
|
||||
-- right side
|
||||
litleds = 0
|
||||
i = 1
|
||||
while(i <= proxcars and rightsideset == false) do
|
||||
if simdata.pd[i].theta > 40 and simdata.pd[i].theta < 130 then
|
||||
dist = math.abs(90 - simdata.pd[i].theta)
|
||||
perct = (90 - dist)/90
|
||||
litleds = math.ceil(perct * right_num_leds)
|
||||
|
||||
color_perct = simdata.pd[i].radius/10
|
||||
yellow = math.floor(color_perct * 255)
|
||||
local rgb = (255 << 16) | (yellow << 8) | (0 << 0)
|
||||
if simdata.pd[1].theta >= 90 then
|
||||
-- car is behind
|
||||
set_led_range_to_rgb_color(right_leds_start, right_leds_start + litleds, rgb)
|
||||
else
|
||||
set_led_range_to_rgb_color(right_leds_start + (right_num_leds - litleds), right_leds_start + right_num_leds, rgb)
|
||||
end
|
||||
rightsideset = true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
-- left side
|
||||
litleds = 0
|
||||
i = 1
|
||||
while(i <= proxcars and leftsideset == false) do
|
||||
if simdata.pd[i].theta > 230 and simdata.pd[i].theta < 320 then
|
||||
dist = math.abs(270 - simdata.pd[1].theta)
|
||||
perct = (90 - dist)/90
|
||||
litleds = math.ceil(perct * left_num_leds)
|
||||
|
||||
color_perct = simdata.pd[i].radius/10
|
||||
yellow = math.floor(color_perct * 255)
|
||||
local rgb = (255 << 16) | (yellow << 8) | (0 << 0)
|
||||
if simdata.pd[1].theta <= 270 then
|
||||
-- car is behind
|
||||
set_led_range_to_rgb_color(left_leds_start, left_leds_start + litleds, rgb)
|
||||
else
|
||||
set_led_range_to_rgb_color(left_leds_start + (left_num_leds - litleds), left_leds_start + left_num_leds, rgb)
|
||||
end
|
||||
leftsideset = true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Message = simdata.velocity .. ";" .. simdata.gear .. ";" .. simdata.rpm .. ";"
|
||||
+246
-68
@@ -1,68 +1,246 @@
|
||||
configs = ({
|
||||
sim = 0;
|
||||
car = "default";
|
||||
devices = ( { device = "USB";
|
||||
type = "Tachometer";
|
||||
devid = "98FD:83AC";
|
||||
subtype = "Revburner";
|
||||
granularity = 2;
|
||||
config = "~/.config/monocoque/revburner15000.xml"; },
|
||||
{ device = "Sound";
|
||||
effect = "Engine";
|
||||
devid = "alsa_output.usb-Generic_USB2.0_Device_20170726905959-00.analog-stereo";
|
||||
pan = 1;
|
||||
volume = 90;
|
||||
frequency = 27; },
|
||||
{ device = "Sound";
|
||||
effect = "Gear"
|
||||
devid = "alsa_output.usb-Generic_USB2.0_Device_20170726905959-00.analog-stereo";
|
||||
pan = 1;
|
||||
duration = .25;
|
||||
volume = 100;
|
||||
frequency = 27; },
|
||||
{ device = "USB";
|
||||
type = "Haptic";
|
||||
subtype = "ClubSportElitePedalsV3";
|
||||
effect = "ABS";
|
||||
tyre = "ALL";
|
||||
threshold = 0.05; },
|
||||
{ device = "USB";
|
||||
type = "Haptic";
|
||||
subtype = "ClubSportElitePedalsV3";
|
||||
effect = "Slip";
|
||||
tyre = "REARS";
|
||||
threshold = 0.75; },
|
||||
{ device = "USB";
|
||||
type = "Haptic";
|
||||
subtype = "ClubSportElitePedalsV3";
|
||||
effect = "Lock";
|
||||
tyre = "ALL";
|
||||
threshold = 0.75; },
|
||||
{ device = "Serial";
|
||||
type = "SimWind";
|
||||
config = "None";
|
||||
devpath = "/dev/ttyACM1"; },
|
||||
{ device = "Serial";
|
||||
type = "ShiftLights";
|
||||
config = "None";
|
||||
devpath = "/dev/ttyACM0"; },
|
||||
{ device = "Serial";
|
||||
type = "Haptic";
|
||||
effect = "TyreSlip";
|
||||
tyre = "ALL"; // motor m1 connected to throttle
|
||||
motors = 0;
|
||||
devpath = "/dev/ttyACM0"; },
|
||||
{ device = "Serial";
|
||||
type = "Haptic";
|
||||
effect = "TyreLock";
|
||||
tyre = "ALL"; // motor m3 connected to brake;
|
||||
motors = 2;
|
||||
devpath = "/dev/ttyACM0"; },
|
||||
{ device = "Serial";
|
||||
type = "Haptic"
|
||||
effect = "ABS";
|
||||
tyre = "ALL"; // this will have to be documented, this tells the code to spin both motors
|
||||
motors = 8;
|
||||
devpath = "/dev/ttyACM0";}
|
||||
);
|
||||
});
|
||||
configs = (
|
||||
{
|
||||
sim = "default";
|
||||
// one can also specify sim by using the "short-name" for example "ac". also, "acc", "ace", "ams2", "et", "at" and "rf2"
|
||||
//sim = "ac";
|
||||
car = "default";
|
||||
devices = (
|
||||
{
|
||||
device = "USB";
|
||||
type = "Tachometer";
|
||||
devid = "98FD:83AC";
|
||||
subtype = "Revburner";
|
||||
granularity = 2;
|
||||
config = "~/.config/monocoque/revburner15000.xml";
|
||||
},
|
||||
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "Engine";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 3;
|
||||
fps = 60;
|
||||
threshold = 0.2;
|
||||
channels = 8;
|
||||
volume = 70;
|
||||
modulation = "frequency";
|
||||
frequency = 17;
|
||||
frequencyMax = 37;
|
||||
noise = 10; // additive noise in Hz
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "Gear"
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 3;
|
||||
fps = 60;
|
||||
threshold = 0.2;
|
||||
channels = 8;
|
||||
duration = .6;
|
||||
volume = 100;
|
||||
frequency = 15;
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreSlip";
|
||||
tyre = "RearLeft";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 4;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
fps = 60;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreSlip";
|
||||
tyre = "RearRight";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 5;
|
||||
fps = 60;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreSlip";
|
||||
tyre = "FrontLeft";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 0;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreSlip";
|
||||
tyre = "FrontRight";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 1;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
|
||||
|
||||
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreLock";
|
||||
tyre = "RearLeft";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 4;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreLock";
|
||||
tyre = "RearRight";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 5;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
modulation = "frequency";
|
||||
volume = 100;
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreLock";
|
||||
tyre = "FrontLeft";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 0;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "TyreLock";
|
||||
tyre = "FrontRight";
|
||||
devid = "alsa_output.pci-0000_0d_00.0.analog-surround-71";
|
||||
pan = 1;
|
||||
channels = 8;
|
||||
threshold = 0.2;
|
||||
volume = 100;
|
||||
modulation = "frequency";
|
||||
frequency = 30;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
|
||||
{
|
||||
device = "USB";
|
||||
type = "Haptic";
|
||||
subtype = "CSLELITEV3PEDALS";
|
||||
//devpath = "/sys/module/hid_fanatec/drivers/hid:fanatec/0003:0EB7:183B.0002/rumble";
|
||||
devpath = "/sys/module/hid_fanatec/drivers/hid:ftec_csl_elite/0003:0EB7:183B.0002/rumble";
|
||||
effect = "ABS";
|
||||
tyre = "ALL";
|
||||
threshold = 0.2;
|
||||
value0 = 0;
|
||||
value1 = 16776960;
|
||||
},
|
||||
{
|
||||
device = "USB";
|
||||
type = "Haptic";
|
||||
subtype = "CSLELITEV3PEDALS";
|
||||
//devpath = "/sys/module/hid_fanatec/drivers/hid:fanatec/0003:0EB7:183B.0002/rumble";
|
||||
devpath = "/sys/module/hid_fanatec/drivers/hid:ftec_csl_elite/0003:0EB7:183B.0002/rumble";
|
||||
effect = "Slip";
|
||||
tyre = "ALL";
|
||||
threshold = 0.2;
|
||||
value0 = 0;
|
||||
value1 = 16711680;
|
||||
},
|
||||
{
|
||||
device = "USB";
|
||||
type = "Haptic";
|
||||
subtype = "CSLELITEV3PEDALS";
|
||||
//devpath = "/sys/module/hid_fanatec/drivers/hid:fanatec/0003:0EB7:183B.0002/rumble";
|
||||
devpath = "/sys/module/hid_fanatec/drivers/hid:ftec_csl_elite/0003:0EB7:183B.0002/rumble";
|
||||
effect = "Lock";
|
||||
tyre = "ALL";
|
||||
threshold = 0.2;
|
||||
value0 = 0;
|
||||
value1 = 65280;
|
||||
},
|
||||
|
||||
{
|
||||
device = "Serial";
|
||||
type = "Haptic";
|
||||
effect = "TyreSlip";
|
||||
tyre = "ALL"; // motor m1 connected to throttle
|
||||
motors = 0;
|
||||
devpath = "/dev/ttyACM0";
|
||||
},
|
||||
{
|
||||
device = "Serial";
|
||||
type = "Haptic";
|
||||
effect = "TyreLock";
|
||||
tyre = "ALL"; // motor m3 connected to brake;
|
||||
motors = 2;
|
||||
devpath = "/dev/ttyACM0";
|
||||
},
|
||||
{
|
||||
device = "Serial";
|
||||
type = "Haptic"
|
||||
effect = "ABS";
|
||||
tyre = "ALL"; // this will have to be documented, this tells the code to spin both motors
|
||||
motors = 8;
|
||||
devpath = "/dev/ttyACM0";
|
||||
},
|
||||
{
|
||||
device = "Serial";
|
||||
type = "SimWind";
|
||||
config = "None";
|
||||
baud = 115200;
|
||||
devpath = "/dev/simdev1";
|
||||
fanpower = 0.6;
|
||||
},
|
||||
|
||||
{
|
||||
device = "Serial";
|
||||
type = "SimWind";
|
||||
config = "None";
|
||||
baud = 115200;
|
||||
devpath = "/dev/simdev1";
|
||||
fanpower = 0.6;
|
||||
},
|
||||
|
||||
{
|
||||
device = "Serial";
|
||||
type = "Simleds";
|
||||
numleds = 6;
|
||||
startled = 2;
|
||||
endled = 5;
|
||||
config = "~/git/monocoque/conf/rpms_and_radar.lua"
|
||||
baud = 115200;
|
||||
devpath = "/dev/simdev0";
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
-- from simapi.h
|
||||
-- SIMAPI_FLAG_GREEN = 0,
|
||||
-- SIMAPI_FLAG_YELLOW = 1,
|
||||
-- SIMAPI_FLAG_RED = 2,
|
||||
-- SIMAPI_FLAG_CHEQUERED = 3,
|
||||
-- SIMAPI_FLAG_BLUE = 4,
|
||||
-- SIMAPI_FLAG_WHITE = 5,
|
||||
-- SIMAPI_FLAG_BLACK = 6,
|
||||
-- SIMAPI_FLAG_BLACK_WHITE = 7,
|
||||
-- SIMAPI_FLAG_BLACK_ORANGE = 8,
|
||||
-- SIMAPI_FLAG_ORANGE = 9
|
||||
|
||||
led_clear_all()
|
||||
|
||||
if simdata.rpm > 0 and simdata.maxrpm > 0 then
|
||||
rpmmargin = .05*simdata.maxrpm;
|
||||
rpminterval = (simdata.maxrpm-rpmmargin) / 14;
|
||||
|
||||
litleds = 0
|
||||
for i = 1,14 do
|
||||
if simdata.rpm >= (rpminterval * i) then
|
||||
litleds = i;
|
||||
end
|
||||
end
|
||||
|
||||
color = GREEN
|
||||
if litleds > 5 and litleds < 12 then
|
||||
color = YELLOW
|
||||
end
|
||||
if litleds >= 12 then
|
||||
color = RED
|
||||
end
|
||||
set_led_range_to_color(59, 59+litleds, color)
|
||||
end
|
||||
|
||||
if simdata.playerflag == 0 then
|
||||
set_led_range_to_color(4, 7, GREEN)
|
||||
end
|
||||
|
||||
|
||||
if simdata.playerflag == 1 then
|
||||
set_led_range_to_color(4, 7, YELLOW)
|
||||
end
|
||||
|
||||
|
||||
if simdata.playerflag == 4 then
|
||||
set_led_range_to_color(4, 7, BLUE)
|
||||
end
|
||||
@@ -0,0 +1,55 @@
|
||||
-- from simapi.h
|
||||
-- SIMAPI_FLAG_GREEN = 0,
|
||||
-- SIMAPI_FLAG_YELLOW = 1,
|
||||
-- SIMAPI_FLAG_RED = 2,
|
||||
-- SIMAPI_FLAG_CHEQUERED = 3,
|
||||
-- SIMAPI_FLAG_BLUE = 4,
|
||||
-- SIMAPI_FLAG_WHITE = 5,
|
||||
-- SIMAPI_FLAG_BLACK = 6,
|
||||
-- SIMAPI_FLAG_BLACK_WHITE = 7,
|
||||
-- SIMAPI_FLAG_BLACK_ORANGE = 8,
|
||||
-- SIMAPI_FLAG_ORANGE = 9
|
||||
|
||||
if simdata.rpm > 0 and simdata.maxrpm > 0 then
|
||||
rpmmargin = .05*simdata.maxrpm;
|
||||
rpminterval = (simdata.maxrpm-rpmmargin) / 6;
|
||||
|
||||
litleds = 0
|
||||
for i = 1,6 do
|
||||
if simdata.rpm >= (rpminterval * i) then
|
||||
litleds = i;
|
||||
end
|
||||
end
|
||||
|
||||
color = GREEN
|
||||
if litleds > 3 and litleds < 6 then
|
||||
color = YELLOW
|
||||
end
|
||||
if litleds >= 6 then
|
||||
color = RED
|
||||
end
|
||||
if litleds >= 6 then
|
||||
|
||||
if simdata.mtick % 2 == 0 then
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
else
|
||||
led_clear_all()
|
||||
end
|
||||
else
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
end
|
||||
end
|
||||
|
||||
if simdata.playerflag == 0 then
|
||||
set_led_range_to_color(7, 48, GREEN)
|
||||
end
|
||||
|
||||
|
||||
if simdata.playerflag == 1 then
|
||||
set_led_range_to_color(7, 48, YELLOW)
|
||||
end
|
||||
|
||||
|
||||
if simdata.playerflag == 4 then
|
||||
set_led_range_to_color(7, 48, BLUE)
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
-- configuration
|
||||
-- set these accordingly
|
||||
right_leds_start = 7
|
||||
right_num_leds = 42
|
||||
left_leds_start = 49
|
||||
left_num_leds = 42
|
||||
--
|
||||
|
||||
max_radius = 10 -- radius is hardcoded in simapi
|
||||
proxcars = simdata.proxcars -- also hard coded in simapi
|
||||
|
||||
rightsideset = false
|
||||
leftsideset = false
|
||||
|
||||
-- right side
|
||||
litleds = 0
|
||||
i = 1
|
||||
while(i <= proxcars and rightsideset == false) do
|
||||
if simdata.pd[i].theta > 40 and simdata.pd[i].theta < 130 then
|
||||
dist = math.abs(90 - simdata.pd[i].theta)
|
||||
perct = (90 - dist)/90
|
||||
litleds = math.ceil(perct * right_num_leds)
|
||||
|
||||
color_perct = simdata.pd[i].radius/10
|
||||
yellow = math.floor(color_perct * 255)
|
||||
local rgb = (255 << 16) | (yellow << 8) | (0 << 0)
|
||||
if simdata.pd[1].theta >= 90 then
|
||||
-- car is behind
|
||||
set_led_range_to_rgb_color(right_leds_start, right_leds_start + litleds, rgb)
|
||||
else
|
||||
set_led_range_to_rgb_color(right_leds_start + (right_num_leds - litleds), right_leds_start + right_num_leds, rgb)
|
||||
end
|
||||
rightsideset = true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
-- left side
|
||||
litleds = 0
|
||||
i = 1
|
||||
while(i <= proxcars and leftsideset == false) do
|
||||
if simdata.pd[i].theta > 230 and simdata.pd[i].theta < 320 then
|
||||
dist = math.abs(270 - simdata.pd[1].theta)
|
||||
perct = (90 - dist)/90
|
||||
litleds = math.ceil(perct * left_num_leds)
|
||||
|
||||
color_perct = simdata.pd[i].radius/10
|
||||
yellow = math.floor(color_perct * 255)
|
||||
local rgb = (255 << 16) | (yellow << 8) | (0 << 0)
|
||||
if simdata.pd[1].theta <= 270 then
|
||||
-- car is behind
|
||||
set_led_range_to_rgb_color(left_leds_start, left_leds_start + litleds, rgb)
|
||||
else
|
||||
set_led_range_to_rgb_color(left_leds_start + (left_num_leds - litleds), left_leds_start + left_num_leds, rgb)
|
||||
end
|
||||
leftsideset = true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
rpm_leds = 6
|
||||
-- rpm stuff
|
||||
if simdata.rpm > 0 and simdata.maxrpm > 0 then
|
||||
rpmmargin = .05*simdata.maxrpm;
|
||||
rpminterval = (simdata.maxrpm-rpmmargin) / rpm_leds;
|
||||
|
||||
litleds = 0
|
||||
for i = 1,6 do
|
||||
if simdata.rpm >= (rpminterval * i) then
|
||||
litleds = i;
|
||||
end
|
||||
end
|
||||
|
||||
color = GREEN
|
||||
if litleds > rpm_leds/2 and litleds < rpm_leds then
|
||||
color = YELLOW
|
||||
end
|
||||
if litleds >= rpm_leds then
|
||||
color = RED
|
||||
end
|
||||
if litleds >= rpm_leds then
|
||||
|
||||
if simdata.mtick % 2 == 0 then
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
else
|
||||
led_clear_range(1, rpm_leds)
|
||||
end
|
||||
else
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
end
|
||||
end
|
||||
Executable
+554
@@ -0,0 +1,554 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Monocoque Universal Installer
|
||||
# Works on: Arch, Debian/Ubuntu, Fedora, and other major distros
|
||||
# Version: 1.0.0
|
||||
|
||||
SCRIPT_VERSION="1.0.0"
|
||||
INSTALL_DIR="${MONOCOQUE_INSTALL_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/monocoque}"
|
||||
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||
BIN_DIR="${HOME}/.local/bin"
|
||||
|
||||
# Color output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
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 Universal Installer v${SCRIPT_VERSION} ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Detect distribution
|
||||
detect_distro() {
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
DISTRO=$ID
|
||||
DISTRO_VERSION=$VERSION_ID
|
||||
DISTRO_LIKE=$ID_LIKE
|
||||
elif [ -f /etc/arch-release ]; then
|
||||
DISTRO="arch"
|
||||
else
|
||||
DISTRO="unknown"
|
||||
fi
|
||||
|
||||
# Normalize Arch-based distributions
|
||||
if [[ "$DISTRO_LIKE" == *"arch"* ]] || [[ "$DISTRO" == "manjaro" ]] || [[ "$DISTRO" == "garuda" ]] || [[ "$DISTRO" == "endeavouros" ]]; then
|
||||
log_info "Detected distribution: $DISTRO (Arch-based)"
|
||||
DISTRO="arch"
|
||||
else
|
||||
log_info "Detected distribution: $DISTRO"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
check_root() {
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
log_error "Please do not run this script as root"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check for required commands
|
||||
check_requirements() {
|
||||
local missing_commands=()
|
||||
|
||||
for cmd in git cmake make gcc; do
|
||||
if ! command -v $cmd &> /dev/null; then
|
||||
missing_commands+=($cmd)
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing_commands[@]} -ne 0 ]; then
|
||||
log_error "Missing required commands: ${missing_commands[*]}"
|
||||
log_info "Please install them first"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Install dependencies based on distro
|
||||
install_dependencies() {
|
||||
log_info "Installing dependencies for $DISTRO..."
|
||||
|
||||
case $DISTRO in
|
||||
arch|manjaro)
|
||||
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
|
||||
log_info "Using yay to check for AUR packages..."
|
||||
echo ""
|
||||
echo "You can install monocoque from AUR instead:"
|
||||
echo " yay -S simapi-git simd-git monocoque-git"
|
||||
echo ""
|
||||
read -p "Install from AUR? (recommended) [Y/n]: " use_aur
|
||||
|
||||
if [[ ! $use_aur =~ ^[Nn]$ ]]; then
|
||||
log_info "Installing from AUR..."
|
||||
yay -S --needed simapi-git simd-git monocoque-git
|
||||
|
||||
# Still need simshmbridge
|
||||
log_info "Building simshmbridge (not in AUR)..."
|
||||
build_simshmbridge_only
|
||||
|
||||
# Setup configs and services
|
||||
setup_configs
|
||||
setup_systemd_services
|
||||
# create_launcher_scripts uses SCRIPT_DIR which is set in main()
|
||||
create_launcher_scripts
|
||||
|
||||
log_success "Installation complete (AUR method)!"
|
||||
print_next_steps
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
log_info "Installing build dependencies with pacman..."
|
||||
sudo pacman -S --needed --noconfirm $deps
|
||||
;;
|
||||
|
||||
ubuntu|debian|linuxmint|pop)
|
||||
local deps="build-essential git cmake libyder-dev libuv1-dev libargtable2-dev libserialport-dev libconfig-dev libhidapi-dev lua5.3 liblua5.3-dev libxdg-basedir-dev mingw-w64"
|
||||
|
||||
log_info "Updating package lists..."
|
||||
sudo apt-get update
|
||||
|
||||
log_info "Installing build dependencies..."
|
||||
sudo apt-get install -y $deps
|
||||
;;
|
||||
|
||||
fedora|rhel|centos)
|
||||
local deps="git cmake gcc gcc-c++ yder-devel libuv-devel argtable-devel libserialport-devel libconfig-devel hidapi-devel lua-devel libxdg-basedir-devel mingw64-gcc"
|
||||
|
||||
log_info "Installing build dependencies..."
|
||||
sudo dnf install -y $deps
|
||||
;;
|
||||
|
||||
opensuse*)
|
||||
local deps="git cmake gcc gcc-c++ libyder-devel libuv-devel argtable-devel libserialport-devel libconfig-devel hidapi-devel lua-devel libxdg-basedir-devel mingw64-gcc"
|
||||
|
||||
log_info "Installing build dependencies..."
|
||||
sudo zypper install -y $deps
|
||||
;;
|
||||
|
||||
*)
|
||||
log_error "Unsupported distribution: $DISTRO"
|
||||
log_info "Please install dependencies manually and try again"
|
||||
log_info "Required: git, cmake, gcc, yder, libuv, argtable, libserialport, libconfig, hidapi, lua, libxdg-basedir, mingw-gcc"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
log_success "Dependencies installed"
|
||||
}
|
||||
|
||||
# Clone repositories
|
||||
clone_repositories() {
|
||||
log_info "Creating installation directory: $INSTALL_DIR"
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cd "$INSTALL_DIR"
|
||||
|
||||
# Clone monocoque
|
||||
if [ ! -d "monocoque" ]; then
|
||||
log_info "Cloning monocoque..."
|
||||
git clone https://github.com/Spacefreak18/monocoque.git
|
||||
cd monocoque
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
else
|
||||
log_info "monocoque already cloned, updating..."
|
||||
cd monocoque
|
||||
git pull
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
cd "$INSTALL_DIR"
|
||||
|
||||
# Clone simapi
|
||||
if [ ! -d "simapi" ]; then
|
||||
log_info "Cloning simapi..."
|
||||
git clone https://github.com/Spacefreak18/simapi.git
|
||||
else
|
||||
log_info "simapi already cloned, updating..."
|
||||
cd simapi
|
||||
git pull
|
||||
fi
|
||||
cd "$INSTALL_DIR"
|
||||
|
||||
# Clone simshmbridge
|
||||
if [ ! -d "simshmbridge" ]; then
|
||||
log_info "Cloning simshmbridge..."
|
||||
git clone https://github.com/spacefreak18/simshmbridge.git
|
||||
cd simshmbridge
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
else
|
||||
log_info "simshmbridge already cloned, updating..."
|
||||
cd simshmbridge
|
||||
git pull
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
log_success "Repositories cloned/updated"
|
||||
}
|
||||
|
||||
# Build simapi
|
||||
build_simapi() {
|
||||
log_info "Building simapi..."
|
||||
cd "$INSTALL_DIR/simapi"
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DINSTALL_SYSTEMD_SERVICE=off ..
|
||||
make -j$(nproc)
|
||||
|
||||
log_info "Installing simapi library..."
|
||||
sudo make install
|
||||
|
||||
# Update library cache
|
||||
sudo ldconfig 2>/dev/null || true
|
||||
|
||||
log_success "simapi built and installed"
|
||||
}
|
||||
|
||||
# Build simd
|
||||
build_simd() {
|
||||
log_info "Building simd..."
|
||||
cd "$INSTALL_DIR/simapi/simd"
|
||||
|
||||
rm -rf build
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
|
||||
log_success "simd built"
|
||||
}
|
||||
|
||||
# Build simshmbridge
|
||||
build_simshmbridge() {
|
||||
log_info "Building simshmbridge..."
|
||||
cd "$INSTALL_DIR/simshmbridge"
|
||||
|
||||
make clean || true
|
||||
make -j$(nproc)
|
||||
|
||||
log_success "simshmbridge built"
|
||||
}
|
||||
|
||||
build_simshmbridge_only() {
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cd "$INSTALL_DIR"
|
||||
|
||||
if [ ! -d "simshmbridge" ]; then
|
||||
log_info "Cloning simshmbridge..."
|
||||
git clone https://github.com/spacefreak18/simshmbridge.git
|
||||
cd simshmbridge
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
build_simshmbridge
|
||||
}
|
||||
|
||||
# Build monocoque
|
||||
build_monocoque() {
|
||||
log_info "Building monocoque..."
|
||||
cd "$INSTALL_DIR/monocoque"
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
|
||||
log_success "monocoque built"
|
||||
}
|
||||
|
||||
# Setup configuration files
|
||||
setup_configs() {
|
||||
log_info "Setting up configuration files..."
|
||||
|
||||
# simd config
|
||||
mkdir -p "$CONFIG_DIR/simd"
|
||||
if [ ! -f "$CONFIG_DIR/simd/simd.config" ]; then
|
||||
if [ -f "$INSTALL_DIR/simapi/simd/conf/simd.config" ]; then
|
||||
cp "$INSTALL_DIR/simapi/simd/conf/simd.config" "$CONFIG_DIR/simd/simd.config"
|
||||
log_success "Created simd config"
|
||||
fi
|
||||
else
|
||||
log_info "simd config already exists, skipping"
|
||||
fi
|
||||
|
||||
# monocoque config
|
||||
mkdir -p "$CONFIG_DIR/monocoque"
|
||||
if [ ! -f "$CONFIG_DIR/monocoque/monocoque.config" ]; then
|
||||
cat > "$CONFIG_DIR/monocoque/monocoque.config" << 'EOF'
|
||||
configs = (
|
||||
{
|
||||
sim = "default";
|
||||
car = "default";
|
||||
devices = (
|
||||
// Add your devices here
|
||||
// Example: Serial device (ESP32/Arduino)
|
||||
/*
|
||||
{
|
||||
device = "Serial";
|
||||
type = "Custom";
|
||||
config = "None";
|
||||
baud = 115200;
|
||||
devpath = "/dev/ttyUSB0";
|
||||
},
|
||||
*/
|
||||
|
||||
// Example: Bass shaker
|
||||
/*
|
||||
{
|
||||
device = "Sound";
|
||||
effect = "Engine";
|
||||
devid = "alsa_output.your_device_here";
|
||||
pan = 0;
|
||||
fps = 60;
|
||||
threshold = 0.2;
|
||||
channels = 2;
|
||||
volume = 70;
|
||||
modulation = "frequency";
|
||||
frequency = 17;
|
||||
frequencyMax = 37;
|
||||
},
|
||||
*/
|
||||
);
|
||||
}
|
||||
);
|
||||
EOF
|
||||
log_success "Created monocoque config"
|
||||
else
|
||||
log_info "monocoque config already exists, skipping"
|
||||
fi
|
||||
}
|
||||
|
||||
# Create launcher scripts
|
||||
create_launcher_scripts() {
|
||||
log_info "Creating launcher scripts in $BIN_DIR..."
|
||||
mkdir -p "$BIN_DIR"
|
||||
|
||||
# Find simd binary location
|
||||
local SIMD_BIN=""
|
||||
if [ -f "$INSTALL_DIR/simapi/simd/build/simd" ]; then
|
||||
SIMD_BIN="$INSTALL_DIR/simapi/simd/build/simd"
|
||||
elif command -v simd &> /dev/null; then
|
||||
SIMD_BIN=$(which simd)
|
||||
fi
|
||||
|
||||
# Find monocoque binary location
|
||||
local MONOCOQUE_BIN=""
|
||||
if [ -f "$INSTALL_DIR/monocoque/build/monocoque" ]; then
|
||||
MONOCOQUE_BIN="$INSTALL_DIR/monocoque/build/monocoque"
|
||||
elif command -v monocoque &> /dev/null; then
|
||||
MONOCOQUE_BIN=$(which monocoque)
|
||||
fi
|
||||
|
||||
# start-simd script
|
||||
cat > "$BIN_DIR/start-simd" << EOF
|
||||
#!/bin/bash
|
||||
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64
|
||||
exec $SIMD_BIN -vv "\$@"
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/start-simd"
|
||||
|
||||
# start-monocoque script
|
||||
cat > "$BIN_DIR/start-monocoque" << EOF
|
||||
#!/bin/bash
|
||||
exec $MONOCOQUE_BIN play "\$@"
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/start-monocoque"
|
||||
|
||||
# test-monocoque script
|
||||
cat > "$BIN_DIR/test-monocoque" << EOF
|
||||
#!/bin/bash
|
||||
exec $MONOCOQUE_BIN test -vv "\$@"
|
||||
EOF
|
||||
chmod +x "$BIN_DIR/test-monocoque"
|
||||
|
||||
# monocoque-manager TUI
|
||||
log_info "Looking for monocoque-manager to install..."
|
||||
local MANAGER_INSTALLED=false
|
||||
|
||||
# Use the SCRIPT_DIR exported from main()
|
||||
# Try multiple locations
|
||||
local SEARCH_PATHS=(
|
||||
"$SCRIPT_DIR/monocoque-manager"
|
||||
"$SCRIPT_DIR/tools/monocoque-manager"
|
||||
)
|
||||
|
||||
for MANAGER_PATH in "${SEARCH_PATHS[@]}"; do
|
||||
log_info "Checking: $MANAGER_PATH"
|
||||
if [ -f "$MANAGER_PATH" ]; then
|
||||
log_info "Found monocoque-manager at: $MANAGER_PATH"
|
||||
cp "$MANAGER_PATH" "$BIN_DIR/monocoque-manager"
|
||||
chmod +x "$BIN_DIR/monocoque-manager"
|
||||
log_success "✓ Installed monocoque-manager TUI to $BIN_DIR/monocoque-manager"
|
||||
MANAGER_INSTALLED=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$MANAGER_INSTALLED" = false ]; then
|
||||
log_error "monocoque-manager not found!"
|
||||
log_warn "Searched in: ${SEARCH_PATHS[*]}"
|
||||
log_warn "SCRIPT_DIR was: $SCRIPT_DIR"
|
||||
log_info "Please copy it manually: cp $SCRIPT_DIR/monocoque-manager ~/.local/bin/"
|
||||
fi
|
||||
|
||||
# Check if BIN_DIR is in PATH
|
||||
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
|
||||
log_warn "$BIN_DIR is not in your PATH"
|
||||
log_info "Add this to your shell config:"
|
||||
echo " # For bash/zsh:"
|
||||
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
|
||||
echo ""
|
||||
echo " # For fish:"
|
||||
echo " fish_add_path ~/.local/bin"
|
||||
fi
|
||||
|
||||
log_success "Launcher scripts created"
|
||||
}
|
||||
|
||||
# Setup systemd user services
|
||||
setup_systemd_services() {
|
||||
local SYSTEMD_DIR="$HOME/.config/systemd/user"
|
||||
mkdir -p "$SYSTEMD_DIR"
|
||||
|
||||
log_info "Creating systemd service files..."
|
||||
|
||||
# Find binary locations
|
||||
local SIMD_BIN=""
|
||||
if [ -f "$INSTALL_DIR/simapi/simd/build/simd" ]; then
|
||||
SIMD_BIN="$INSTALL_DIR/simapi/simd/build/simd"
|
||||
elif command -v simd &> /dev/null; then
|
||||
SIMD_BIN=$(which simd)
|
||||
fi
|
||||
|
||||
# simd service
|
||||
cat > "$SYSTEMD_DIR/simd.service" << EOF
|
||||
[Unit]
|
||||
Description=Sim Telemetry Daemon
|
||||
Documentation=https://spacefreak18.github.io/simapi/
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment="LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64"
|
||||
ExecStart=$SIMD_BIN
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
|
||||
log_success "systemd services created"
|
||||
log_info "To enable auto-start on boot:"
|
||||
echo " systemctl --user enable simd.service"
|
||||
echo " systemctl --user start simd.service"
|
||||
}
|
||||
|
||||
# Print next steps
|
||||
print_next_steps() {
|
||||
echo ""
|
||||
echo "╔══════════════════════════════════════════════════════════════════╗"
|
||||
echo "║ Installation Complete! ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
log_success "Monocoque and all components are installed!"
|
||||
echo ""
|
||||
echo "📁 Installation location: $INSTALL_DIR"
|
||||
echo "⚙️ Configuration: $CONFIG_DIR/simd and $CONFIG_DIR/monocoque"
|
||||
echo "🚀 Launcher scripts: $BIN_DIR"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo ""
|
||||
echo "1️⃣ Configure your games (REQUIRED!)"
|
||||
echo " See: https://github.com/Spacefreak18/monocoque/blob/master/HOW-TO-USE.md"
|
||||
echo ""
|
||||
echo "2️⃣ Start the services:"
|
||||
echo " Terminal 1: start-simd"
|
||||
echo " Terminal 2: start-monocoque"
|
||||
echo ""
|
||||
echo " OR enable auto-start:"
|
||||
echo " systemctl --user enable --now simd.service"
|
||||
echo ""
|
||||
echo "3️⃣ Configure your devices:"
|
||||
echo " Edit: $CONFIG_DIR/monocoque/monocoque.config"
|
||||
echo ""
|
||||
echo "4️⃣ Test your setup:"
|
||||
echo " test-monocoque"
|
||||
echo ""
|
||||
echo "🎮 Supported games:"
|
||||
echo " • Assetto Corsa / ACC"
|
||||
echo " • Automobilista 2"
|
||||
echo " • Project Cars 2"
|
||||
echo " • RFactor 2"
|
||||
echo " • Euro/American Truck Simulator"
|
||||
echo ""
|
||||
echo "📚 Documentation: https://spacefreak18.github.io/simapi/"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Main installation flow
|
||||
main() {
|
||||
# Save the directory where this script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
export SCRIPT_DIR
|
||||
|
||||
print_header
|
||||
|
||||
check_root
|
||||
detect_distro
|
||||
check_requirements
|
||||
|
||||
log_info "Starting installation..."
|
||||
echo ""
|
||||
|
||||
install_dependencies
|
||||
clone_repositories
|
||||
|
||||
log_info "Building components (this may take a few minutes)..."
|
||||
build_simapi
|
||||
build_simd
|
||||
build_monocoque
|
||||
build_simshmbridge
|
||||
|
||||
setup_configs
|
||||
create_launcher_scripts
|
||||
setup_systemd_services
|
||||
|
||||
print_next_steps
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,30 @@
|
||||
// Called when starting the arduino (setup method in main sketch)
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
// Called when new data is coming from computer
|
||||
void read()
|
||||
{
|
||||
if(Serial.available())
|
||||
{
|
||||
int speed = Serial.readStringUntil(';').toInt();
|
||||
int gear = Serial.readStringUntil(';').toInt();
|
||||
int rpms = Serial.readStringUntil(';').toInt();
|
||||
//Serial.println("speed: " + String(speed) + " " + "gear: " + String(gear) + " " + "rpms: " + String(rpms));
|
||||
}
|
||||
}
|
||||
|
||||
// Called once per arduino loop, timing can't be predicted,
|
||||
// but it's called between each command sent to the arduino
|
||||
void loop() {
|
||||
read();
|
||||
}
|
||||
|
||||
// Called once between each byte read on arduino,
|
||||
// THIS IS A CRITICAL PATH :
|
||||
// AVOID ANY TIME CONSUMING ROUTINES !!!
|
||||
// PREFER READ OR LOOP METHOS AS MUCH AS POSSIBLE
|
||||
// AVOID ANY INTERRUPTS DISABLE (serial data would be lost!!!)
|
||||
void idle() {
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../monocoque/simulatorapi/simapi/simapi/simdata.h
|
||||
@@ -22,7 +22,7 @@ int effect3 = 0;
|
||||
int effect4 = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
if (!AFMS.begin()) {
|
||||
Serial.println("Could not find Motor Shield. Check wiring.");
|
||||
while (1);
|
||||
|
||||
@@ -14,7 +14,7 @@ SimWindData sd;
|
||||
int velocity = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
if (!AFMS.begin()) {
|
||||
Serial.println("Could not find Motor Shield. Check wiring.");
|
||||
while (1);
|
||||
|
||||
@@ -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,19 +23,31 @@ 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
|
||||
usb/wheels/cammusc5.c
|
||||
usb/wheels/cammusc12.h
|
||||
usb/wheels/cammusc12.c
|
||||
sound/usb_generic_shaker.h
|
||||
sound/usb_generic_shaker.c
|
||||
usb/wheels/gtneo.h
|
||||
usb/wheels/gtneo.c
|
||||
sound/usb_generic_shaker_pulse.c
|
||||
serial/arduino.h
|
||||
serial/arduino.c
|
||||
serial/arduinoledlua.h
|
||||
serial/arduinoledlua.c
|
||||
serial/moza.h
|
||||
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")
|
||||
|
||||
add_library(devices STATIC ${devices_source_files})
|
||||
|
||||
set_property(TARGET devices PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
@@ -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"
|
||||
@@ -21,7 +22,7 @@
|
||||
|
||||
bool hasTyreDiameter(SimData* simdata)
|
||||
{
|
||||
if (simdata->tyrediameter[0] == -1 || simdata->tyrediameter[1] == -1 || simdata->tyrediameter[2] == -1 || simdata->tyrediameter[3] == -1)
|
||||
if (simdata->tyrediameter[0] <= 0 || simdata->tyrediameter[1] <= 0 || simdata->tyrediameter[2] <= 0 || simdata->tyrediameter[3] <= 0)
|
||||
{
|
||||
slogt("failed to find tyre diameter data");
|
||||
return false;
|
||||
@@ -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)
|
||||
{
|
||||
@@ -75,15 +77,15 @@ int loadtyreconfig(SimData* simdata, char* configfile)
|
||||
config_setting_lookup_float(config_car, "tyre1", &tyre1);
|
||||
config_setting_lookup_float(config_car, "tyre2", &tyre2);
|
||||
config_setting_lookup_float(config_car, "tyre3", &tyre3);
|
||||
int found = config_setting_lookup_string(config_car, "sim", &simstr);
|
||||
if(found == 0)
|
||||
{
|
||||
int found = config_setting_lookup_int(config_car, "sim", &sim);
|
||||
}
|
||||
else
|
||||
{
|
||||
sim = simapi_strtogame(simstr);
|
||||
}
|
||||
int found = config_setting_lookup_int(config_car, "sim", &sim);
|
||||
//if(found == CONFIG_FALSE)
|
||||
//{
|
||||
// int found = config_setting_lookup_int(config_car, "sim", &sim);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// sim = simapi_strtogame(simstr);
|
||||
//}
|
||||
|
||||
|
||||
if(simdata->car != NULL && car != NULL)
|
||||
@@ -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)
|
||||
@@ -142,8 +153,8 @@ int savetyreconfig(SimData* simdata, char* configfile)
|
||||
|
||||
setting = config_setting_add(carobject, "car", CONFIG_TYPE_STRING);
|
||||
config_setting_set_string(setting, simdata->car);
|
||||
setting = config_setting_add(carobject, "sim", CONFIG_TYPE_INT);
|
||||
config_setting_set_string(setting, simapi_gametostr(simdata->simexe));
|
||||
setting = config_setting_add(carobject, "sim", CONFIG_TYPE_INT64);
|
||||
config_setting_set_int64(setting, simdata->simexe);
|
||||
setting = config_setting_add(carobject, "tyre0", CONFIG_TYPE_FLOAT);
|
||||
config_setting_set_float(setting, simdata->tyrediameter[0]);
|
||||
setting = config_setting_add(carobject, "tyre1", CONFIG_TYPE_FLOAT);
|
||||
@@ -160,7 +171,7 @@ int savetyreconfig(SimData* simdata, char* configfile)
|
||||
config_destroy(&cfg);
|
||||
}
|
||||
|
||||
slogi("New configuration successfully written to: %s\n", configfile);
|
||||
slogi("New configuration successfully written to: %s for sim %i, car %s\n", configfile, simdata->simexe, simdata->car);
|
||||
|
||||
config_destroy(&cfg);
|
||||
|
||||
@@ -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,89 +262,72 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
|
||||
wheelslip[2] = 0;
|
||||
wheelslip[3] = 0;
|
||||
|
||||
if(simdata->car == NULL)
|
||||
int sim_slip_ratio =0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
slogw("sim is not compatible with wheel and tyre effects, or car and session not loaded.");
|
||||
return 0;
|
||||
}
|
||||
if(simdata->car[0] == '\0')
|
||||
{
|
||||
slogw("sim is not compatible with wheel and tyre effects, or car not loaded.");
|
||||
return 0;
|
||||
sim_slip_ratio = abs(simdata->tyreslipratio[i]);
|
||||
}
|
||||
|
||||
if(sim_slip_ratio == 0)
|
||||
{
|
||||
//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)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
case (EFFECT_TYRELOCK):
|
||||
case (EFFECT_ABSBRAKES):
|
||||
|
||||
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
double Speedms = kmhtoms * simdata->velocity;
|
||||
slogt("attempting wheel slip calculation");
|
||||
if (Speedms > minspeedinms)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
wheelslip[i] = (Speedms - simdata->tyrediameter[i] * simdata->tyreRPS[i] / 2) / Speedms;
|
||||
}
|
||||
}
|
||||
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:
|
||||
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]);
|
||||
}
|
||||
|
||||
slogt("wheel vibration calculation with wheel config set to %i configchecked %i configfile %s car %s", useconfig, *configcheck, configfile, simdata->car);
|
||||
|
||||
switch (effecttype)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
case (EFFECT_TYRELOCK):
|
||||
case (EFFECT_ABSBRAKES):
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(hasTyreDiameter(simdata)==false)
|
||||
{
|
||||
slogt("could not find tyre diameter in config file, attempting to calculate new");
|
||||
getTyreDiameter(simdata);
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
slogi("saving tyre config");
|
||||
error = savetyreconfig(simdata, configfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasTyreDiameter(simdata)==true)
|
||||
{
|
||||
double Speedms = kmhtoms * simdata->velocity;
|
||||
slogt("attempting wheel slip calculation");
|
||||
if (Speedms > minspeedinms)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
wheelslip[i] = (Speedms - simdata->tyrediameter[i] * simdata->tyreRPS[i] / 2) / Speedms;
|
||||
}
|
||||
}
|
||||
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;
|
||||
default:
|
||||
slogd("Unknown effect type");
|
||||
}
|
||||
|
||||
if(simdata->Yvelocity <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(simdata->Zvelocity > 1 || simdata->Zvelocity < -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (effecttype)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
|
||||
|
||||
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
||||
{
|
||||
@@ -386,6 +437,42 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
|
||||
play = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case (EFFECT_SUSPENSION):
|
||||
|
||||
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
||||
{
|
||||
if(simdata->suspension[0] > threshold)
|
||||
{
|
||||
play += simdata->suspension[0] - threshold;
|
||||
slogt("suspension is %f", play);
|
||||
}
|
||||
}
|
||||
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
|
||||
{
|
||||
if(simdata->suspension[1] > threshold)
|
||||
{
|
||||
play += simdata->suspension[1] - threshold;
|
||||
slogt("suspension is %f", play);
|
||||
}
|
||||
}
|
||||
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
|
||||
{
|
||||
if(simdata->suspension[2] > threshold)
|
||||
{
|
||||
play += simdata->suspension[2] - threshold;
|
||||
slogt("suspension is %f", play);
|
||||
}
|
||||
}
|
||||
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
|
||||
{
|
||||
if(simdata->suspension[3] > threshold)
|
||||
{
|
||||
play += simdata->suspension[3] - threshold;
|
||||
slogt("suspension is %f", play);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return play;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,12 +2,36 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "arduino.h"
|
||||
#include "arduinoledlua.h"
|
||||
#include "../serialadapter.h"
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
#define arduino_timeout 5000
|
||||
#define arduino_timeout 9000
|
||||
|
||||
int arduino_check(enum sp_return result)
|
||||
{
|
||||
char* error_message;
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case SP_ERR_ARG:
|
||||
return 1;
|
||||
case SP_ERR_FAIL:
|
||||
error_message = sp_last_error_message();
|
||||
sloge("error: serial write failed: %s", error_message);
|
||||
sp_free_error_message(error_message);
|
||||
case SP_ERR_SUPP:
|
||||
printf("Error: Not supported.\n");
|
||||
case SP_ERR_MEM:
|
||||
printf("Error: Couldn't allocate memory.\n");
|
||||
case SP_OK:
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
int arduino_update(SerialDevice* serialdevice, void* data, size_t size)
|
||||
{
|
||||
@@ -18,8 +42,388 @@ int arduino_update(SerialDevice* serialdevice, void* data, size_t size)
|
||||
return result;
|
||||
}
|
||||
|
||||
// the input event waiting and flushing is the right way to do this
|
||||
// most of the time i'm just "bit blasting" and the only receiving
|
||||
// happens initially to get the number of lights
|
||||
int GetNumberOfLeds(SerialDevice* serialdevice, int* numlights)
|
||||
|
||||
{
|
||||
int count = 0;
|
||||
int bytesWaiting;
|
||||
char buf[256];
|
||||
int retval = 0;
|
||||
int i;
|
||||
|
||||
//sp_flush(port, SP_BUF_INPUT);
|
||||
|
||||
while (count < 4)
|
||||
{
|
||||
slogi("Attempting to retrieve num lights from port...");
|
||||
|
||||
size_t bufsize1 = 11;
|
||||
size_t recv_bufsize1 = 5;
|
||||
char recv_buf1[recv_bufsize1];
|
||||
char bytes1[bufsize1];
|
||||
|
||||
for(int j = 0; j < bufsize1; j++)
|
||||
{
|
||||
bytes1[j] = 0x00;
|
||||
}
|
||||
bytes1[0] = 0xff;
|
||||
bytes1[1] = 0xff;
|
||||
bytes1[2] = 0xff;
|
||||
bytes1[3] = 0xff;
|
||||
bytes1[4] = 0xff;
|
||||
bytes1[5] = 0xff;
|
||||
bytes1[6] = 0x6c;
|
||||
bytes1[7] = 0x65;
|
||||
bytes1[8] = 0x64;
|
||||
bytes1[9] = 0x73;
|
||||
bytes1[10] = 0x63;
|
||||
|
||||
int result = 0;
|
||||
unsigned int timeout = 6000;
|
||||
slogd("Sending message to get num lights");
|
||||
monocoque_wait_for_event(serialdevice->id, 6);
|
||||
|
||||
result = monocoque_serial_write(serialdevice->id, &bytes1, bufsize1, arduino_timeout);
|
||||
|
||||
|
||||
monocoque_wait_for_event(serialdevice->id, 5);
|
||||
bytesWaiting = monocoque_input_wait(serialdevice->id);
|
||||
if (bytesWaiting > 0)
|
||||
{
|
||||
memset(buf, 0, sizeof(buf));
|
||||
retval = monocoque_serial_read_block(serialdevice->id, buf, sizeof(buf)-1, 10);
|
||||
if (retval < 0)
|
||||
{
|
||||
retval = -1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0; i<retval; i++)
|
||||
{
|
||||
if (buf[i] == 13)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
int ret = atoi(buf);
|
||||
*numlights = ret;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (bytesWaiting < 0)
|
||||
{
|
||||
sloge("Error getting bytes available from serial port: %d", bytesWaiting);
|
||||
retval = -1;
|
||||
break;
|
||||
}
|
||||
retval = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int error = arduino_init(serialdevice, portdev);
|
||||
|
||||
int numlights = 0;
|
||||
|
||||
if(uselights == true)
|
||||
{
|
||||
error = GetNumberOfLeds(serialdevice, &numlights);
|
||||
slogi("numlights is %i\n", numlights);
|
||||
// close, error and free if numlights is 0
|
||||
serialdevice->numleds = numlights;
|
||||
}
|
||||
|
||||
if(luafile == NULL)
|
||||
{
|
||||
return serialdevice->id;
|
||||
}
|
||||
|
||||
|
||||
slogi("LUA config specified for this device... initializing...");
|
||||
|
||||
lua_State* L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
int top=lua_gettop(L);
|
||||
int status = luaL_loadfile(L, luafile);
|
||||
|
||||
if (status) {
|
||||
/* If something went wrong, error message is at the top of */
|
||||
/* the stack */
|
||||
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
|
||||
lua_close(serialdevice->m.L);
|
||||
return -1;
|
||||
exit(1);
|
||||
}
|
||||
lua_setglobal(L,"myFunc");
|
||||
|
||||
serialdevice->m.L = L;
|
||||
|
||||
slogi("LUA config setup successful.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int arduino_simled_update(SerialDevice* serialdevice, SimData* simdata)
|
||||
{
|
||||
int result = 1;
|
||||
|
||||
int total_leds = serialdevice->numleds;
|
||||
size_t bufsize = (total_leds * 3) + 14;
|
||||
char bytes[bufsize];
|
||||
int endled = serialdevice->endled;
|
||||
int startled = serialdevice->startled;
|
||||
if(endled == 0)
|
||||
{
|
||||
endled = total_leds;
|
||||
}
|
||||
int num_avail_leds = endled - startled + 1;
|
||||
int rpm = simdata->rpms;
|
||||
int maxrpm = simdata->maxrpm;
|
||||
int litleds = 0;
|
||||
if(rpm > 0 && maxrpm > 0)
|
||||
{
|
||||
int rpmmargin = ceil(.05*maxrpm);
|
||||
int rpminterval = (maxrpm-rpmmargin) / (num_avail_leds);
|
||||
|
||||
|
||||
for (int l = 1; l <= (num_avail_leds); l++)
|
||||
{
|
||||
if(rpm >= (rpminterval * l))
|
||||
{
|
||||
litleds = l;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(int j = 0; j < bufsize; j++)
|
||||
{
|
||||
bytes[j] = 0x00;
|
||||
}
|
||||
bytes[0] = 0xff;
|
||||
bytes[1] = 0xff;
|
||||
bytes[2] = 0xff;
|
||||
bytes[3] = 0xff;
|
||||
bytes[4] = 0xff;
|
||||
bytes[5] = 0xff;
|
||||
bytes[6] = 0x73;
|
||||
bytes[7] = 0x6c;
|
||||
bytes[8] = 0x65;
|
||||
bytes[9] = 0x64;
|
||||
bytes[10] = 0x73;
|
||||
bytes[bufsize-1] = 0xfd;
|
||||
bytes[bufsize-2] = 0xfe;
|
||||
bytes[bufsize-3] = 0xff;
|
||||
|
||||
for(int i = 0; i < litleds; i++)
|
||||
{
|
||||
if(i < ((num_avail_leds) / 2))
|
||||
{
|
||||
//green
|
||||
bytes[11 + ((i + startled - 1) * 3) + 1] = 0xff;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(i < num_avail_leds - 1)
|
||||
{
|
||||
//yellow
|
||||
bytes[11 + ((i + startled - 1) * 3) + 0] = 0xff;
|
||||
bytes[11 + ((i + startled - 1) * 3) + 1] = 0xff;
|
||||
}
|
||||
}
|
||||
if(i == num_avail_leds - 1)
|
||||
{
|
||||
//red
|
||||
bytes[11 + ((i + startled - 1) * 3) + 0] = 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slogt("Updating arduino device lights to %i", litleds);
|
||||
// we can add configs to set all the colors
|
||||
size_t size = sizeof(bytes);
|
||||
|
||||
result = monocoque_serial_write(serialdevice->id, &bytes, size, arduino_timeout);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata)
|
||||
{
|
||||
int result = 1;
|
||||
|
||||
int total_leds = serialdevice->numleds;
|
||||
size_t bufsize = (total_leds * 3) + 14;
|
||||
char ledbytes[total_leds * 3];
|
||||
char bytes[bufsize];
|
||||
|
||||
for(int j = 0; j < bufsize; j++)
|
||||
{
|
||||
bytes[j] = 0x00;
|
||||
}
|
||||
for(int j = 0; j < total_leds * 3; j++)
|
||||
{
|
||||
ledbytes[j] = 0x00;
|
||||
}
|
||||
bytes[0] = 0xff;
|
||||
bytes[1] = 0xff;
|
||||
bytes[2] = 0xff;
|
||||
bytes[3] = 0xff;
|
||||
bytes[4] = 0xff;
|
||||
bytes[5] = 0xff;
|
||||
bytes[6] = 0x73;
|
||||
bytes[7] = 0x6c;
|
||||
bytes[8] = 0x65;
|
||||
bytes[9] = 0x64;
|
||||
bytes[10] = 0x73;
|
||||
bytes[bufsize-1] = 0xfd;
|
||||
bytes[bufsize-2] = 0xfe;
|
||||
bytes[bufsize-3] = 0xff;
|
||||
|
||||
|
||||
lua_State* L = serialdevice->m.L;
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_pushlightuserdata(L, &ledbytes);
|
||||
lua_settable(L, LUA_REGISTRYINDEX);
|
||||
|
||||
simdata_to_lua(L, simdata);
|
||||
lua_setglobal(L, "simdata");
|
||||
|
||||
lua_pushinteger(L, total_leds);
|
||||
lua_setglobal(L, "TotalLeds");
|
||||
|
||||
lua_register(L, "set_led_to_color", set_led_to_color);
|
||||
lua_register(L, "set_led_range_to_color", set_led_range_to_color);
|
||||
lua_register(L, "set_led_to_rgb_color", set_led_to_rgb_color);
|
||||
lua_register(L, "set_led_range_to_rgb_color", set_led_range_to_rgb_color);
|
||||
lua_register(L, "led_clear_all", led_clear_all);
|
||||
lua_register(L, "led_clear_range", led_clear_all);
|
||||
|
||||
lua_pushinteger(L, LUALEDCOLOR_RED);
|
||||
lua_setglobal(L, "RED");
|
||||
lua_pushinteger(L, LUALEDCOLOR_GREEN);
|
||||
lua_setglobal(L, "GREEN");
|
||||
lua_pushinteger(L, LUALEDCOLOR_BLUE);
|
||||
lua_setglobal(L, "BLUE");
|
||||
lua_pushinteger(L, LUALEDCOLOR_YELLOW);
|
||||
lua_setglobal(L, "YELLOW");
|
||||
lua_pushinteger(L, LUALEDCOLOR_ORANGE);
|
||||
lua_setglobal(L, "ORANGE");
|
||||
|
||||
lua_getglobal(L,"myFunc");
|
||||
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
|
||||
{
|
||||
fprintf(stderr, "Error calling Lua script: %s\n", lua_tostring(L, -1));
|
||||
}
|
||||
|
||||
for(int i = 0; i < total_leds; i++)
|
||||
{
|
||||
bytes[11 + (i * 3) + 0] = ledbytes[(i * 3) + 0];
|
||||
bytes[11 + (i * 3) + 1] = ledbytes[(i * 3) + 1];
|
||||
bytes[11 + (i * 3) + 2] = ledbytes[(i * 3) + 2];
|
||||
}
|
||||
|
||||
size_t size = sizeof(bytes);
|
||||
result = arduino_update(serialdevice, &bytes, size);
|
||||
|
||||
slogt("custom led wrote %i bytes", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int arduino_customled_free(SerialDevice* serialdevice, bool lua)
|
||||
{
|
||||
size_t bufsize = (serialdevice->numleds * 3) + 14;
|
||||
char bytes[bufsize];
|
||||
int endled = serialdevice->endled;
|
||||
int startled = serialdevice->startled;
|
||||
if(endled == 0)
|
||||
|
||||
for(int j = 0; j < bufsize; j++)
|
||||
{
|
||||
bytes[j] = 0x00;
|
||||
}
|
||||
bytes[0] = 0xff;
|
||||
bytes[1] = 0xff;
|
||||
bytes[2] = 0xff;
|
||||
bytes[3] = 0xff;
|
||||
bytes[4] = 0xff;
|
||||
bytes[5] = 0xff;
|
||||
bytes[6] = 0x73;
|
||||
bytes[7] = 0x6c;
|
||||
bytes[8] = 0x65;
|
||||
bytes[9] = 0x64;
|
||||
bytes[10] = 0x73;
|
||||
bytes[bufsize-1] = 0xfd;
|
||||
bytes[bufsize-2] = 0xfe;
|
||||
bytes[bufsize-3] = 0xff;
|
||||
|
||||
for(int i = 0; i < serialdevice->numleds; i++)
|
||||
{
|
||||
bytes[11 + (i * 3) + 0] = 0x00;
|
||||
bytes[11 + (i * 3) + 1] = 0x00;
|
||||
bytes[11 + (i * 3) + 2] = 0x00;
|
||||
}
|
||||
size_t size = sizeof(bytes);
|
||||
|
||||
int result = monocoque_serial_write_block(serialdevice->id, &bytes, size, arduino_timeout);
|
||||
|
||||
if(lua == false)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
lua_close(serialdevice->m.L);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int arduino_custom_update(SerialDevice* serialdevice, SimData* simdata)
|
||||
{
|
||||
size_t bufsize = 14;
|
||||
char bytes[bufsize];
|
||||
lua_State* L = serialdevice->m.L;
|
||||
|
||||
simdata_to_lua(L, simdata);
|
||||
lua_setglobal(L, "simdata");
|
||||
|
||||
lua_getglobal(L,"myFunc");
|
||||
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
|
||||
{
|
||||
fprintf(stderr, "Error calling Lua script: %s\n", lua_tostring(L, -1));
|
||||
}
|
||||
|
||||
lua_getglobal(L, "Message");
|
||||
int result = 0;
|
||||
if (lua_isstring(L, -1)) {
|
||||
const char *msg = lua_tostring(L, -1);
|
||||
size_t size = strlen(msg);
|
||||
result = arduino_update(serialdevice, (void*) msg, size);
|
||||
slogt("custom arduino wrote message %s of %i bytes", msg, result);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
lua_pop(L, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,13 @@
|
||||
#include "../serialdevice.h"
|
||||
|
||||
|
||||
int arduino_simled_update(SerialDevice* serialdevice, SimData* simdata);
|
||||
int arduino_update(SerialDevice* serialdevice, void* data, size_t size);
|
||||
int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const char* luafile, bool useleds);
|
||||
int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata);
|
||||
int arduino_custom_update(SerialDevice* serialdevice, SimData* simdata);
|
||||
int arduino_init(SerialDevice* serialdevice, const char* portdev);
|
||||
int arduino_free(SerialDevice* serialdevice);
|
||||
int arduino_customled_free(SerialDevice* serialdevice, bool lua);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,430 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "arduinoledlua.h"
|
||||
#include "arduino.h"
|
||||
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
long long ledTimeInMilliseconds(void) {
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv,NULL);
|
||||
return (((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000);
|
||||
}
|
||||
|
||||
|
||||
int simdata_to_lua(lua_State *L, SimData* simdata) {
|
||||
|
||||
// make the time up now if we are running in test mode
|
||||
if(simdata->mtick == 0)
|
||||
{
|
||||
simdata->mtick = ledTimeInMilliseconds();
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
lua_pushstring(L, simdata->gearc);
|
||||
lua_setfield(L, -2, "gearc");
|
||||
|
||||
lua_pushinteger(L, simdata->playerflag);
|
||||
lua_setfield(L, -2, "playerflag");
|
||||
|
||||
lua_pushinteger(L, simdata->rpms);
|
||||
lua_setfield(L, -2, "rpm");
|
||||
|
||||
lua_pushinteger(L, simdata->gear);
|
||||
lua_setfield(L, -2, "gear");
|
||||
|
||||
lua_pushinteger(L, simdata->velocity);
|
||||
lua_setfield(L, -2, "velocity");
|
||||
|
||||
lua_pushinteger(L, simdata->mtick);
|
||||
lua_setfield(L, -2, "mtick");
|
||||
|
||||
lua_pushinteger(L, simdata->maxrpm);
|
||||
lua_setfield(L, -2, "maxrpm");
|
||||
|
||||
lua_pushinteger(L, PROXCARS);
|
||||
lua_setfield(L, -2, "proxcars");
|
||||
|
||||
lua_newtable(L);
|
||||
for(int i = 0; i < PROXCARS; i++)
|
||||
{
|
||||
lua_newtable(L);
|
||||
lua_pushinteger(L, simdata->pd[i].radius);
|
||||
lua_setfield(L, -2, "radius");
|
||||
lua_pushinteger(L, simdata->pd[i].theta);
|
||||
lua_setfield(L, -2, "theta");
|
||||
lua_rawseti(L, -2, i+1);
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
uint8_t get_color_rgb_value(int color, int rgb)
|
||||
{
|
||||
switch (color)
|
||||
{
|
||||
case LUALEDCOLOR_RED:
|
||||
switch (rgb)
|
||||
{
|
||||
case 0:
|
||||
return 255;
|
||||
case 1:
|
||||
return 0;
|
||||
case 2:
|
||||
return 0;
|
||||
}
|
||||
case LUALEDCOLOR_GREEN:
|
||||
switch (rgb)
|
||||
{
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return 255;
|
||||
case 2:
|
||||
return 0;
|
||||
}
|
||||
case LUALEDCOLOR_BLUE:
|
||||
switch (rgb)
|
||||
{
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
return 0;
|
||||
case 2:
|
||||
return 255;
|
||||
}
|
||||
case LUALEDCOLOR_YELLOW:
|
||||
switch (rgb)
|
||||
{
|
||||
case 0:
|
||||
return 255;
|
||||
case 1:
|
||||
return 255;
|
||||
case 2:
|
||||
return 0;
|
||||
}
|
||||
case LUALEDCOLOR_ORANGE:
|
||||
switch (rgb)
|
||||
{
|
||||
case 0:
|
||||
return 255;
|
||||
case 1:
|
||||
return 165;
|
||||
case 2:
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int set_led_range_to_color(lua_State *L)
|
||||
{
|
||||
|
||||
slogt("lua called c function set_led_range_to_color");
|
||||
|
||||
int range_start = lua_tonumber(L, 1);
|
||||
int range_end = lua_tonumber(L, 2);
|
||||
int color = lua_tonumber(L, 3);
|
||||
|
||||
slogd("lua range start is %i", range_start);
|
||||
slogd("lua range end is %i", range_end);
|
||||
slogd("lua color is %i", color);
|
||||
|
||||
range_start = range_start - 1;
|
||||
|
||||
lua_getglobal(L, "TotalLeds");
|
||||
int numlights = 0;
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
numlights = lua_tonumber(L, -1);
|
||||
}
|
||||
slogd("num leds is %i", numlights);
|
||||
|
||||
if(range_end > numlights)
|
||||
{
|
||||
range_end = numlights;
|
||||
}
|
||||
|
||||
if(range_end == 0)
|
||||
{
|
||||
slogt("Invalid range, doing nothing");
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
char* bytes = lua_touserdata(L, -1);
|
||||
|
||||
slogt("first byte of buff is x%02x", bytes[0]);
|
||||
|
||||
uint8_t color0 = get_color_rgb_value(color, 0);
|
||||
uint8_t color1 = get_color_rgb_value(color, 1);
|
||||
uint8_t color2 = get_color_rgb_value(color, 2);
|
||||
|
||||
for( int i = range_start; i < range_end; i++)
|
||||
{
|
||||
bytes[(i * 3) + 0] = color0;
|
||||
bytes[(i * 3) + 1] = color1;
|
||||
bytes[(i * 3) + 2] = color2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int set_led_range_to_rgb_color(lua_State *L)
|
||||
{
|
||||
|
||||
slogt("lua called c function set_led_range_to_rgb_color");
|
||||
|
||||
int range_start = lua_tonumber(L, 1);
|
||||
int range_end = lua_tonumber(L, 2);
|
||||
int color = lua_tonumber(L, 3);
|
||||
|
||||
uint8_t color0 = (color >> 16) & 0xff;
|
||||
uint8_t color1 = (color >> 8) & 0xff;
|
||||
uint8_t color2 = (color >> 0) & 0xff;
|
||||
//int color0 = lua_tonumber(L, 3);
|
||||
//int color1 = lua_tonumber(L, 4);
|
||||
//int color2 = lua_tonumber(L, 5);
|
||||
|
||||
slogd("lua range start is %i", range_start);
|
||||
slogd("lua range end is %i", range_end);
|
||||
slogd("lua color0 is %i", color0);
|
||||
slogd("lua color1 is %i", color1);
|
||||
slogd("lua color2 is %i", color2);
|
||||
|
||||
range_start = range_start - 1;
|
||||
|
||||
lua_getglobal(L, "TotalLeds");
|
||||
int numlights = 0;
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
numlights = lua_tonumber(L, -1);
|
||||
}
|
||||
slogd("num leds is %i", numlights);
|
||||
|
||||
if(range_end > numlights)
|
||||
{
|
||||
range_end = numlights;
|
||||
}
|
||||
|
||||
if(range_end == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
char* bytes = lua_touserdata(L, -1);
|
||||
|
||||
slogt("first byte of buff is x%02x", bytes[0]);
|
||||
|
||||
for( int i = range_start; i < range_end; i++)
|
||||
{
|
||||
bytes[(i * 3) + 0] = color0;
|
||||
bytes[(i * 3) + 1] = color1;
|
||||
bytes[(i * 3) + 2] = color2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int set_led_to_color(lua_State *L)
|
||||
{
|
||||
slogt("lua called c function set_led_to_rgb_color");
|
||||
|
||||
int led = lua_tonumber(L, 1);
|
||||
int color = lua_tonumber(L, 2);
|
||||
|
||||
slogd("lua led is %i", led);
|
||||
slogd("lua color is %i", color);
|
||||
|
||||
led = led - 1;
|
||||
|
||||
lua_getglobal(L, "TotalLeds");
|
||||
int numlights = 0;
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
numlights = lua_tonumber(L, -1);
|
||||
}
|
||||
slogd("num leds is %i", numlights);
|
||||
|
||||
if(led > numlights)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
char* bytes = lua_touserdata(L, -1);
|
||||
|
||||
slogt("first byte of buff is x%02x", bytes[0]);
|
||||
|
||||
uint8_t color0 = get_color_rgb_value(color, 0);
|
||||
uint8_t color1 = get_color_rgb_value(color, 1);
|
||||
uint8_t color2 = get_color_rgb_value(color, 2);
|
||||
|
||||
bytes[(led * 3) + 0] = color0;
|
||||
bytes[(led * 3) + 1] = color1;
|
||||
bytes[(led * 3) + 2] = color2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int set_led_to_rgb_color(lua_State *L)
|
||||
{
|
||||
slogt("lua called c function set_led_to_rgb_color");
|
||||
|
||||
int led = lua_tonumber(L, 1);
|
||||
int color = lua_tonumber(L, 2);
|
||||
|
||||
uint8_t color0 = (color >> 16) & 0xff;
|
||||
uint8_t color1 = (color >> 8) & 0xff;
|
||||
uint8_t color2 = (color >> 0) & 0xff;
|
||||
|
||||
slogd("lua led is %i", led);
|
||||
slogd("lua color0 is %i", color0);
|
||||
slogd("lua color1 is %i", color1);
|
||||
slogd("lua color2 is %i", color2);
|
||||
|
||||
led = led - 1;
|
||||
|
||||
lua_getglobal(L, "TotalLeds");
|
||||
int numlights = 0;
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
numlights = lua_tonumber(L, -1);
|
||||
}
|
||||
slogd("num leds is %i", numlights);
|
||||
|
||||
if(led > numlights)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
char* bytes = lua_touserdata(L, -1);
|
||||
|
||||
slogt("first byte of buff is x%02x", bytes[0]);
|
||||
|
||||
bytes[(led * 3) + 0] = color0;
|
||||
bytes[(led * 3) + 1] = color1;
|
||||
bytes[(led * 3) + 2] = color2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int led_clear_all(lua_State *L)
|
||||
{
|
||||
|
||||
slogt("lua called c function led_clear_all");
|
||||
|
||||
lua_getglobal(L, "TotalLeds");
|
||||
int numlights = 0;
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
numlights = lua_tonumber(L, -1);
|
||||
}
|
||||
slogd("num leds is %i", numlights);
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
char* bytes = lua_touserdata(L, -1);
|
||||
|
||||
slogt("first byte of buff is x%02x", bytes[0]);
|
||||
|
||||
for( int i = 0; i < numlights; i++)
|
||||
{
|
||||
bytes[(i * 3) + 0] = 0x00;
|
||||
bytes[(i * 3) + 1] = 0x00;
|
||||
bytes[(i * 3) + 2] = 0x00;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int led_clear_range(lua_State *L)
|
||||
{
|
||||
|
||||
slogt("lua called c function led_clear_range");
|
||||
|
||||
int range_start = lua_tonumber(L, 1);
|
||||
int range_end = lua_tonumber(L, 2);
|
||||
|
||||
slogd("lua range start is %i", range_start);
|
||||
slogd("lua range end is %i", range_end);
|
||||
|
||||
range_start = range_start - 1;
|
||||
|
||||
lua_getglobal(L, "TotalLeds");
|
||||
int numlights = 0;
|
||||
if (lua_isnumber(L, -1))
|
||||
{
|
||||
numlights = lua_tonumber(L, -1);
|
||||
}
|
||||
slogd("num leds is %i", numlights);
|
||||
|
||||
if(range_end > numlights)
|
||||
{
|
||||
range_end = numlights;
|
||||
}
|
||||
|
||||
if(range_end == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
char* bytes = lua_touserdata(L, -1);
|
||||
|
||||
slogt("first byte of buff is x%02x", bytes[0]);
|
||||
|
||||
for( int i = 0; i < numlights; i++)
|
||||
{
|
||||
bytes[(i * 3) + 0] = 0x00;
|
||||
bytes[(i * 3) + 1] = 0x00;
|
||||
bytes[(i * 3) + 2] = 0x00;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef _ARDUINOLEDLUA_H
|
||||
#define _ARDUINOLEDLUA_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"
|
||||
|
||||
typedef enum {
|
||||
LUALEDCOLOR_RED = 1,
|
||||
LUALEDCOLOR_GREEN,
|
||||
LUALEDCOLOR_BLUE,
|
||||
LUALEDCOLOR_YELLOW,
|
||||
LUALEDCOLOR_ORANGE,
|
||||
} LUALEDColor;
|
||||
|
||||
int simdata_to_lua(lua_State *L, SimData* simdata);
|
||||
int set_led_range_to_color(lua_State *L);
|
||||
int set_led_to_color(lua_State *L);
|
||||
int set_led_range_to_rgb_color(lua_State *L);
|
||||
int set_led_to_rgb_color(lua_State *L);
|
||||
int led_clear_all(lua_State *L);
|
||||
int led_clear_range(lua_State *L);
|
||||
|
||||
#endif
|
||||
@@ -10,70 +10,71 @@
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
#define MOZA_TIMEOUT 1000
|
||||
#define MOZA_SERIAL_TEMPLATE {0x7e, 0x06, 0x41, 0x17, 0xfd, 0xde, 0x0, 0x0, 0x0, 0x0, 0x0}
|
||||
#define MOZA_SERIAL_TEMPLATE {0x7e, 0x06, 0x41, 0x13, 0xfd, 0xde, 0x0, 0x0, 0x0, 0x0, 0x0}
|
||||
#define MOZA_NUM_AVAILABLE_LEDS 10
|
||||
#define MOZA_BLINKING_BIT 7
|
||||
#define MOZA_PAYLOAD_SIZE 11
|
||||
#define MOZA_MAGIC_VALUE 0x0d
|
||||
#define BIT(nr) (1UL << (nr))
|
||||
|
||||
unsigned char moza_checksum(unsigned char *data)
|
||||
unsigned char moza_checksum(unsigned char *data, unsigned short size)
|
||||
{
|
||||
unsigned char ret = MOZA_MAGIC_VALUE;
|
||||
for (short i = 0; i < sizeof(data)/sizeof(data[0]); i++)
|
||||
unsigned int ret = MOZA_MAGIC_VALUE;
|
||||
for (unsigned short i = 0; i < size; i++)
|
||||
{
|
||||
ret += data[i];
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret % 0x100;
|
||||
}
|
||||
|
||||
int moza_update(SerialDevice* serialdevice, unsigned short maxrpm, unsigned short rpm)
|
||||
int moza_update(SerialDevice* serialdevice, unsigned short rpm, unsigned short maxrpm)
|
||||
{
|
||||
unsigned char bytes[] = MOZA_SERIAL_TEMPLATE;
|
||||
int size = sizeof(bytes)/sizeof(bytes[0]);
|
||||
unsigned short size = MOZA_PAYLOAD_SIZE;
|
||||
float perctflt = ((float)rpm/(float)maxrpm)*100;
|
||||
int perct = round(perctflt);
|
||||
|
||||
float perct = (float)rpm/(float)maxrpm;
|
||||
|
||||
if (perct >= 0.8)
|
||||
if (perct >= 10)
|
||||
bytes[9] |= BIT(0);
|
||||
|
||||
if (perct >= 0.83)
|
||||
if (perct >= 20)
|
||||
bytes[9] |= BIT(1);
|
||||
|
||||
if (perct >= 0.86)
|
||||
if (perct >= 30)
|
||||
bytes[9] |= BIT(2);
|
||||
|
||||
if (perct >= 0.89)
|
||||
if (perct >= 40)
|
||||
bytes[9] |= BIT(3);
|
||||
|
||||
if (perct >= 0.91)
|
||||
bytes[8] |= BIT(4);
|
||||
if (perct >= 50)
|
||||
bytes[9] |= BIT(4);
|
||||
|
||||
if (perct >= 0.92)
|
||||
bytes[8] |= BIT(5);
|
||||
if (perct >= 60)
|
||||
bytes[9] |= BIT(5);
|
||||
|
||||
if (perct >= 0.93)
|
||||
bytes[8] |= BIT(6);
|
||||
if (perct >= 70)
|
||||
bytes[9] |= BIT(6);
|
||||
|
||||
if (perct >= 0.94)
|
||||
bytes[8] |= BIT(7);
|
||||
if (perct >= 80)
|
||||
bytes[9] |= BIT(7);
|
||||
|
||||
if (perct >= 0.96)
|
||||
if (perct >= 90)
|
||||
bytes[8] |= BIT(0);
|
||||
|
||||
if (perct >= 0.96)
|
||||
if (perct >= 92)
|
||||
bytes[8] |= BIT(1);
|
||||
|
||||
// blinking
|
||||
if (perct >= 0.97)
|
||||
bytes[9] |= BIT(MOZA_BLINKING_BIT);
|
||||
if (perct >= 94)
|
||||
bytes[8] |= BIT(MOZA_BLINKING_BIT);
|
||||
|
||||
bytes[10] = moza_checksum(bytes);
|
||||
bytes[10] = moza_checksum(bytes, size);
|
||||
|
||||
int result = 1;
|
||||
if (serialdevice->port)
|
||||
{
|
||||
slogd("copying %i bytes to moza device", size);
|
||||
slogd("copying %i bytes to moza device", MOZA_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], rpm, maxrpm);
|
||||
result = monocoque_serial_write(serialdevice->id, bytes, size, MOZA_TIMEOUT);
|
||||
}
|
||||
@@ -83,6 +84,8 @@ int moza_update(SerialDevice* serialdevice, unsigned short maxrpm, unsigned shor
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@
|
||||
#include "../serialdevice.h"
|
||||
#include "../simdevice.h"
|
||||
|
||||
int moza_update(SerialDevice* serialdevice, unsigned short maxrpm, unsigned short rpm);
|
||||
int moza_update(SerialDevice* serialdevice, unsigned short rpm, unsigned short maxrpm);
|
||||
int moza_init(SerialDevice* serialdevice, const char* portdev);
|
||||
int moza_free(SerialDevice* serialdevice);
|
||||
int moza_serial_check(enum sp_return result);
|
||||
|
||||
unsigned char moza_checksum(unsigned char *data, unsigned short size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "moza.h"
|
||||
#include "moza_new.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, 0xff, 0, 1, 0, 0xff, 0, 2, 0, 0xff, 0, 3, 0xff, 0x7f, 0, 4, 0xff, 0x7f, 0, 0}
|
||||
#define MOZA_RPM_COLOR_PAYLOAD_2 {0x7e, 0x16, 0x3f, 0x17, 0x19, 0, 5, 0xff, 0x7f, 0, 6, 0xff, 0x7f, 0, 7, 0xff, 0, 0, 8, 0xff, 0, 0, 9, 0xff, 0, 0, 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 BIT(nr) (1UL << (nr))
|
||||
|
||||
int moza_new_update(SerialDevice* serialdevice, SimData* simData)
|
||||
{
|
||||
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(0);
|
||||
|
||||
if (perct >= 79)
|
||||
bytes[6] |= BIT(1);
|
||||
|
||||
if (perct >= 82)
|
||||
bytes[6] |= BIT(2);
|
||||
|
||||
if (perct >= 85)
|
||||
bytes[6] |= BIT(3);
|
||||
|
||||
if (perct >= 87)
|
||||
bytes[6] |= BIT(4);
|
||||
|
||||
if (perct >= 88)
|
||||
bytes[6] |= BIT(5);
|
||||
|
||||
if (perct >= 89)
|
||||
bytes[6] |= BIT(6);
|
||||
|
||||
if (perct >= 90)
|
||||
bytes[6] |= BIT(7);
|
||||
|
||||
if (perct >= 92)
|
||||
bytes[7] |= BIT(0);
|
||||
|
||||
if (perct >= 94)
|
||||
bytes[7] |= BIT(1);
|
||||
|
||||
bytes[10] = moza_checksum(bytes, size);
|
||||
|
||||
int result = 1;
|
||||
if (serialdevice->port)
|
||||
{
|
||||
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_new_init(SerialDevice* serialdevice, const char* portdev)
|
||||
{
|
||||
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;
|
||||
unsigned char p3[] = MOZA_BTN_COLOR_PAYLOAD_1;
|
||||
unsigned char p4[] = 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);
|
||||
|
||||
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 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _MOZA_NEW_H
|
||||
#define _MOZA_NEW_H
|
||||
|
||||
#include "../serialdevice.h"
|
||||
#include "../simdevice.h"
|
||||
|
||||
int moza_new_update(SerialDevice* serialdevice, SimData* simData);
|
||||
int moza_new_init(SerialDevice* serialdevice, const char* portdev);
|
||||
|
||||
#endif
|
||||
@@ -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;
|
||||
@@ -57,10 +60,13 @@ int monocoque_serial_free(SerialDevice* serialdevice)
|
||||
slogd("freeing physical device %s", monocoque_serial_devices[serialdevice->id].portname);
|
||||
sp_close(monocoque_serial_devices[serialdevice->id].port);
|
||||
sp_free_port(monocoque_serial_devices[serialdevice->id].port);
|
||||
free(monocoque_serial_devices[serialdevice->id].portname);
|
||||
|
||||
monocoque_serial_devices[serialdevice->id].port = NULL;
|
||||
monocoque_serial_devices[serialdevice->id].portname = NULL;
|
||||
monocoque_serial_devices[serialdevice->id].busy = false;
|
||||
monocoque_serial_devices[serialdevice->id].open = false;
|
||||
monocoque_serial_devices[serialdevice->id].openfail = false;
|
||||
free(monocoque_serial_devices[serialdevice->id].portname);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -70,23 +76,71 @@ int monocoque_serial_free(SerialDevice* serialdevice)
|
||||
}
|
||||
}
|
||||
|
||||
int monocoque_serial_write(uint8_t serialdevicenum, void* data, size_t size, int timeout)
|
||||
|
||||
int monocoque_wait_for_event(uint8_t serialdevicenum, int event)
|
||||
{
|
||||
|
||||
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);
|
||||
int retval;
|
||||
struct sp_event_set* eventSet = NULL;
|
||||
|
||||
if(monocoque_serial_dev.port == NULL)
|
||||
retval = sp_new_event_set(&eventSet);
|
||||
if (retval == SP_OK)
|
||||
{
|
||||
retval = sp_add_port_events(eventSet, monocoque_serial_dev.port, event);
|
||||
if (retval == SP_OK)
|
||||
{
|
||||
slogd("set event on port");
|
||||
retval = sp_wait(eventSet, 5000);
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Unable to add events to port.");
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Unable to create new event set.");
|
||||
retval = -1;
|
||||
}
|
||||
sp_free_event_set(eventSet);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int monocoque_input_wait(uint8_t serialdevicenum)
|
||||
{
|
||||
monocoque_serial_device monocoque_serial_dev = monocoque_serial_devices[serialdevicenum];
|
||||
return sp_input_waiting(monocoque_serial_dev.port);
|
||||
}
|
||||
|
||||
// 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);
|
||||
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
|
||||
{
|
||||
@@ -94,37 +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)
|
||||
{
|
||||
monocoque_serial_device* dev = monocoque_get_serial_device(serialdevicenum);
|
||||
|
||||
int result = -1;
|
||||
if(dev->open == true)
|
||||
{
|
||||
while(dev->busy == true)
|
||||
{
|
||||
slogt("hopefully this doesn't happen long");
|
||||
continue;
|
||||
}
|
||||
|
||||
dev->busy = true;
|
||||
result = sp_blocking_read(dev->port, data, size, timeout);
|
||||
slogi("actually performed read");
|
||||
}
|
||||
|
||||
dev->busy = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -135,7 +203,7 @@ int monocoque_serial_open(SerialDevice* serialdevice, const char* portdev)
|
||||
slogi("looking to open physical serialdevice %s", portdev);
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
if(monocoque_serial_devices[i].open == true || monocoque_serial_devices[i].openfail == true)
|
||||
if(monocoque_serial_devices[i].open == true && monocoque_serial_devices[i].openfail == false)
|
||||
{
|
||||
if(msastrcicmp(monocoque_serial_devices[i].portname, portdev) == 0)
|
||||
{
|
||||
@@ -173,13 +241,17 @@ int monocoque_serial_open(SerialDevice* serialdevice, const char* portdev)
|
||||
error = check(sp_get_port_by_name(port_name, &sp));
|
||||
if (error != 0)
|
||||
{
|
||||
sloge("Error opening serial port");
|
||||
free(port_name);
|
||||
free(monocoque_serial_devices[i].portname);
|
||||
monocoque_serial_devices[i].portname = NULL;
|
||||
monocoque_serial_devices[i].open = false;
|
||||
monocoque_serial_devices[i].openfail = true;
|
||||
monocoque_serial_devices[i].openfail = false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
slogd("Opening port");
|
||||
check(sp_open(sp, SP_MODE_READ_WRITE));
|
||||
check(sp_open(sp, SP_MODE_READ | SP_MODE_WRITE));
|
||||
|
||||
slogd("Setting port to %i 8N1, no flow control", serialdevice->baudrate);
|
||||
check(sp_set_baudrate(sp, serialdevice->baudrate));
|
||||
@@ -188,6 +260,9 @@ int monocoque_serial_open(SerialDevice* serialdevice, const char* portdev)
|
||||
check(sp_set_stopbits(sp, 1));
|
||||
check(sp_set_flowcontrol(sp, SP_FLOWCONTROL_NONE));
|
||||
|
||||
check(sp_set_rts(sp, 1));
|
||||
check(sp_set_dtr(sp, 1));
|
||||
|
||||
monocoque_serial_devices[i].port = sp;
|
||||
|
||||
monocoque_serial_devices[i].open = true;
|
||||
@@ -198,7 +273,7 @@ int monocoque_serial_open(SerialDevice* serialdevice, const char* portdev)
|
||||
serial_device_num = i;
|
||||
|
||||
free(port_name);
|
||||
slogd("Successfully setup arduino serial device...");
|
||||
slogd("Successfully setup monocoque serial device...");
|
||||
}
|
||||
|
||||
return serial_device_num;
|
||||
|
||||
@@ -18,10 +18,13 @@ typedef struct
|
||||
}
|
||||
monocoque_serial_device;
|
||||
|
||||
static monocoque_serial_device monocoque_serial_devices[10];
|
||||
static monocoque_serial_device monocoque_serial_devices[20];
|
||||
|
||||
int monocoque_input_wait(uint8_t serialdevicenum);
|
||||
int monocoque_wait_for_event(uint8_t serialdevicenum, int event);
|
||||
int monocoque_serial_write(uint8_t serialdevicenum, void* data, size_t size, int timeout);
|
||||
int monocoque_serial_write_block(uint8_t serialdevicenum, void* data, size_t size, int timeout);
|
||||
int monocoque_serial_read_block(uint8_t serialdevicenum, void* data, size_t size, int timeout);
|
||||
int monocoque_serial_open(SerialDevice* serialdevice, const char* port);
|
||||
int monocoque_serial_free(SerialDevice* serialdevice);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "hapticeffect.h"
|
||||
#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"
|
||||
@@ -20,7 +22,20 @@ int serial_wheel_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
|
||||
moza_update(serialdevice, simdata->maxrpm, simdata->rpms);
|
||||
switch (serialdevice->devicetype) {
|
||||
case SIMDEVSUBTYPE_MOZA_NEW:
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -34,6 +49,32 @@ int serialdev_update(SimDevice* this, SimData* simdata)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arduino_custom_updater(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
|
||||
arduino_custom_update(serialdevice, simdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arduino_customled_updater(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
arduino_customled_update(serialdevice, simdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arduino_simled_updater(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
|
||||
arduino_simled_update(serialdevice, simdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int arduino_shiftlights_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
@@ -70,6 +111,8 @@ int arduino_shiftlights_update(SimDevice* this, SimData* simdata)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int arduino_simwind_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
@@ -79,8 +122,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);
|
||||
@@ -95,8 +139,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;
|
||||
@@ -104,25 +152,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);
|
||||
@@ -146,11 +196,19 @@ 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);
|
||||
slogi("set zero to arduino device");
|
||||
break;
|
||||
case ARDUINODEV__SIMLED__CUSTOM:
|
||||
//arduino_customled_free(serialdevice, true);
|
||||
free(serialdevice->m.device_specific_config_file);
|
||||
break;
|
||||
case ARDUINODEV__SIMLED:
|
||||
arduino_customled_free(serialdevice, false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -172,26 +230,50 @@ 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);
|
||||
slogi("initializing serial device on port %s to %i...", ds->dev, ds->serialdevsettings.baud);
|
||||
int error = 0;
|
||||
|
||||
|
||||
serialdevice->motorsposition = ds->serialdevsettings.motorsposition;
|
||||
serialdevice->baudrate = ds->serialdevsettings.baud;
|
||||
|
||||
switch (serialdevice->type)
|
||||
switch (serialdevice->devicetype)
|
||||
{
|
||||
case SERIALDEV_WHEEL:
|
||||
|
||||
case SERIALDEV__MOZAR5:
|
||||
// the wheel stuff assumed it was a usb
|
||||
//error = wheeldev_init(&serialdevice->u.wheeldevice, ds);
|
||||
error = moza_init(serialdevice, ds->serialdevsettings.portdev);
|
||||
// maybe this call a more generic serial wheel init first
|
||||
error = moza_init(serialdevice, ds->dev);
|
||||
break;
|
||||
case SERIALDEV__MOZA_NEW:
|
||||
error = moza_new_init(serialdevice, ds->dev);
|
||||
break;
|
||||
case SERIALDEV__MOZA_KS_PRO_WHEEL:
|
||||
error = moza_ks_pro_wheel_init(serialdevice, ds->dev);
|
||||
break;
|
||||
case ARDUINODEV__SIMLED__CUSTOM:
|
||||
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||
error = arduino_custom_init(serialdevice, ds->dev, serialdevice->m.device_specific_config_file, true);
|
||||
if(error < 0)
|
||||
{
|
||||
free(serialdevice->m.device_specific_config_file);
|
||||
}
|
||||
break;
|
||||
case ARDUINODEV__CUSTOM:
|
||||
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||
error = arduino_custom_init(serialdevice, ds->dev, serialdevice->m.device_specific_config_file, false);
|
||||
if(error < 0)
|
||||
{
|
||||
free(serialdevice->m.device_specific_config_file);
|
||||
}
|
||||
break;
|
||||
case ARDUINODEV__SIMLED:
|
||||
error = arduino_custom_init(serialdevice, ds->dev, NULL, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
error = arduino_init(serialdevice, ds->serialdevsettings.portdev );
|
||||
error = arduino_init(serialdevice, ds->dev);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -201,11 +283,14 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
||||
|
||||
static const vtable serial_simdevice_vtable = { &serialdev_update, &serialdev_free };
|
||||
static const vtable arduino_shiftlights_vtable = { &arduino_shiftlights_update, &serialdev_free };
|
||||
static const vtable arduino_simled_vtable = { &arduino_simled_updater, &serialdev_free };
|
||||
static const vtable arduino_custom_vtable = { &arduino_custom_updater, &serialdev_free };
|
||||
static const vtable arduino_simled_custom_vtable = { &arduino_customled_updater, &serialdev_free };
|
||||
static const vtable arduino_simwind_vtable = { &arduino_simwind_update, &serialdev_free };
|
||||
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));
|
||||
|
||||
@@ -214,6 +299,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) {
|
||||
@@ -223,12 +309,42 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
this->m.vtable = &arduino_shiftlights_vtable;
|
||||
slogi("Initializing arduino device for shiftlights.");
|
||||
break;
|
||||
case (SIMDEVTYPE_SIMLED):
|
||||
|
||||
if(ds->has_config == true)
|
||||
{
|
||||
this->devicetype = ARDUINODEV__SIMLED__CUSTOM;
|
||||
this->startled = ds->serialdevsettings.startled;
|
||||
this->endled = ds->serialdevsettings.endled;
|
||||
this->m.vtable = &arduino_simled_custom_vtable;
|
||||
slogi("Initializing arduino device for custom simled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this->devicetype = ARDUINODEV__SIMLED;
|
||||
this->numleds = ds->serialdevsettings.numleds;
|
||||
this->startled = ds->serialdevsettings.startled;
|
||||
this->endled = ds->serialdevsettings.endled;
|
||||
this->m.vtable = &arduino_simled_vtable;
|
||||
slogi("Initializing arduino device for simled.");
|
||||
}
|
||||
break;
|
||||
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;
|
||||
this->m.vtable = &arduino_custom_vtable;
|
||||
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;
|
||||
@@ -239,41 +355,56 @@ 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):
|
||||
this->type = SERIALDEV_WHEEL;
|
||||
|
||||
slogi("Initializing serial wheel device.");
|
||||
switch (ds->dev_subsubtype) {
|
||||
|
||||
case SIMDEVSUBTYPE_MOZA_NEW:
|
||||
slogi("Initializing new firmware Moza serial wheel device.");
|
||||
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
|
||||
this->devicetype = SERIALDEV__MOZAR5;
|
||||
this->m.vtable = &serialwheel_vtable;
|
||||
|
||||
break;
|
||||
//move this stuff to wheeldevice or it's own serial wheel device module
|
||||
slogi("Initializing Moza serial wheel device.");
|
||||
this->devicetype = SERIALDEV__MOZAR5;
|
||||
this->m.vtable = &serialwheel_vtable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ARDUINODEV__SHIFTLIGHTS = 0,
|
||||
ARDUINODEV__SIMWIND = 1,
|
||||
ARDUINODEV__HAPTIC = 2,
|
||||
SERIALDEV__MOZAR5 = 3,
|
||||
ARDUINODEV__SHIFTLIGHTS = 0,
|
||||
ARDUINODEV__SIMWIND = 1,
|
||||
ARDUINODEV__HAPTIC = 2,
|
||||
SERIALDEV__MOZAR5 = 3,
|
||||
ARDUINODEV__SIMLED = 4,
|
||||
ARDUINODEV__SIMLED__CUSTOM = 5,
|
||||
ARDUINODEV__CUSTOM = 6,
|
||||
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;
|
||||
@@ -50,26 +50,32 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
||||
}
|
||||
|
||||
if (ds[j].dev_type == SIMDEV_SOUND) {
|
||||
|
||||
SoundDevice* sim = new_sound_device(&ds[j], ms);
|
||||
if (sim != NULL)
|
||||
if(ms->disable_audio == true)
|
||||
{
|
||||
|
||||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SOUND;
|
||||
simdevices[j].fps = ds[j].fps;
|
||||
devices++;
|
||||
slogi("skipping configured sound device due to disable_audio being specified...");
|
||||
}
|
||||
else
|
||||
{
|
||||
slogw("Could not initialize Sound Device");
|
||||
SoundDevice* sim = new_sound_device(&ds[j], ms, siminfo);
|
||||
if (sim != NULL)
|
||||
{
|
||||
|
||||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SOUND;
|
||||
simdevices[j].fps = ds[j].fps;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
{
|
||||
slogw("Could not initialize Sound Device");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
#define _SIMDEVICE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include <lua.h>
|
||||
|
||||
#include "usbdevice.h"
|
||||
#include "sounddevice.h"
|
||||
#include "serialdevice.h"
|
||||
|
||||
#include "hapticeffect.h"
|
||||
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
@@ -25,6 +30,8 @@ struct SimDevice
|
||||
int id;
|
||||
int fps;
|
||||
bool initialized;
|
||||
lua_State* L;
|
||||
char* device_specific_config_file;
|
||||
DeviceType type;
|
||||
HapticEffect hapticeffect;
|
||||
};
|
||||
@@ -49,13 +56,18 @@ typedef struct
|
||||
int id;
|
||||
SerialType type;
|
||||
struct sp_port* port;
|
||||
|
||||
SerialDeviceType devicetype;
|
||||
// move these two they only apply to the haptic device
|
||||
int motorsposition;
|
||||
int numlights;
|
||||
int numleds;
|
||||
int startled;
|
||||
int endled;
|
||||
int baudrate;
|
||||
double ampfactor;
|
||||
double state;
|
||||
double fanpower;
|
||||
double hapticstate;
|
||||
union
|
||||
{
|
||||
SimWindData simwinddata;
|
||||
@@ -71,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;
|
||||
|
||||
@@ -87,12 +99,15 @@ 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;
|
||||
@@ -100,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 *****/
|
||||
@@ -109,14 +124,13 @@ typedef struct
|
||||
SimDevice m;
|
||||
int id;
|
||||
int configcheck;
|
||||
SoundEffectModulationType modulationType;
|
||||
SoundData sounddata;
|
||||
#ifdef USE_PULSEAUDIO
|
||||
//#ifdef USE_PULSEAUDIO
|
||||
pa_stream *stream;
|
||||
#else
|
||||
PaStreamParameters outputParameters;
|
||||
PaStream* stream;
|
||||
#endif
|
||||
//#else
|
||||
//PaStreamParameters outputParameters;
|
||||
//PaStream* stream;
|
||||
//#endif
|
||||
}
|
||||
SoundDevice;
|
||||
|
||||
@@ -125,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 *********/
|
||||
|
||||
@@ -133,10 +147,23 @@ 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);
|
||||
|
||||
int simdevfree(SimDevice* this);
|
||||
|
||||
|
||||
/****** USB SubTypes ****************/
|
||||
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);
|
||||
|
||||
int tachdev_update(USBDevice* tachdevice, SimData* simdata);
|
||||
int tachdev_init(USBDevice* tachdevice, DeviceSettings* ds);
|
||||
int tachdev_free(USBDevice* tachdevice);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "../slog/slog.h"
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
|
||||
pa_threaded_mainloop* mainloop;
|
||||
pa_context* context;
|
||||
|
||||
@@ -21,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);
|
||||
|
||||
@@ -32,48 +28,50 @@ 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);
|
||||
}
|
||||
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
slogi("successfully connected pulseaudio...");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int freesound()
|
||||
{
|
||||
if (mainloop) {
|
||||
pa_threaded_mainloop_lock(mainloop);
|
||||
}
|
||||
|
||||
if (context)
|
||||
{
|
||||
pa_context_unref(context);
|
||||
slogt("freed pulseaudio context");
|
||||
}
|
||||
|
||||
if (mainloop) {
|
||||
pa_signal_done();
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
pa_threaded_mainloop_free(mainloop);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int setupsound()
|
||||
{
|
||||
slogi("connecting portaudio...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int freesound()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
//int setupsound()
|
||||
//{
|
||||
// slogi("connecting portaudio...");
|
||||
//}
|
||||
//
|
||||
//
|
||||
//int freesound()
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
#include "../simdevice.h"
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
//#ifdef USE_PULSEAUDIO
|
||||
int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop, pa_context* context, const char* devname, int volume, int pan, int channels, const char* streamname);
|
||||
int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop);
|
||||
#else
|
||||
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
||||
int usb_generic_shaker_free(SoundDevice* sounddevice);
|
||||
#endif
|
||||
//#else
|
||||
//int usb_generic_shaker_init(SoundDevice* sounddevice);
|
||||
//int usb_generic_shaker_free(SoundDevice* sounddevice);
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
#ifdef USE_PULSEAUDIO
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
#include "usb_generic_shaker.h"
|
||||
#include "../sounddevice.h"
|
||||
|
||||
#define FORMAT PA_SAMPLE_S16LE
|
||||
#define SAMPLE_RATE (44100)
|
||||
#define AMPLITUDE .5
|
||||
#define AMPLITUDE 1
|
||||
#define DURATION 1.0
|
||||
|
||||
#ifndef M_PI
|
||||
#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;
|
||||
@@ -27,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 = AMPLITUDE * 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 = AMPLITUDE * 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);
|
||||
}
|
||||
@@ -94,18 +116,29 @@ void stream_state_cb(pa_stream *s, void *mainloop) {
|
||||
pa_threaded_mainloop_signal(mainloop, 0);
|
||||
}
|
||||
|
||||
|
||||
int usb_generic_shaker_free(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop)
|
||||
{
|
||||
if(!mainloop)
|
||||
{
|
||||
// if this happens we are in trouble
|
||||
return 1;
|
||||
}
|
||||
|
||||
pa_threaded_mainloop_lock(mainloop);
|
||||
|
||||
int err = 0;
|
||||
if (sounddevice->stream)
|
||||
{
|
||||
pa_stream_disconnect(sounddevice->stream);
|
||||
pa_stream_unref(sounddevice->stream);
|
||||
// why is this wrong
|
||||
//pa_xfree(sounddevice->stream);
|
||||
|
||||
|
||||
}
|
||||
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -158,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;
|
||||
|
||||
@@ -174,13 +207,16 @@ 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(;;) {
|
||||
for(;;)
|
||||
{
|
||||
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
||||
assert(PA_STREAM_IS_GOOD(stream_state));
|
||||
if (stream_state == PA_STREAM_READY) break;
|
||||
PA_STREAM_IS_GOOD(stream_state);
|
||||
//PA_STREAM_IS_GOOD(stream_state);
|
||||
if (stream_state == PA_STREAM_READY) break;
|
||||
pa_threaded_mainloop_wait(mainloop);
|
||||
}
|
||||
|
||||
@@ -193,5 +229,3 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+142
-126
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "sound.h"
|
||||
#include "simdevice.h"
|
||||
@@ -14,17 +15,50 @@
|
||||
#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_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.frequency);
|
||||
slogt("set gear frequency to %f", sounddevice->sounddata.curr_frequency);
|
||||
}
|
||||
|
||||
|
||||
double modulate(SimDevice* this, double raw_effect, HapticEffectModulationType modulation)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
double modulated_effect = raw_effect;
|
||||
switch (modulation)
|
||||
{
|
||||
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 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 = 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 HAPTIC_EFFECT_MODULATION_NONE:
|
||||
default:
|
||||
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
|
||||
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
|
||||
break;
|
||||
}
|
||||
|
||||
return modulated_effect;
|
||||
}
|
||||
|
||||
// we could make a vtable for these different effects too
|
||||
@@ -32,45 +66,26 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
sounddevice->sounddata.curr_frequency = simdata->rpms/60;
|
||||
//sounddevice->sounddata.table_size = 48000/(sounddevice->sounddata.frequency);
|
||||
|
||||
slogt("set engine frequency to %i", sounddevice->sounddata.frequency);
|
||||
}
|
||||
|
||||
double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulationType modulation)
|
||||
{
|
||||
double modulated_effect = raw_effect;
|
||||
switch (modulation)
|
||||
{
|
||||
case SOUND_EFFECT_MODULATION_FREQUENCY:
|
||||
modulated_effect = (sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect;
|
||||
break;
|
||||
case SOUND_EFFECT_MODULATION_AMPLIFY:
|
||||
case SOUND_EFFECT_MODULATION_NONE:
|
||||
default:
|
||||
modulated_effect = raw_effect;
|
||||
}
|
||||
|
||||
return modulated_effect;
|
||||
double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60);
|
||||
slogt("Set base effect of %f from rpms of %i", effect, simdata->rpms);
|
||||
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)
|
||||
{
|
||||
effect = modulate(sounddevice, effect, sounddevice->modulationType);
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -80,17 +95,17 @@ 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)
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -98,80 +113,83 @@ 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)
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
|
||||
int sounddev_suspension_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
gear_sound_set(sounddevice, simdata);
|
||||
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(this, effect, this->hapticeffect.modulationType);
|
||||
}
|
||||
else
|
||||
{
|
||||
sounddevice->sounddata.curr_frequency = 0.0;
|
||||
sounddevice->sounddata.curr_amplitude = 0;
|
||||
sounddevice->sounddata.curr_duration = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
gear_sound_set(this, simdata);
|
||||
}
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
|
||||
int sounddev_free(SimDevice* this)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
usb_generic_shaker_free(sounddevice, mainloop);
|
||||
|
||||
free(sounddevice);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
int sounddev_free(SimDevice* this)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
usb_generic_shaker_free(sounddevice);
|
||||
|
||||
free(sounddevice);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
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("frequency is: %i", sds.frequency);
|
||||
slogi("frequency Max is: %i", sds.frequencyMax);
|
||||
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.curr_frequency = 0;
|
||||
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.0;
|
||||
|
||||
|
||||
const char* streamname= "Engine";
|
||||
switch (sounddevice->m.hapticeffect.effecttype) {
|
||||
case (EFFECT_GEARSHIFT):
|
||||
sounddevice->sounddata.last_gear = 0;
|
||||
sounddevice->sounddata.duration = sds.duration;
|
||||
sounddevice->sounddata.duration = 0.125;
|
||||
streamname = "Gear";
|
||||
break;
|
||||
case (EFFECT_TYRESLIP):
|
||||
@@ -183,18 +201,18 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId
|
||||
case (EFFECT_ABSBRAKES):
|
||||
streamname = "ABS";
|
||||
break;
|
||||
case (EFFECT_SUSPENSION):
|
||||
streamname = "Suspension";
|
||||
break;
|
||||
case (EFFECT_ENGINERPM):
|
||||
default:
|
||||
streamname = "Engine";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
|
||||
|
||||
//pa_threaded_mainloop* mainloop;
|
||||
//pa_context* context;
|
||||
usb_generic_shaker_init(sounddevice, mainloop, context, devname, sds.volume, sds.pan, sds.channels, streamname);
|
||||
#else
|
||||
usb_generic_shaker_init(sounddevice);
|
||||
#endif
|
||||
//usb_generic_shaker_init(sounddevice);
|
||||
}
|
||||
|
||||
static const vtable engine_sound_simdevice_vtable = { &sounddev_engine_update, &sounddev_free };
|
||||
@@ -202,74 +220,73 @@ static const vtable gear_sound_simdevice_vtable = { &sounddev_gearshift_update,
|
||||
static const vtable tyreslip_sound_simdevice_vtable = { &sounddev_tyreslip_update, &sounddev_free };
|
||||
static const vtable tyrelock_sound_simdevice_vtable = { &sounddev_tyrelock_update, &sounddev_free };
|
||||
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):
|
||||
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->dev);
|
||||
error = sounddev_init(this, ds->dev, ds->sounddevsettings);
|
||||
}
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
free(this);
|
||||
@@ -278,4 +295,3 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,24 @@
|
||||
#ifndef _SOUNDDEVICE_H
|
||||
#define _SOUNDDEVICE_H
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
//#ifdef USE_PULSEAUDIO
|
||||
#include <pulse/pulseaudio.h>
|
||||
#else
|
||||
#include "portaudio.h"
|
||||
#endif
|
||||
//#else
|
||||
//#include "portaudio.h"
|
||||
//#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
|
||||
{
|
||||
int last_gear;
|
||||
uint8_t last_gear;
|
||||
int volume;
|
||||
uint32_t frequency;
|
||||
uint32_t frequencyMax;
|
||||
double duration;
|
||||
int curr_frequency;
|
||||
double curr_frequency;
|
||||
uint32_t curr_amplitude;
|
||||
double curr_duration;
|
||||
double phase;
|
||||
double noise;
|
||||
}
|
||||
SoundData;
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tachdevice.h"
|
||||
#include "revburner.h"
|
||||
#include "../../helper/confighelper.h"
|
||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../../slog/slog.h"
|
||||
//#include "tachdevice.h"
|
||||
#include "simdevice.h"
|
||||
#include "usb/revburner.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
int tachdev_update(TachDevice* tachdevice, SimData* simdata)
|
||||
int tachdev_update(USBDevice* usbdevice, SimData* simdata)
|
||||
{
|
||||
TachDevice* tachdevice = &usbdevice->u.tachdevice;
|
||||
// current plan is to just use the revburner xml format for other possible tachometer devices
|
||||
// with that assumption this same logic is assumed the same for other tachometer devices
|
||||
// the only difference then being in communication to the physical device
|
||||
@@ -43,30 +45,33 @@ int tachdev_update(TachDevice* tachdevice, SimData* simdata)
|
||||
}
|
||||
}
|
||||
slogt("Settings tachometer pulses to %i", pulses);
|
||||
revburner_update(tachdevice, pulses);
|
||||
revburner_update(usbdevice, pulses);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tachdev_free(TachDevice* tachdevice)
|
||||
int tachdev_free(USBDevice* usbdevice)
|
||||
{
|
||||
TachDevice* tachdevice = &usbdevice->u.tachdevice;
|
||||
switch ( tachdevice->type )
|
||||
{
|
||||
case TACHDEV_UNKNOWN :
|
||||
case TACHDEV_REVBURNER :
|
||||
revburner_update(tachdevice, 0);
|
||||
revburner_free(tachdevice);
|
||||
revburner_update(usbdevice, 0);
|
||||
revburner_free(usbdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tachdev_init(TachDevice* tachdevice, DeviceSettings* ds)
|
||||
int tachdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||
{
|
||||
slogi("initializing tachometer device...");
|
||||
|
||||
TachDevice* tachdevice = &usbdevice->u.tachdevice;
|
||||
int error = 0;
|
||||
// detection of tach device model
|
||||
tachdevice->type = TACHDEV_UNKNOWN;
|
||||
@@ -74,7 +79,7 @@ int tachdev_init(TachDevice* tachdevice, DeviceSettings* ds)
|
||||
|
||||
tachdevice->tachsettings = ds->tachsettings;
|
||||
|
||||
error = revburner_init(tachdevice);
|
||||
error = revburner_init(usbdevice);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _TACHDEVICE_H
|
||||
#define _TACHDEVICE_H
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
@@ -19,13 +19,10 @@ typedef struct
|
||||
int id;
|
||||
TachType type;
|
||||
bool use_pulses;
|
||||
hid_device* handle;
|
||||
TachometerSettings tachsettings;
|
||||
}
|
||||
TachDevice;
|
||||
|
||||
int tachdev_update(TachDevice* tachdevice, SimData* simdata);
|
||||
int tachdev_init(TachDevice* tachdevice, DeviceSettings* ds);
|
||||
int tachdev_free(TachDevice* tachdevice);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "tachdevice.h"
|
||||
#include "../slog/slog.h"
|
||||
#include "../simdevice.h"
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
const size_t REVBURNER_BUFSIZE = 8;
|
||||
|
||||
|
||||
int revburner_update(TachDevice* tachdevice, int pulses)
|
||||
int revburner_update(USBDevice* tachdevice, int pulses)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
@@ -37,7 +37,7 @@ int revburner_update(TachDevice* tachdevice, int pulses)
|
||||
return res;
|
||||
}
|
||||
|
||||
int revburner_free(TachDevice* tachdevice)
|
||||
int revburner_free(USBDevice* tachdevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ int revburner_free(TachDevice* tachdevice)
|
||||
return res;
|
||||
}
|
||||
|
||||
int revburner_init(TachDevice* tachdevice)
|
||||
int revburner_init(USBDevice* tachdevice)
|
||||
{
|
||||
slogi("initializing revburner tachometer...");
|
||||
//tachdevice->update_tachometer = revburner_device_update;
|
||||
@@ -64,6 +64,6 @@ int revburner_init(TachDevice* tachdevice)
|
||||
res = hid_exit();
|
||||
return 1;
|
||||
}
|
||||
slogd("Found RevBurner Tachometer...");
|
||||
slogd("Found RevBurner Tachometer handle %i...", tachdevice->handle);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#ifndef _REVBURNER_H
|
||||
#define _REVBURNER_H
|
||||
|
||||
int revburner_update(TachDevice* tachdevice, int pulses);
|
||||
int revburner_init(TachDevice* tachdevice);
|
||||
int revburner_free(TachDevice* tachdevice);
|
||||
#include "../simdevice.h"
|
||||
|
||||
int revburner_update(USBDevice* tachdevice, int pulses);
|
||||
int revburner_init(USBDevice* tachdevice);
|
||||
int revburner_free(USBDevice* tachdevice);
|
||||
|
||||
#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_write(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]);
|
||||
}
|
||||
@@ -27,10 +27,10 @@ int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, s
|
||||
{
|
||||
slogd("no handle");
|
||||
}
|
||||
return res;
|
||||
return res != bufsize;
|
||||
}
|
||||
|
||||
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play)
|
||||
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
@@ -44,45 +44,47 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
bytes[0] = 0xEC;
|
||||
bytes[0] = 241;
|
||||
bytes[1] = 0xEC;
|
||||
// we can add config settings for these values
|
||||
bytes[2] = 0x01;
|
||||
bytes[3] = 0x0A;
|
||||
bytes[4] = 0xFF;
|
||||
bytes[3] = 0x01;
|
||||
bytes[4] = 0x0A;
|
||||
bytes[5] = 0xFF;
|
||||
switch (effecttype)
|
||||
{
|
||||
case (EFFECT_TYRESLIP):
|
||||
bytes[1] = 0x02;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x02;
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
bytes[1] = 0x01;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x01;
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
bytes[1] = 0x02;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[1] = 0x01;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x02;
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x01;
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes[1] = 0x01;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[1] = 0x02;
|
||||
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[0] = 241;
|
||||
bytes[2] = 0x01;
|
||||
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[2] = 0x02;
|
||||
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;
|
||||
@@ -90,7 +92,7 @@ int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
|
||||
return res;
|
||||
}
|
||||
|
||||
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
int simagicp1000_init(USBDevice* usbdevice)
|
||||
{
|
||||
slogi("initializing %s...", SIMAGICP1000DEVSTRING);
|
||||
|
||||
@@ -98,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();
|
||||
@@ -113,14 +115,15 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
}
|
||||
bytes[0] = 0xF1;
|
||||
bytes[1] = 0x17;
|
||||
bytes[2] = 0x00;
|
||||
bytes[0] = 241;
|
||||
bytes[1] = 0xF1;
|
||||
bytes[2] = 0x17;
|
||||
bytes[3] = 0x00;
|
||||
bytes[4] = 0x00;
|
||||
bytes[5] = 0x01;
|
||||
bytes[6] = 0x02;
|
||||
res = senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
|
||||
bytes[5] = 0x00;
|
||||
bytes[6] = 0x01;
|
||||
bytes[7] = 0x02;
|
||||
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
|
||||
@@ -4,17 +4,21 @@
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "cammusc12.h"
|
||||
#include "../../serial/arduinoledlua.h"
|
||||
#include "../../../slog/slog.h"
|
||||
|
||||
const int cammusc12_hidupdate_buf_size = 16;
|
||||
const int cammusc12_hidledupdate_buf_size = 7;
|
||||
|
||||
int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity)
|
||||
const int cammusc12_total_leds = 23;
|
||||
|
||||
int cammusc12_update(USBDevice* usbdevice, int maxrpm, int rpm, int gear, int velocity)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
|
||||
unsigned char bytes[cammusc12_hidupdate_buf_size];
|
||||
|
||||
|
||||
for (int x = 0; x < cammusc12_hidupdate_buf_size; x++)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
@@ -42,10 +46,11 @@ int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, in
|
||||
// byte 4 is gear
|
||||
bytes[6] = gear-1;
|
||||
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x%02x%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], rpm, velocity, gear);
|
||||
if (wheeldevice->handle)
|
||||
|
||||
if (usbdevice->handle)
|
||||
{
|
||||
res = hid_write(wheeldevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02xx%02xx%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], rpm, velocity, gear);
|
||||
res = hid_write(usbdevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -55,17 +60,23 @@ int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, in
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc12_free(WheelDevice* wheeldevice)
|
||||
int cammusc12_free(USBDevice* wheeldevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(wheeldevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
if(wheeldevice->u.wheeldevice.useLua == true)
|
||||
{
|
||||
slogt("closing lua");
|
||||
lua_close(wheeldevice->m.L);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc12_init(WheelDevice* wheeldevice)
|
||||
int cammusc12_init_(USBDevice* wheeldevice)
|
||||
{
|
||||
slogi("initializing cammus c12 wheel...");
|
||||
|
||||
@@ -84,3 +95,137 @@ int cammusc12_init(WheelDevice* wheeldevice)
|
||||
slogd("Found Cammus C12 Wheel...");
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc12_init(USBDevice* wheeldevice, const char* luafile)
|
||||
{
|
||||
|
||||
wheeldevice->u.wheeldevice.useLua = false;
|
||||
int res = cammusc12_init_(wheeldevice);
|
||||
|
||||
if(!wheeldevice->handle)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(luafile == NULL)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
slogt("Using lua file for cammus c12 device");
|
||||
|
||||
lua_State* L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
//int top=lua_gettop(L);
|
||||
int status = luaL_loadfile(L, luafile);
|
||||
|
||||
if (status) {
|
||||
/* If something went wrong, error message is at the top of */
|
||||
/* the stack */
|
||||
sloge("There is an issue with your lua script");
|
||||
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
|
||||
lua_close(L);
|
||||
return -1;
|
||||
//exit(1);
|
||||
}
|
||||
|
||||
wheeldevice->u.wheeldevice.useLua = true;
|
||||
lua_setglobal(L,"myFunc");
|
||||
|
||||
wheeldevice->m.L = L;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int cammusc12_customled_update(USBDevice* usbdevice, SimData* simdata)
|
||||
{
|
||||
int result = 1;
|
||||
|
||||
|
||||
size_t bufsize = (cammusc12_total_leds * 3);
|
||||
char ledbytes[bufsize];
|
||||
for(int x = 0; x < bufsize; x++)
|
||||
{
|
||||
ledbytes[x] = 0x00;
|
||||
}
|
||||
|
||||
lua_State* L = usbdevice->m.L;
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_pushlightuserdata(L, &ledbytes);
|
||||
lua_settable(L, LUA_REGISTRYINDEX);
|
||||
|
||||
simdata_to_lua(L, simdata);
|
||||
lua_setglobal(L, "simdata");
|
||||
|
||||
lua_pushinteger(L, cammusc12_total_leds);
|
||||
lua_setglobal(L, "TotalLeds");
|
||||
|
||||
lua_register(L, "set_led_to_color", set_led_to_color);
|
||||
lua_register(L, "set_led_range_to_color", set_led_range_to_color);
|
||||
lua_register(L, "set_led_to_rgb_color", set_led_to_rgb_color);
|
||||
lua_register(L, "set_led_range_to_rgb_color", set_led_range_to_rgb_color);
|
||||
lua_register(L, "led_clear_all", led_clear_all);
|
||||
|
||||
lua_pushinteger(L, LUALEDCOLOR_RED);
|
||||
lua_setglobal(L, "RED");
|
||||
lua_pushinteger(L, LUALEDCOLOR_GREEN);
|
||||
lua_setglobal(L, "GREEN");
|
||||
lua_pushinteger(L, LUALEDCOLOR_BLUE);
|
||||
lua_setglobal(L, "BLUE");
|
||||
lua_pushinteger(L, LUALEDCOLOR_YELLOW);
|
||||
lua_setglobal(L, "YELLOW");
|
||||
lua_pushinteger(L, LUALEDCOLOR_ORANGE);
|
||||
lua_setglobal(L, "ORANGE");
|
||||
|
||||
lua_getglobal(L,"myFunc");
|
||||
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
|
||||
{
|
||||
fprintf(stderr, "Error calling Lua script: %s\n", lua_tostring(L, -1));
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
|
||||
unsigned char bytes[cammusc12_hidledupdate_buf_size];
|
||||
for(int x = 0; x < cammusc12_hidledupdate_buf_size; x++)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
}
|
||||
bytes[0] = 0xFA;
|
||||
bytes[1] = 0xFB;
|
||||
bytes[2] = 0x02;
|
||||
|
||||
for(int i = 0; i < cammusc12_total_leds; i++)
|
||||
{
|
||||
if(i >= 15) // make this a setting
|
||||
{
|
||||
for (int x = 3; x < cammusc12_hidledupdate_buf_size; x++)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
}
|
||||
uint8_t led = i+1;
|
||||
uint8_t red = ledbytes[(i * 3) + 0];
|
||||
uint8_t green = ledbytes[(i * 3) + 1];
|
||||
uint8_t blue = ledbytes[(i * 3) + 2];
|
||||
|
||||
bytes[3] = led;
|
||||
bytes[4] = red;
|
||||
bytes[5] = green;
|
||||
bytes[6] = blue;
|
||||
|
||||
|
||||
if (usbdevice->handle)
|
||||
{
|
||||
res = hid_write(usbdevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02xx%02xx%02x from red %i green %i blue %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], red, green, blue);
|
||||
}
|
||||
else
|
||||
{
|
||||
slogd("no handle");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#define _CAMMUSC12_H
|
||||
|
||||
#include "../../wheeldevice.h"
|
||||
#include "../../simdevice.h"
|
||||
|
||||
int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
int cammusc12_init(WheelDevice* wheeldevice);
|
||||
int cammusc12_free(WheelDevice* wheeldevice);
|
||||
int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
int cammusc12_customled_update(USBDevice* usbdevice, SimData* simdata);
|
||||
int cammusc12_init(USBDevice* wheeldevice, const char* luafile);
|
||||
int cammusc12_free(USBDevice* wheeldevice);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
const int cammusc5_hidupdate_buf_size = 14;
|
||||
const int num_avail_leds = 9;
|
||||
|
||||
int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity)
|
||||
int cammusc5_update(USBDevice* usbdevice, int maxrpm, int rpm, int gear, int velocity)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
|
||||
unsigned char bytes[cammusc5_hidupdate_buf_size];
|
||||
|
||||
|
||||
for (int x = 0; x < cammusc5_hidupdate_buf_size; x++)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
@@ -56,9 +56,9 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
|
||||
bytes[4] = gear-1;
|
||||
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], rpm, velocity, gear);
|
||||
if (wheeldevice->handle)
|
||||
if (usbdevice->handle)
|
||||
{
|
||||
res = hid_write(wheeldevice->handle, bytes, cammusc5_hidupdate_buf_size);
|
||||
res = hid_write(usbdevice->handle, bytes, cammusc5_hidupdate_buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -68,17 +68,17 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc5_free(WheelDevice* wheeldevice)
|
||||
int cammusc5_free(USBDevice* usbdevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(wheeldevice->handle);
|
||||
hid_close(usbdevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc5_init(WheelDevice* wheeldevice)
|
||||
int cammusc5_init(USBDevice* usbdevice)
|
||||
{
|
||||
slogi("initializing cammus c5 wheel...");
|
||||
|
||||
@@ -86,9 +86,9 @@ int cammusc5_init(WheelDevice* wheeldevice)
|
||||
|
||||
res = hid_init();
|
||||
|
||||
wheeldevice->handle = hid_open(0x3416, 0x1021, NULL);
|
||||
usbdevice->handle = hid_open(0x3416, 0x1021, NULL);
|
||||
|
||||
if (!wheeldevice->handle)
|
||||
if (!usbdevice->handle)
|
||||
{
|
||||
sloge("Could not find attached Cammus C5 Wheel");
|
||||
res = hid_exit();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef _CAMMUSC5_H
|
||||
#define _CAMMUSC5_H
|
||||
|
||||
#include "../../wheeldevice.h"
|
||||
#include "../../simdevice.h"
|
||||
|
||||
int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
int cammusc5_init(WheelDevice* wheeldevice);
|
||||
int cammusc5_free(WheelDevice* wheeldevice);
|
||||
int cammusc5_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
int cammusc5_init(USBDevice* wheeldevice);
|
||||
int cammusc5_free(USBDevice* wheeldevice);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "gtneo.h"
|
||||
#include <string.h>
|
||||
#include "../../../slog/slog.h"
|
||||
#include "../../serial/arduinoledlua.h"
|
||||
|
||||
// Simagic allows setting any led, therefore LED index should be defined.
|
||||
struct LED {
|
||||
uint8_t index;
|
||||
uint8_t red;
|
||||
uint8_t green;
|
||||
uint8_t blue;
|
||||
};
|
||||
|
||||
// Simagic is using SEND_FEATURE_REPORT
|
||||
// ReportID is 240 (0xf0)
|
||||
// Data length is 64 bytes
|
||||
// Prefix is 00 00 00 00 00
|
||||
// Then we have some descriptor. I had 0xEC and 0x03.
|
||||
// Then: length of LED array
|
||||
// Then: number of LED in hex
|
||||
// RGB value for that LED
|
||||
|
||||
|
||||
void prepare_device(hid_device *device) {
|
||||
uint8_t prepare_report[SIMAGIC_MAX_PAYLOAD_SIZE] = {0};
|
||||
prepare_report[0] = 0x00;
|
||||
prepare_report[1] = 0x00;
|
||||
prepare_report[2] = 0x00;
|
||||
prepare_report[3] = 0x00;
|
||||
prepare_report[4] = 0x00;
|
||||
prepare_report[5] = SIMAGIC_LED_DESCRIPTOR_LED_CONTROL;
|
||||
prepare_report[6] = SIMAGIC_LED_DESCRIPTOR_PREPARE_LEDS;
|
||||
prepare_report[7] = 0x01;
|
||||
|
||||
uint8_t report_id_with_data[SIMAGIC_MAX_PAYLOAD_SIZE] = {SIMAGIC_LED_REPORT_ID}; // Report ID at the start
|
||||
memcpy(&report_id_with_data[1], prepare_report, SIMAGIC_MAX_PAYLOAD_SIZE-1);
|
||||
|
||||
// Send the HID feature report
|
||||
int res = hid_send_feature_report(device, report_id_with_data, sizeof(report_id_with_data));
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Failed to send HID feature report\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Arbitrary function for sending out leds to simagic.
|
||||
Inputs:
|
||||
device: hid_device handle
|
||||
leds: array of the struct LED
|
||||
led_count: count of leds in leds array
|
||||
*/
|
||||
int send_leds(hid_device *device, struct LED* leds, size_t led_count) {
|
||||
uint8_t descriptor[2] = {SIMAGIC_LED_DESCRIPTOR_LED_CONTROL, SIMAGIC_LED_DESCRIPTOR_SET_LEDS};
|
||||
|
||||
prepare_device(device);
|
||||
int result = 0;
|
||||
size_t led_i = 0;
|
||||
while (led_i < led_count) {
|
||||
size_t chunk_length = (SIMAGIC_MAX_PAYLOAD_SIZE -1-9) / 4; // 1 for reportid, 9 bytes for header, rest for LED data (each LED is 4 bytes)
|
||||
size_t chunk_size = chunk_length * 4;
|
||||
|
||||
uint8_t report[SIMAGIC_MAX_PAYLOAD_SIZE] = {0}; // SIMAGIC_MAX_PAYLOAD_SIZE bytes per report
|
||||
memcpy(report, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00}, 5); // Set the prefix (5 bytes)
|
||||
|
||||
memcpy(&report[5], descriptor, 2); // Set the descriptor (2 bytes)
|
||||
|
||||
// Fill in the LED data
|
||||
for (size_t i = 0; i < chunk_length && led_i + i < led_count; ++i) {
|
||||
memcpy(&report[8+i*4], &leds[led_i+i], 4);
|
||||
report[7]++; // Set the LED array length for this chunk
|
||||
}
|
||||
|
||||
uint8_t report_id_with_data[SIMAGIC_MAX_PAYLOAD_SIZE] = {SIMAGIC_LED_REPORT_ID};
|
||||
memcpy(&report_id_with_data[1], report, SIMAGIC_MAX_PAYLOAD_SIZE-1);
|
||||
|
||||
// Send the HID feature report
|
||||
int res = hid_send_feature_report(device, report_id_with_data, sizeof(report_id_with_data));
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Failed to send HID feature report chunk\n");
|
||||
return -1;
|
||||
}
|
||||
result += res;
|
||||
|
||||
// Move to the next chunk of LEDs
|
||||
led_i += chunk_length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// default simpro profile:
|
||||
// 97: b b b b b b b b b b b b b b b //flashing
|
||||
// 93: b b b b b b b b b b b b b b b //flashing
|
||||
// 90: g g g g g g g g g y y y w w w
|
||||
// 88: g g g g g g g g g y y y
|
||||
// 85: g g g g g g g g g
|
||||
// 83: g g g g g g g
|
||||
// 78: g g g g g
|
||||
// 75: g g g
|
||||
// 70: g
|
||||
// less: empty (000000)
|
||||
// Telemetry LEDs are 58-72
|
||||
|
||||
|
||||
int simagic_gtneo_customled_update(USBDevice* usbdevice, SimData* simdata)
|
||||
{
|
||||
int res = 1;
|
||||
|
||||
size_t led_count = GT_NEO_LEDS_TOTAL-GT_NEO_LEDS_TELEMETRY_START; // Expose whole LED array
|
||||
size_t bufsize = (led_count * 3);
|
||||
char ledbytes[bufsize];
|
||||
for(int x = 0; x < bufsize; x++)
|
||||
ledbytes[x] = 0x00;
|
||||
|
||||
lua_State* L = usbdevice->m.L;
|
||||
|
||||
lua_pushstring(L, "buff");
|
||||
lua_pushlightuserdata(L, &ledbytes);
|
||||
lua_settable(L, LUA_REGISTRYINDEX);
|
||||
|
||||
simdata_to_lua(L, simdata);
|
||||
lua_setglobal(L, "simdata");
|
||||
|
||||
lua_pushinteger(L, led_count);
|
||||
lua_setglobal(L, "TotalLeds");
|
||||
|
||||
lua_register(L, "set_led_to_color", set_led_to_color);
|
||||
lua_register(L, "set_led_range_to_color", set_led_range_to_color);
|
||||
lua_register(L, "set_led_to_rgb_color", set_led_to_rgb_color);
|
||||
lua_register(L, "set_led_range_to_rgb_color", set_led_range_to_rgb_color);
|
||||
lua_register(L, "led_clear_all", led_clear_all);
|
||||
|
||||
lua_pushinteger(L, LUALEDCOLOR_RED);
|
||||
lua_setglobal(L, "RED");
|
||||
lua_pushinteger(L, LUALEDCOLOR_GREEN);
|
||||
lua_setglobal(L, "GREEN");
|
||||
lua_pushinteger(L, LUALEDCOLOR_BLUE);
|
||||
lua_setglobal(L, "BLUE");
|
||||
lua_pushinteger(L, LUALEDCOLOR_YELLOW);
|
||||
lua_setglobal(L, "YELLOW");
|
||||
lua_pushinteger(L, LUALEDCOLOR_ORANGE);
|
||||
lua_setglobal(L, "ORANGE");
|
||||
|
||||
lua_getglobal(L,"myFunc");
|
||||
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
|
||||
{
|
||||
fprintf(stderr, "Error calling Lua script: %s\n", lua_tostring(L, -1));
|
||||
}
|
||||
|
||||
// ledbytes is an array of leds. We need to copy colours to our struct LED and call 'send_leds'
|
||||
struct LED teleleds[led_count];
|
||||
|
||||
for (int i = 0; i < led_count; i++) {
|
||||
teleleds[i] = (struct LED){GT_NEO_LEDS_TELEMETRY_START+i, 0x00, 0x00, 0x00};
|
||||
teleleds[i].red = ledbytes[(i * 3) + 0];
|
||||
teleleds[i].green = ledbytes[(i * 3) + 1];
|
||||
teleleds[i].blue = ledbytes[(i * 3) + 2];
|
||||
}
|
||||
|
||||
res = send_leds(usbdevice->handle, teleleds, led_count);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int simagic_gtneo_init(USBDevice* wheeldevice, const char* luafile)
|
||||
{
|
||||
wheeldevice->u.wheeldevice.useLua = false;
|
||||
|
||||
slogi("initializing Simagic GT Neo wheel...");
|
||||
|
||||
int res = 0;
|
||||
|
||||
res = hid_init();
|
||||
|
||||
wheeldevice->handle = hid_open(SIMAGIC_GTNEO_VENDORID, SIMAGIC_GTNEO_PRODUCTID, NULL);
|
||||
|
||||
if (!wheeldevice->handle)
|
||||
{
|
||||
sloge("Could not find attached GT Neo Wheel");
|
||||
res = hid_exit();
|
||||
return 1;
|
||||
}
|
||||
slogd("Found Simagic GT Neo Wheel...");
|
||||
|
||||
slogt("Using lua file");
|
||||
|
||||
lua_State* L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
//int top=lua_gettop(L);
|
||||
int status = luaL_loadfile(L, luafile);
|
||||
|
||||
if (status) {
|
||||
/* If something went wrong, error message is at the top of */
|
||||
/* the stack */
|
||||
sloge("There is an issue with your lua script");
|
||||
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
|
||||
lua_close(L);
|
||||
return -1;
|
||||
//exit(1);
|
||||
}
|
||||
|
||||
wheeldevice->u.wheeldevice.useLua = true;
|
||||
lua_setglobal(L,"myFunc");
|
||||
|
||||
wheeldevice->m.L = L;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int simagic_gtneo_free(USBDevice* wheeldevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(wheeldevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef _GTNEO_H
|
||||
#define _GTNEO_H
|
||||
|
||||
#include "../../wheeldevice.h"
|
||||
#include "../../simdevice.h"
|
||||
|
||||
#define SIMAGIC_GTNEO_VENDORID 0x3670
|
||||
#define SIMAGIC_GTNEO_PRODUCTID 0x0805
|
||||
|
||||
#define SIMAGIC_MAX_PAYLOAD_SIZE 64
|
||||
#define SIMAGIC_LED_REPORT_ID 0xf0 // LED control report id?
|
||||
|
||||
#define SIMAGIC_LED_DESCRIPTOR_LED_CONTROL 0xEC // LED control?
|
||||
#define SIMAGIC_LED_DESCRIPTOR_PREPARE_LEDS 0x02 //probably something like 'prepare led canvas'
|
||||
#define SIMAGIC_LED_DESCRIPTOR_SET_LEDS 0x03 //probably 'set temporare leds'
|
||||
|
||||
// expose whole LED array to the lua.
|
||||
// Telemetry leds are 58-72
|
||||
#define GT_NEO_LEDS_TELEMETRY_START 0
|
||||
#define GT_NEO_LEDS_TOTAL 73
|
||||
|
||||
int simagic_gtneo_init(USBDevice* wheeldevice, const char* luafile);
|
||||
int simagic_gtneo_free(USBDevice* wheeldevice);
|
||||
int simagic_gtneo_customled_update(USBDevice* usbdevice, SimData* simdata);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "logitechg29.h"
|
||||
#include "../../../slog/slog.h"
|
||||
|
||||
const int logitechg29_hidupdate_buf_size = 7;
|
||||
|
||||
int logitechg29_update(USBDevice* usbdevice, int maxrpm, int rpm, int gear, int velocity)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
|
||||
uint8_t leds = 0;
|
||||
|
||||
float percent = 0;
|
||||
if(maxrpm > 0)
|
||||
{
|
||||
percent = (float) rpm / (float) maxrpm;
|
||||
|
||||
if (percent > .84)
|
||||
{
|
||||
leds = 0b11111;
|
||||
}
|
||||
else if (percent > .69)
|
||||
{
|
||||
leds = 0b1111;
|
||||
}
|
||||
else if (percent > .39)
|
||||
{
|
||||
leds = 0b111;
|
||||
}
|
||||
else if (percent > .19)
|
||||
{
|
||||
leds = 0b11;
|
||||
}
|
||||
else if (percent > .4)
|
||||
{
|
||||
leds = 0b1;
|
||||
}
|
||||
else
|
||||
{
|
||||
leds = 0b0;
|
||||
}
|
||||
}
|
||||
uint8_t bytes[7] = {
|
||||
0xF8,
|
||||
0x12,
|
||||
leds,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01
|
||||
};
|
||||
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x from rpm %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[6], rpm);
|
||||
if (usbdevice->handle)
|
||||
{
|
||||
res = hid_write(usbdevice->handle, bytes, logitechg29_hidupdate_buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
slogd("no handle");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int logitechg29_free(USBDevice* usbdevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(usbdevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int logitechg29_init(USBDevice* usbdevice)
|
||||
{
|
||||
slogi("initializing Logitech G29 wheel...");
|
||||
|
||||
int res = 0;
|
||||
|
||||
res = hid_init();
|
||||
usbdevice->handle = hid_open(0x046D, 0xC24F, NULL);
|
||||
|
||||
if (!usbdevice->handle)
|
||||
{
|
||||
sloge("Could not find attached Logitech G29 Wheel");
|
||||
res = hid_exit();
|
||||
return 1;
|
||||
}
|
||||
slogd("Found Logitech G29 Wheel...");
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef _LOGITECHG29_H
|
||||
#define _LOGITECHG29_H
|
||||
|
||||
#include "../../simdevice.h"
|
||||
|
||||
int logitechg29_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
int logitechg29_init(USBDevice* wheeldevice);
|
||||
int logitechg29_free(USBDevice* wheeldevice);
|
||||
|
||||
#endif
|
||||
@@ -17,13 +17,11 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
||||
tachdev_update(usbdevice, simdata);
|
||||
break;
|
||||
case USBDEV_WHEEL :
|
||||
wheeldev_update(&usbdevice->u.wheeldevice, 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;
|
||||
}
|
||||
|
||||
@@ -39,13 +37,10 @@ int usbdev_free(SimDevice* this)
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
tachdev_free(&usbdevice->u.tachdevice);
|
||||
tachdev_free(usbdevice);
|
||||
break;
|
||||
case USBDEV_WHEEL :
|
||||
wheeldev_free(&usbdevice->u.wheeldevice);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
||||
case USBDEV_WHEEL_OR_PEDALS :
|
||||
wheeldev_free(usbdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -64,58 +59,62 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
error = tachdev_init(&usbdevice->u.tachdevice, ds);
|
||||
error = tachdev_init(usbdevice, ds);
|
||||
break;
|
||||
case USBDEV_WHEEL :
|
||||
error = wheeldev_init(&usbdevice->u.wheeldevice, ds);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
||||
case USBDEV_WHEEL_OR_PEDALS :
|
||||
error = wheeldev_init(usbdevice, 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,15 +99,13 @@ 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");
|
||||
}
|
||||
|
||||
if(usbhapticdevice->handle == 0)
|
||||
{
|
||||
error = MONOCOQUE_ERROR_INVALID_DEV;
|
||||
return error;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -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,73 +2,223 @@
|
||||
#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 "wheeldevice.h"
|
||||
#include "../helper/confighelper.h"
|
||||
|
||||
|
||||
#include "usb/cslelitev3.h"
|
||||
#include "usb/simagicp1000.h"
|
||||
#include "usb/simnetpedals.h"
|
||||
|
||||
#include "simdevice.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
int wheeldev_update(WheelDevice* wheeldevice, 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 :
|
||||
case WHEELDEV_CAMMUSC5 :
|
||||
cammusc5_update(wheeldevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
cammusc5_update(usbdevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
break;
|
||||
case WHEELDEV_LOGITECHG29 :
|
||||
logitechg29_update(usbdevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
break;
|
||||
case WHEELDEV_CAMMUSC12 :
|
||||
cammusc12_update(wheeldevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
if(usbdevice->u.wheeldevice.useLua == true)
|
||||
{
|
||||
cammusc12_customled_update(usbdevice, simdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
cammusc12_update(usbdevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
}
|
||||
break;
|
||||
|
||||
case WHEELDEV_SIMAGICGTNEO :
|
||||
if(usbdevice->u.wheeldevice.useLua == true)
|
||||
{
|
||||
simagic_gtneo_customled_update(usbdevice, simdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("GT Neo requires config file");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wheeldev_free(WheelDevice* wheeldevice)
|
||||
int wheeldev_free(USBDevice* usbdevice)
|
||||
{
|
||||
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||
slogt("wheel device free");
|
||||
switch ( wheeldevice->type )
|
||||
{
|
||||
case WHEELDEV_UNKNOWN :
|
||||
case WHEELDEV_CAMMUSC5 :
|
||||
cammusc5_update(wheeldevice, 0, 0, 0, 0);
|
||||
cammusc5_free(wheeldevice);
|
||||
cammusc5_update(usbdevice, 0, 0, 0, 0);
|
||||
cammusc5_free(usbdevice);
|
||||
break;
|
||||
case WHEELDEV_LOGITECHG29 :
|
||||
logitechg29_update(usbdevice, 0, 0, 0, 0);
|
||||
logitechg29_free(usbdevice);
|
||||
break;
|
||||
case WHEELDEV_CAMMUSC12 :
|
||||
cammusc12_update(wheeldevice, 0, 0, 0, 0);
|
||||
cammusc12_free(wheeldevice);
|
||||
cammusc12_free(usbdevice);
|
||||
if(wheeldevice->useLua == true)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int wheeldev_init(WheelDevice* wheeldevice, DeviceSettings* ds)
|
||||
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) {
|
||||
|
||||
case SIMDEVSUBTYPE_CAMMUSC5:
|
||||
wheeldevice->type = WHEELDEV_CAMMUSC5;
|
||||
slogi("Attempting to initialize cammus C5");
|
||||
error = cammusc5_init(wheeldevice);
|
||||
error = cammusc5_init(usbdevice);
|
||||
break;
|
||||
case SIMDEVSUBTYPE_LOGITECH_G29:
|
||||
wheeldevice->type = WHEELDEV_LOGITECHG29;
|
||||
slogi("Attempting to initialize Logitech G29");
|
||||
error = logitechg29_init(usbdevice);
|
||||
break;
|
||||
case SIMDEVSUBTYPE_CAMMUSC12:
|
||||
wheeldevice->type = WHEELDEV_CAMMUSC12;
|
||||
slogi("Attempting to initialize cammus C12");
|
||||
error = cammusc12_init(wheeldevice);
|
||||
|
||||
if(ds->has_config == true)
|
||||
{
|
||||
usbdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||
error = cammusc12_init(usbdevice, usbdevice->m.device_specific_config_file);
|
||||
if(error != 0)
|
||||
{
|
||||
if(usbdevice->m.device_specific_config_file != NULL)
|
||||
{
|
||||
free(usbdevice->m.device_specific_config_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = cammusc12_init(usbdevice, NULL);
|
||||
}
|
||||
break;
|
||||
case SIMDEVSUBTYPE_SIMAGICGTNEO:
|
||||
wheeldevice->type = WHEELDEV_SIMAGICGTNEO;
|
||||
slogi("Attempting to initialize Simagic GT Neo");
|
||||
|
||||
if(ds->has_config == true)
|
||||
{
|
||||
usbdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||
error = simagic_gtneo_init(usbdevice, usbdevice->m.device_specific_config_file);
|
||||
if(error != 0)
|
||||
{
|
||||
if(usbdevice->m.device_specific_config_file != NULL)
|
||||
{
|
||||
free(usbdevice->m.device_specific_config_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Simagic GT Neo requires lua config file to function");
|
||||
error = -1;
|
||||
}
|
||||
break;
|
||||
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:
|
||||
wheeldevice->type = WHEELDEV_UNKNOWN;
|
||||
slogw("Unknown cammus wheel detected, trying C5");
|
||||
error = cammusc5_init(wheeldevice);
|
||||
break;
|
||||
slogw("Possibly unknown wheel device");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef _WHEELDEVICE_H
|
||||
#define _WHEELDEVICE_H
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
@@ -9,10 +8,15 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WHEELDEV_UNKNOWN = 0,
|
||||
WHEELDEV_CAMMUSC5 = 1,
|
||||
WHEELDEV_CAMMUSC12 = 2,
|
||||
WHEELDEV_MOZAR5 = 3
|
||||
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;
|
||||
|
||||
@@ -20,13 +24,10 @@ typedef struct
|
||||
{
|
||||
int id;
|
||||
WheelType type;
|
||||
hid_device* handle;
|
||||
bool useLua;
|
||||
char* port;
|
||||
}
|
||||
WheelDevice;
|
||||
|
||||
int wheeldev_update(WheelDevice* wheeldevice, SimData* simdata);
|
||||
int wheeldev_init(WheelDevice* wheeldevice, DeviceSettings* ds);
|
||||
int wheeldev_free(WheelDevice* wheeldevice);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,3 +10,5 @@ set(LIBXML_INCLUDE_DIR /usr/include/libxml2)
|
||||
include_directories("." ${LIBXML_INCLUDE_DIR})
|
||||
|
||||
add_library(gameloop STATIC ${gameloop_source_files})
|
||||
|
||||
set_property(TARGET gameloop PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
+561
-145
@@ -11,11 +11,9 @@
|
||||
|
||||
#include "gameloop.h"
|
||||
#include "loopdata.h"
|
||||
|
||||
#include "../helper/parameters.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../devices/simdevice.h"
|
||||
#include "../devices/serialadapter.h"
|
||||
#include "../devices/hapticeffect.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../simulatorapi/simapi/simapi/simmapper.h"
|
||||
#include "../slog/slog.h"
|
||||
@@ -25,20 +23,44 @@
|
||||
bool go = false;
|
||||
bool go2 = false;
|
||||
struct sigaction act;
|
||||
static pthread_t loop_thread;
|
||||
static uv_loop_t *loop = NULL;
|
||||
|
||||
SimData* simdata;
|
||||
SimMap* simmap;
|
||||
loop_data* baton;
|
||||
|
||||
device_loop_data* test_baton;
|
||||
SimDevice* test_simdevice;
|
||||
SimInfo* test_siminfo;
|
||||
|
||||
|
||||
uv_idle_t idler;
|
||||
uv_timer_t datachecktimer;
|
||||
uv_timer_t showstatstimer;
|
||||
uv_timer_t datamaptimer;
|
||||
uv_timer_t tyrediametertimer;
|
||||
uv_timer_t testdevicetimer;
|
||||
uv_udp_t recv_socket;
|
||||
|
||||
bool doui = false;
|
||||
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");
|
||||
@@ -216,61 +238,95 @@ 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;
|
||||
configcheck(ms->config_str, confignum, &configureddevices);
|
||||
|
||||
DeviceSettings* ds = malloc(configureddevices * sizeof(DeviceSettings));
|
||||
slogd("loading confignum %i, with %i devices.", confignum, configureddevices);
|
||||
|
||||
f->numdevices = uiloadconfig(ms->config_str, confignum, configureddevices, ms, ds);
|
||||
|
||||
if(ms->useconfig == 1)
|
||||
{
|
||||
ms->configcheck = 0;
|
||||
}
|
||||
|
||||
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
|
||||
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
|
||||
int i = 0;
|
||||
for( i = 0; i < configureddevices; i++)
|
||||
int initdevices = devinit(f->simdevices, &f->siminfo, configureddevices, ds, ms);
|
||||
slogi("initialized %i devices", initdevices);
|
||||
|
||||
for( int i = 0; i < configureddevices; i++)
|
||||
{
|
||||
settingsfree(ds[i]);
|
||||
}
|
||||
free(ds);
|
||||
|
||||
|
||||
for(int d = 0; d < 10; d++)
|
||||
{
|
||||
monocoque_serial_devices[d].open = false;
|
||||
monocoque_serial_devices[d].openfail = false;
|
||||
monocoque_serial_devices[d].busy = false;
|
||||
monocoque_serial_devices[d].refs = 0;
|
||||
}
|
||||
|
||||
|
||||
int numdevices = f->numdevices;
|
||||
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++)
|
||||
{
|
||||
@@ -284,53 +340,79 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||
uv_handle_set_data((uv_handle_t*) dt, (void*) dld);
|
||||
int interval = 1000/devices[x].fps;
|
||||
uv_timer_start(dt, devicetimercallback, 0, interval);
|
||||
slogi("starting device at %i fps (%i ms ticks)", devices[x].fps, interval);
|
||||
slogi("starting device type %i at id at %i fps: %i (%i ms ticks)", devices[x].type, x, devices[x].fps, interval);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//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 shmdatamapcallback(uv_timer_t* handle)
|
||||
void showstatscallback(uv_timer_t* handle)
|
||||
{
|
||||
void* b = uv_handle_get_data((uv_handle_t*) handle);
|
||||
loop_data* f = (loop_data*) b;
|
||||
SimData* simdata = f->simdata;
|
||||
SimMap* simmap = f->simmap;
|
||||
MonocoqueSettings* ms = f->ms;
|
||||
//appstate = 2;
|
||||
if (appstate == 2)
|
||||
if(appstate == 2)
|
||||
{
|
||||
simdatamap(simdata, simmap, NULL, f->map, false, NULL);
|
||||
looprun(ms, f, simdata);
|
||||
showstats(simdata);
|
||||
}
|
||||
}
|
||||
|
||||
if (f->simstate == false || simdata->simstatus <= 1 || appstate <= 1)
|
||||
{
|
||||
void releaseloop(loop_data* f, SimData* simdata, SimMap* simmap)
|
||||
{
|
||||
slogi("release loop");
|
||||
if(f->releasing == false)
|
||||
{
|
||||
f->releasing = true;
|
||||
uv_timer_stop(handle);
|
||||
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;
|
||||
|
||||
// help things spin down
|
||||
simdata->simstatus = 0;
|
||||
simdata->rpms = 0;
|
||||
simdata->velocity = 0;
|
||||
|
||||
@@ -355,6 +437,7 @@ void shmdatamapcallback(uv_timer_t* handle)
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
@@ -364,15 +447,7 @@ void shmdatamapcallback(uv_timer_t* handle)
|
||||
}
|
||||
free(devices);
|
||||
|
||||
for(int d = 0; d < 10; d++)
|
||||
{
|
||||
if(monocoque_serial_devices[d].portname != NULL)
|
||||
{
|
||||
free(monocoque_serial_devices[d].portname);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -381,7 +456,8 @@ void shmdatamapcallback(uv_timer_t* handle)
|
||||
|
||||
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)
|
||||
@@ -389,6 +465,25 @@ void shmdatamapcallback(uv_timer_t* handle)
|
||||
appstate = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void shmdatamapcallback(uv_timer_t* handle)
|
||||
{
|
||||
void* b = uv_handle_get_data((uv_handle_t*) handle);
|
||||
loop_data* f = (loop_data*) b;
|
||||
SimData* simdata = f->simdata;
|
||||
SimMap* simmap = f->simmap;
|
||||
MonocoqueSettings* ms = f->ms;
|
||||
//appstate = 2;
|
||||
if (appstate == 2)
|
||||
{
|
||||
simapi_datamap(simdata, simmap, f->siminfo.mapapi, false, NULL);
|
||||
looprun(ms, f, simdata);
|
||||
}
|
||||
|
||||
if (f->siminfo.isSimOn == false || simdata->simstatus <= 1 || appstate <= 1)
|
||||
{
|
||||
releaseloop(f, simdata, simmap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,6 +498,10 @@ static void on_udp_recv(uv_udp_t* handle, ssize_t nread, const uv_buf_t* rcvbuf,
|
||||
if (nread > 0) {
|
||||
slogt("udp data received");
|
||||
}
|
||||
if (nread <= 0) {
|
||||
free(rcvbuf->base);
|
||||
return;
|
||||
}
|
||||
|
||||
char* a;
|
||||
a = rcvbuf->base;
|
||||
@@ -415,56 +514,13 @@ 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)
|
||||
{
|
||||
if(f->releasing == false)
|
||||
{
|
||||
f->releasing = true;
|
||||
uv_udp_recv_stop(handle);
|
||||
slogi("releasing devices, please wait");
|
||||
f->uion = false;
|
||||
SimDevice* devices = f->simdevices;
|
||||
int numdevices = f->numdevices;
|
||||
|
||||
// help things spin down
|
||||
simdata->rpms = 0;
|
||||
simdata->velocity = 0;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].free(&devices[x]);
|
||||
}
|
||||
}
|
||||
free(devices);
|
||||
int r = simfree(simdata, simmap, f->map);
|
||||
slogd("simfree returned %i", r);
|
||||
f->numdevices = 0;
|
||||
slogi("stopped mapping data, press q again to quit");
|
||||
//stopui(ms->ui_type, f);
|
||||
// free loop data
|
||||
|
||||
if(appstate > 0)
|
||||
{
|
||||
uv_timer_start(&datachecktimer, datacheckcallback, 3000, 1000);
|
||||
}
|
||||
f->releasing = false;
|
||||
if(appstate > 1)
|
||||
{
|
||||
appstate = 1;
|
||||
}
|
||||
}
|
||||
releaseloop(f, simdata, simmap);
|
||||
}
|
||||
|
||||
slogt("udp free :%lu %p\n",rcvbuf->len,rcvbuf->base);
|
||||
@@ -473,7 +529,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);
|
||||
@@ -486,7 +542,7 @@ void udpstart(MonocoqueSettings* sms, loop_data* f, SimData* simdata, SimMap* si
|
||||
{
|
||||
if (appstate == 2)
|
||||
{
|
||||
simdatamap(simdata, simmap, NULL, f->sim, true, NULL);
|
||||
simapi_datamap(simdata, simmap, f->siminfo.simulatorapi, true, NULL);
|
||||
if (doui == true)
|
||||
{
|
||||
looprun(sms, f, simdata);
|
||||
@@ -503,19 +559,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 )
|
||||
{
|
||||
@@ -526,7 +577,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);
|
||||
@@ -539,13 +590,21 @@ 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (appstate == 0)
|
||||
{
|
||||
slogi("stopping checking for data");
|
||||
slogi("stopped checking for data");
|
||||
uv_timer_stop(handle);
|
||||
}
|
||||
}
|
||||
@@ -570,6 +629,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);
|
||||
}
|
||||
@@ -577,11 +640,240 @@ void cb(uv_poll_t* handle, int status, int events)
|
||||
|
||||
|
||||
|
||||
void* monocoque_mainloop_start(void* arg)
|
||||
{
|
||||
MonocoqueSettings* ms = arg;
|
||||
simdata = malloc(sizeof(SimData));
|
||||
simmap = simapi_simmap_create();
|
||||
slogd("setting initial app state");
|
||||
appstate = 1;
|
||||
|
||||
//struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||
//uv_poll_t* poll = (uv_poll_t*) malloc(uv_handle_size(UV_POLL));
|
||||
|
||||
baton = (loop_data*) malloc(sizeof(loop_data));
|
||||
baton->siminfo.mapapi = -1;
|
||||
baton->simmap = simmap;
|
||||
baton->simdata = simdata;
|
||||
baton->ms = ms;
|
||||
baton->uion = false;
|
||||
baton->releasing = false;
|
||||
baton->use_udp = false;
|
||||
baton->req.data = (void*) baton;
|
||||
|
||||
|
||||
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 NULL;
|
||||
//};
|
||||
|
||||
uv_udp_init(loop, &recv_socket);
|
||||
uv_timer_init(loop, &datachecktimer);
|
||||
uv_timer_init(loop, &datamaptimer);
|
||||
uv_timer_init(loop, &tyrediametertimer);
|
||||
|
||||
|
||||
|
||||
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 NULL;
|
||||
//};
|
||||
|
||||
uv_timer_start(&datachecktimer, datacheckcallback, 1000, 1000);
|
||||
|
||||
//fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SimData* get_test_simdata()
|
||||
{
|
||||
if(test_baton == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return test_baton->simdata;
|
||||
}
|
||||
|
||||
void* monocoque_testloop_start(void* arg)
|
||||
{
|
||||
test_loop_args* args = arg;
|
||||
simmap = simapi_simmap_create();
|
||||
|
||||
|
||||
simapi_set_log_info(simapilib_loginfo);
|
||||
simapi_set_log_debug(simapilib_logdebug);
|
||||
simapi_set_log_trace(simapilib_logtrace);
|
||||
|
||||
|
||||
DeviceSettings ds;
|
||||
//int numdevices = getsingledevice(args->ms->config_str, args->confignum, args->devicenum, args->ms, &ds);
|
||||
test_simdevice = malloc(1 * sizeof(SimDevice));
|
||||
test_siminfo = malloc(sizeof(SimInfo));
|
||||
simapi_set_faux_siminfo(test_siminfo);
|
||||
int initdevices = devinit(test_simdevice, test_siminfo, 1, args->ds, args->ms);
|
||||
//settingsfree(ds);
|
||||
|
||||
|
||||
|
||||
test_baton->siminfo.mapapi = -1;
|
||||
test_baton->simdevice = test_simdevice;
|
||||
|
||||
test_baton->ms = args->ms;
|
||||
test_baton->req.data = (void*) test_baton;
|
||||
|
||||
|
||||
uv_timer_init(loop, &testdevicetimer);
|
||||
uv_handle_set_data((uv_handle_t*) &testdevicetimer, (void*) test_baton);
|
||||
uv_timer_start(&testdevicetimer, devicetimercallback, 1000, 16);
|
||||
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int monocoque_testloop_stop()
|
||||
{
|
||||
uv_timer_stop(&testdevicetimer);
|
||||
|
||||
uv_stop(loop);
|
||||
pthread_join(loop_thread, NULL);
|
||||
|
||||
uv_run(loop, UV_RUN_NOWAIT);
|
||||
uv_walk(loop, close_walk_cb, NULL);
|
||||
uv_loop_close(loop);
|
||||
uv_library_shutdown();
|
||||
|
||||
slogi("All threads stopped...");
|
||||
|
||||
test_simdevice->free(test_simdevice);
|
||||
free(loop);
|
||||
free(test_baton);
|
||||
//free(simdata);
|
||||
free(simmap);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int monocoque_mainloop_stop(MonocoqueSettings* ms)
|
||||
{
|
||||
|
||||
uv_udp_recv_stop(&recv_socket);
|
||||
uv_timer_stop(&datamaptimer);
|
||||
uv_timer_stop(&datachecktimer);
|
||||
|
||||
uv_stop(loop);
|
||||
pthread_join(loop_thread, NULL);
|
||||
|
||||
uv_run(loop, UV_RUN_NOWAIT);
|
||||
uv_walk(loop, close_walk_cb, NULL);
|
||||
uv_loop_close(loop);
|
||||
uv_library_shutdown();
|
||||
|
||||
slogi("All threads stopped...");
|
||||
|
||||
free(loop);
|
||||
free(baton);
|
||||
free(simdata);
|
||||
free(simmap);
|
||||
|
||||
appstate = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int start_loop(MonocoqueSettings* ms)
|
||||
{
|
||||
loop = malloc(sizeof(uv_loop_t));
|
||||
|
||||
if (loop == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uv_loop_init(loop) != 0)
|
||||
{
|
||||
free(loop);
|
||||
loop = NULL;
|
||||
return -1;
|
||||
}
|
||||
return pthread_create(&loop_thread, NULL, monocoque_mainloop_start, ms);
|
||||
}
|
||||
|
||||
int start_test(test_loop_args* test_data)
|
||||
{
|
||||
|
||||
test_baton = (device_loop_data*) malloc(sizeof(device_loop_data));
|
||||
test_baton->simdata = test_data->simdata;
|
||||
|
||||
loop = malloc(sizeof(uv_loop_t));
|
||||
|
||||
if (loop == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uv_loop_init(loop) != 0)
|
||||
{
|
||||
free(loop);
|
||||
loop = NULL;
|
||||
return -1;
|
||||
}
|
||||
return pthread_create(&loop_thread, NULL, monocoque_testloop_start, test_data);
|
||||
}
|
||||
|
||||
const char* get_simexe_name(void)
|
||||
{
|
||||
if(appstate <= 0)
|
||||
{
|
||||
return "None Detected";
|
||||
}
|
||||
if(baton == NULL)
|
||||
{
|
||||
return "None Detected";
|
||||
}
|
||||
if(baton->siminfo.simulatorexe <= 0)
|
||||
{
|
||||
return "None Detected";
|
||||
}
|
||||
return simapi_gametofullstr(baton->siminfo.simulatorexe);
|
||||
}
|
||||
|
||||
const char* get_simd_onoff(void)
|
||||
{
|
||||
if(appstate <= 0)
|
||||
{
|
||||
return "Not Detected";
|
||||
}
|
||||
if(baton == NULL)
|
||||
{
|
||||
return "Not Detected";
|
||||
}
|
||||
if(baton->siminfo.mapapi == 0)
|
||||
{
|
||||
return "Running";
|
||||
}
|
||||
return "Not Detected";
|
||||
}
|
||||
|
||||
int monocoque_mainloop(MonocoqueSettings* ms)
|
||||
{
|
||||
|
||||
SimData* simdata = malloc(sizeof(SimData));
|
||||
SimMap* simmap = createSimMap();
|
||||
simdata = malloc(sizeof(SimData));
|
||||
simmap = simapi_simmap_create();
|
||||
|
||||
struct termios newsettings, canonicalmode;
|
||||
tcgetattr(0, &canonicalmode);
|
||||
@@ -595,54 +887,117 @@ int monocoque_mainloop(MonocoqueSettings* ms)
|
||||
|
||||
uv_poll_t* poll = (uv_poll_t*) malloc(uv_handle_size(UV_POLL));
|
||||
|
||||
loop_data* baton = (loop_data*) malloc(sizeof(loop_data));
|
||||
baton = (loop_data*) malloc(sizeof(loop_data));
|
||||
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*) &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);
|
||||
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;
|
||||
}
|
||||
|
||||
void set_basic_simdata(SimData* simdata)
|
||||
{
|
||||
simdata->car[0] = 'C';
|
||||
simdata->car[1] = 'A';
|
||||
simdata->car[2] = 'R';
|
||||
simdata->car[3] = '\0';
|
||||
simdata->gear = SIMAPI_GEAR_NEUTRAL;
|
||||
simdata->gearc[0] = 0x4e;
|
||||
simdata->gearc[1] = 0;
|
||||
simdata->velocity = 160;
|
||||
simdata->rpms = 7000;
|
||||
simdata->maxrpm = 8000;
|
||||
simdata->abs = 0;
|
||||
simdata->tyrediameter[0] = -1;
|
||||
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;
|
||||
}
|
||||
|
||||
void set_wheel_spin_simdata(SimData* simdata)
|
||||
{
|
||||
simdata->velocity = 15;
|
||||
simdata->tyreRPS[0] = 50;
|
||||
simdata->tyreRPS[1] = 50;
|
||||
simdata->tyreRPS[2] = 50;
|
||||
simdata->tyreRPS[3] = 50;
|
||||
simdata->tyrediameter[0] = 0.638636385206394;
|
||||
simdata->tyrediameter[1] = 0.633384434597093;
|
||||
simdata->tyrediameter[2] = 0.710475735564615;
|
||||
simdata->tyrediameter[3] = 0.710475735564615;
|
||||
}
|
||||
|
||||
void set_wheel_lock_simdata(SimData* simdata)
|
||||
{
|
||||
simdata->velocity = 150;
|
||||
simdata->tyreRPS[0] = 25;
|
||||
simdata->tyreRPS[1] = 25;
|
||||
simdata->tyreRPS[2] = 25;
|
||||
simdata->tyreRPS[3] = 25;
|
||||
simdata->tyrediameter[0] = 0.638636385206394;
|
||||
simdata->tyrediameter[1] = 0.633384434597093;
|
||||
simdata->tyrediameter[2] = 0.710475735564615;
|
||||
simdata->tyrediameter[3] = 0.710475735564615;
|
||||
}
|
||||
|
||||
int tester(SimDevice* devices, int numdevices)
|
||||
{
|
||||
|
||||
@@ -663,7 +1018,9 @@ int tester(SimDevice* devices, int numdevices)
|
||||
simdata->car[2] = 'R';
|
||||
simdata->car[3] = '\0';
|
||||
|
||||
simdata->gear = MONOCOQUE_GEAR_NEUTRAL;
|
||||
simdata->gear = SIMAPI_GEAR_NEUTRAL;
|
||||
simdata->gearc[0] = 0x4e;
|
||||
simdata->gearc[1] = 0;
|
||||
simdata->velocity = 16;
|
||||
simdata->rpms = 100;
|
||||
simdata->maxrpm = 8000;
|
||||
@@ -672,11 +1029,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;
|
||||
@@ -689,8 +1078,12 @@ int tester(SimDevice* devices, int numdevices)
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Green Flag!\n");
|
||||
simdata->playerflag = SIMAPI_FLAG_GREEN;
|
||||
|
||||
fprintf(stdout, "Shifting into first gear\n");
|
||||
simdata->gear = 2;
|
||||
simdata->gear = SIMAPI_GEAR_FIRST;
|
||||
simdata->gearc[0] = 0x31;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
@@ -755,7 +1148,8 @@ int tester(SimDevice* devices, int numdevices)
|
||||
simdata->tyrediameter[2] = -1;
|
||||
simdata->tyrediameter[3] = -1;
|
||||
simdata->abs = 0;
|
||||
simdata->gear = 3;
|
||||
simdata->gear = SIMAPI_GEAR_SECOND;
|
||||
simdata->gearc[0] = 0x32;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
@@ -804,8 +1198,12 @@ int tester(SimDevice* devices, int numdevices)
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Yellow Flag!\n");
|
||||
simdata->playerflag = SIMAPI_FLAG_YELLOW;
|
||||
|
||||
fprintf(stdout, "Shifting into third gear\n");
|
||||
simdata->gear = 4;
|
||||
simdata->gear = SIMAPI_GEAR_THIRD;
|
||||
simdata->gearc[0] = 0x33;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
@@ -826,6 +1224,9 @@ int tester(SimDevice* devices, int numdevices)
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Blue Flag!\n");
|
||||
simdata->playerflag = SIMAPI_FLAG_BLUE;
|
||||
|
||||
fprintf(stdout, "Setting rpms to 4000\n");
|
||||
simdata->rpms = 4000;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
@@ -838,7 +1239,8 @@ int tester(SimDevice* devices, int numdevices)
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Shifting into fourth gear\n");
|
||||
simdata->gear = 5;
|
||||
simdata->gear = SIMAPI_GEAR_FOURTH;
|
||||
simdata->gearc[0] = 0x34;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
@@ -870,6 +1272,9 @@ int tester(SimDevice* devices, int numdevices)
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Red Flag!\n");
|
||||
simdata->playerflag = SIMAPI_FLAG_RED;
|
||||
|
||||
fprintf(stdout, "Setting rpms to 8000\n");
|
||||
simdata->rpms = 8000;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
@@ -879,11 +1284,22 @@ int tester(SimDevice* devices, int numdevices)
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
for(int x = 0; x < 100; x++)
|
||||
{
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
simdata->velocity = 0;
|
||||
simdata->rpms = 100;
|
||||
simdata->gear = MONOCOQUE_GEAR_NEUTRAL;
|
||||
simdata->gear = SIMAPI_GEAR_NEUTRAL;
|
||||
simdata->gearc[0] = 0x4e;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
#include "../devices/simdevice.h"
|
||||
#include "../helper/parameters.h"
|
||||
#include "loopdata.h"
|
||||
|
||||
extern int appstate;
|
||||
|
||||
int tester(SimDevice* devices, int numdevices);
|
||||
int looper(SimDevice* devices, int numdevices, Parameters* p);
|
||||
|
||||
int monocoque_mainloop(MonocoqueSettings* ms);
|
||||
|
||||
int start_loop(MonocoqueSettings* ms);
|
||||
int start_test(test_loop_args* test_loop_data);
|
||||
int monocoque_mainloop_stop(MonocoqueSettings* ms);
|
||||
int monocoque_testloop_stop();
|
||||
|
||||
const char* get_simd_onoff(void);
|
||||
const char* get_simexe_name(void);
|
||||
SimData* get_test_simdata();
|
||||
|
||||
|
||||
void set_basic_simdata(SimData* simdata);
|
||||
void set_wheel_spin_simdata(SimData* simdata);
|
||||
void set_wheel_lock_simdata(SimData* simdata);
|
||||
|
||||
@@ -10,29 +10,43 @@
|
||||
|
||||
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;
|
||||
|
||||
|
||||
typedef struct test_loop_args
|
||||
{
|
||||
MonocoqueSettings* ms;
|
||||
DeviceSettings* ds;
|
||||
SimData* simdata;
|
||||
int devicenum;
|
||||
int confignum;
|
||||
} test_loop_args;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,3 +11,5 @@ set(LIBXML_INCLUDE_DIR /usr/include/libxml2)
|
||||
include_directories("." ${LIBXML_INCLUDE_DIR})
|
||||
|
||||
add_library(helper STATIC ${helper_source_files})
|
||||
|
||||
set_property(TARGET helper PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
+819
-142
File diff suppressed because it is too large
Load Diff
@@ -13,26 +13,32 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SIMDEV_UNKNOWN = 0,
|
||||
SIMDEV_USB = 1,
|
||||
SIMDEV_SOUND = 2,
|
||||
SIMDEV_SERIAL = 3
|
||||
SIMDEV_USB = 0,
|
||||
SIMDEV_SOUND = 1,
|
||||
SIMDEV_SERIAL = 2,
|
||||
SIMDEV_UNKNOWN = 3,
|
||||
}
|
||||
DeviceType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SIMDEVTYPE_UNKNOWN = 0,
|
||||
SIMDEVTYPE_TACHOMETER = 1,
|
||||
SIMDEVTYPE_USBHAPTIC = 2,
|
||||
SIMDEVTYPE_SHIFTLIGHTS = 3,
|
||||
SIMDEVTYPE_SIMWIND = 4,
|
||||
SIMDEVTYPE_SERIALHAPTIC = 5,
|
||||
SIMDEVTYPE_USBWHEEL = 6,
|
||||
SIMDEVTYPE_SERIALWHEEL = 7
|
||||
SIMDEVTYPE_SOUNDHAPTIC = 1,
|
||||
SIMDEVTYPE_TACHOMETER = 2,
|
||||
SIMDEVTYPE_USBHAPTIC = 3,
|
||||
SIMDEVTYPE_USBWHEEL = 4,
|
||||
SIMDEVTYPE_SHIFTLIGHTS = 5,
|
||||
SIMDEVTYPE_SIMWIND = 6,
|
||||
SIMDEVTYPE_SERIALHAPTIC = 7,
|
||||
SIMDEVTYPE_SERIALWHEEL = 8,
|
||||
SIMDEVTYPE_SIMLED = 9,
|
||||
SIMDEVTYPE_ARDUINOCUSTOM = 10,
|
||||
}
|
||||
DeviceSubType;
|
||||
|
||||
#define SerialDevicesOffset 5
|
||||
#define USBDevicesOffset 2
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SIMDEVSUBTYPE_UNKNOWN = 0,
|
||||
@@ -40,7 +46,13 @@ typedef enum
|
||||
SIMDEVSUBTYPE_CAMMUSC12 = 2,
|
||||
SIMDEVSUBTYPE_MOZAR5 = 3,
|
||||
SIMDEVSUBTYPE_CSLELITEV3PEDALS = 4,
|
||||
SIMDEVSUBTYPE_SIMAGICP1000PEDALS =5
|
||||
SIMDEVSUBTYPE_SIMAGICP1000PEDALS = 5,
|
||||
SIMDEVSUBTYPE_SIMAGICGTNEO = 6,
|
||||
SIMDEVSUBTYPE_MOZA_NEW = 7,
|
||||
SIMDEVSUBTYPE_LOGITECH_G29 = 8,
|
||||
SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL = 9,
|
||||
SIMDEVSUBTYPE_SIMNETPEDALS = 10,
|
||||
SIMDEVSUBTYPE_REVBURNERTACHOMETER = 11
|
||||
}
|
||||
DeviceSubSubType;
|
||||
|
||||
@@ -62,10 +74,19 @@ typedef enum
|
||||
EFFECT_GEARSHIFT = 1,
|
||||
EFFECT_ABSBRAKES = 2,
|
||||
EFFECT_TYRESLIP = 3,
|
||||
EFFECT_TYRELOCK = 4
|
||||
EFFECT_TYRELOCK = 4,
|
||||
EFFECT_SUSPENSION = 5
|
||||
}
|
||||
VibrationEffectType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EFFECT_MODULATION_NONE = 0,
|
||||
EFFECT_MODULATION_FREQUENCY = 1,
|
||||
EFFECT_MODULATION_AMPLIFY = 2,
|
||||
}
|
||||
EffectModulationType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MOTOR_1 = 0,
|
||||
@@ -103,12 +124,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;
|
||||
|
||||
@@ -133,10 +155,12 @@ typedef struct
|
||||
int verbosity_count;
|
||||
int fps;
|
||||
bool force_udp_mode;
|
||||
bool disable_audio;
|
||||
char* tyre_diameter_config;
|
||||
char* config_str;
|
||||
char* log_filename_str;
|
||||
char* log_dirname_str;
|
||||
config_t* cfg;
|
||||
}
|
||||
MonocoqueSettings;
|
||||
|
||||
@@ -152,33 +176,46 @@ TachometerSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* portdev;
|
||||
MotorPosition motorsposition;
|
||||
int numlights;
|
||||
uint32_t numlights;
|
||||
uint32_t numleds;
|
||||
uint32_t startled;
|
||||
uint32_t endled;
|
||||
float ampfactor;
|
||||
int baud;
|
||||
float fanpower;
|
||||
// baud is the only serial thing
|
||||
uint32_t baud;
|
||||
}
|
||||
SerialDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t frequency;
|
||||
uint32_t volume;
|
||||
int lowbound_frequency;
|
||||
int upperbound_frequency;
|
||||
uint32_t frequencyMax;
|
||||
int pan;
|
||||
int channels;
|
||||
double duration;
|
||||
char* dev;
|
||||
SoundEffectModulationType modulation;
|
||||
uint32_t pan;
|
||||
uint32_t channels;
|
||||
uint32_t noise;
|
||||
}
|
||||
SoundDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int value0;
|
||||
int value1;
|
||||
uint32_t frequency;
|
||||
uint32_t amplitude;
|
||||
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;
|
||||
@@ -186,21 +223,23 @@ USBDeviceSettings;
|
||||
typedef struct
|
||||
{
|
||||
bool is_valid;
|
||||
int fps;
|
||||
|
||||
DeviceType dev_type;
|
||||
DeviceSubType dev_subtype;
|
||||
DeviceSubSubType dev_subsubtype;
|
||||
// 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_haptic_effects;
|
||||
bool has_led_effects;
|
||||
|
||||
char* dev;
|
||||
bool has_config;
|
||||
char* specific_config_file;
|
||||
uint32_t fps;
|
||||
// union?
|
||||
HapticEffectSettings hapticsettings;
|
||||
TachometerSettings tachsettings;
|
||||
SerialDeviceSettings serialdevsettings;
|
||||
SoundDeviceSettings sounddevsettings;
|
||||
USBDeviceSettings usbdevsettings;
|
||||
|
||||
}
|
||||
DeviceSettings;
|
||||
|
||||
@@ -218,9 +257,16 @@ int getconfigtouse2(const char* config_file_str, char* car, int sim);
|
||||
int getconfigtouse1(const char* config_file_str, char* car, int sim);
|
||||
int getconfigtouse(const char* config_file_str, char* car, int sim);
|
||||
|
||||
config_t *open_monocoque_config(const char *filename);
|
||||
void close_monocoque_config(config_t *cfg);
|
||||
|
||||
int delete_device_config(config_t *cfg, const char *configfile, int confignum, int devicenum);
|
||||
int save_device_config(config_t *cfg, const char* configfile, int confignum, int devicenum, const DeviceSettings *ds);
|
||||
int configcheck(const char* config_file_str, int confignum, int* devices);
|
||||
|
||||
int uiloadconfig(const char* config_file_str, int confignum, int configureddevices, MonocoqueSettings* ms, DeviceSettings* ds);
|
||||
|
||||
int getsingledevice(const char* config_file_str, int confignum, int devicenum, MonocoqueSettings* ms, DeviceSettings* ds);
|
||||
|
||||
int getNumberOfConfigs(const char* config_file_str);
|
||||
#endif
|
||||
|
||||
@@ -48,19 +48,12 @@ char* gethome()
|
||||
char* homedir = getenv("HOME");
|
||||
return homedir;
|
||||
|
||||
if (homedir != NULL)
|
||||
{
|
||||
printf("Home dir in enviroment");
|
||||
printf("%s\n", homedir);
|
||||
}
|
||||
|
||||
uid_t uid = getuid();
|
||||
struct passwd* pw = getpwuid(uid);
|
||||
|
||||
if (pw == NULL)
|
||||
{
|
||||
printf("Failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pw->pw_dir;
|
||||
@@ -269,3 +262,30 @@ bool does_file_exist(const char* file)
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
char* expand_tilde(char* path) {
|
||||
if (path[0] != '~') {
|
||||
return path;
|
||||
}
|
||||
|
||||
const char* home_dir = getenv("HOME");
|
||||
if (!home_dir) {
|
||||
return path;
|
||||
}
|
||||
|
||||
size_t expanded_size = strlen(home_dir) + strlen(path);
|
||||
char* expanded_path = (char*)malloc(expanded_size + 1);
|
||||
|
||||
if (!expanded_path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
strcpy(expanded_path, home_dir);
|
||||
strcat(expanded_path, path + 1);
|
||||
|
||||
if (path) {
|
||||
free(path);
|
||||
}
|
||||
|
||||
return expanded_path;
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ bool does_directory_exist(char* path);
|
||||
void restrict_folders_to_cache(char* path, int cachesize);
|
||||
void delete_dir(char* path);
|
||||
bool does_file_exist(const char* file);
|
||||
char* expand_tilde(char* path);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -46,6 +46,7 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
p->verbosity_count = 0;
|
||||
p->fps = 60;
|
||||
|
||||
p->disable_audio = false;
|
||||
p->udp = false;
|
||||
|
||||
p->user_specified_config_file = false;
|
||||
@@ -61,14 +62,15 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
|
||||
struct arg_rex* cmd1 = arg_rex1(NULL, NULL, "play", NULL, REG_ICASE, NULL);
|
||||
struct arg_lit* arg_udp = arg_lit0("d", "udp", "force udp mode for sims which support it");
|
||||
struct arg_file* arg_conf = arg_filen(NULL, "uiconf", "<config_file>", 0, 1, NULL);
|
||||
struct arg_lit* arg_audio1 = arg_lit0("a", "disable_audio", "force disable of audio devices");
|
||||
struct arg_file* arg_conf = arg_file0("c", "uiconf", "<config_file>", NULL);
|
||||
struct arg_file* arg_log = arg_filen("l", "log", "<log_file>", 0, 1, NULL);
|
||||
struct arg_str* arg_confdir = arg_strn(NULL, "configdir", "config_dir>", 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_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);
|
||||
@@ -83,10 +85,11 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
int nerrors2;
|
||||
|
||||
struct arg_rex* cmd3 = arg_rex1(NULL, NULL, "test", NULL, REG_ICASE, NULL);
|
||||
struct arg_lit* arg_audio2 = arg_lit0("a", "disable_audio", "force disable of audio devices");
|
||||
struct arg_lit* help3 = arg_litn(NULL,"help", 0, 1, "print this help and exit");
|
||||
struct arg_lit* vers3 = arg_litn(NULL,"version", 0, 1, "print version information and exit");
|
||||
struct arg_end* end3 = arg_end(20);
|
||||
void* argtable3[] = {cmd3,arg_verbosity3,help3,vers3,end3};
|
||||
void* argtable3[] = {cmd3,arg_verbosity3,arg_audio2,help3,vers3,end3};
|
||||
int nerrors3;
|
||||
|
||||
struct arg_lit* help0 = arg_lit0(NULL,"help", "print this help and exit");
|
||||
@@ -111,8 +114,6 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
arg_granularity->ival[0] = 1;
|
||||
|
||||
nerrors0 = arg_parse(argc,argv,argtable0);
|
||||
nerrors1 = arg_parse(argc,argv,argtable1);
|
||||
nerrors2 = arg_parse(argc,argv,argtable2);
|
||||
@@ -120,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;
|
||||
|
||||
@@ -132,6 +141,10 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||
{
|
||||
p->udp = true;
|
||||
}
|
||||
if (arg_audio1->count > 0)
|
||||
{
|
||||
p->disable_audio = true;
|
||||
}
|
||||
if(arg_fps->count > 0)
|
||||
{
|
||||
p->fps = arg_fps->ival[0];
|
||||
@@ -149,60 +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;
|
||||
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);
|
||||
@@ -230,5 +258,4 @@ cleanup:
|
||||
arg_freetable(argtable2,sizeof(argtable2)/sizeof(argtable2[0]));
|
||||
arg_freetable(argtable3,sizeof(argtable3)/sizeof(argtable3[0]));
|
||||
return exitcode;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ typedef struct
|
||||
SimulatorAPI sim;
|
||||
bool simon;
|
||||
bool udp;
|
||||
bool disable_audio;
|
||||
|
||||
char* config_filepath;
|
||||
char* config_dirpath;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
set(mgui_source_files
|
||||
addeditaction.c
|
||||
addeditaction.h
|
||||
testaction.c
|
||||
testaction.h
|
||||
uiconfighelper.c
|
||||
uiconfighelper.h
|
||||
mainwindow.h
|
||||
)
|
||||
|
||||
set(NAPPGUI_DEMO NO CACHE BOOL "" FORCE)
|
||||
set(NAPPGUI_WEB False CACHE BOOL "Build NAppGUI WebView support.")
|
||||
set(_saved_build_type ${CMAKE_BUILD_TYPE})
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
add_subdirectory(nappgui_src)
|
||||
set(CMAKE_BUILD_TYPE ${_saved_build_type})
|
||||
|
||||
|
||||
add_library(mgui STATIC ${mgui_source_files} ${NAppGUI_SOURCE_DIR}/src)
|
||||
set_property(TARGET mgui PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
add_dependencies(mgui gui osapp osgui draw2d geom2d core osbs sewer encode)
|
||||
target_include_directories(mgui PUBLIC ${LIBXML_INCLUDE_DIR} ${NAppGUI_SOURCE_DIR}/src ${GTK3_INCLUDE_DIRS})
|
||||
set_target_properties(mgui PROPERTIES LINKER_LANGUAGE C)
|
||||
|
||||
set(NAPPGUI_LIB_DIR ${CMAKE_BINARY_DIR}/Release/lib)
|
||||
target_link_libraries(mgui PUBLIC
|
||||
#gui osapp osgui draw2d geom2d core osbs sewer osapp encode
|
||||
${NAPPGUI_LIB_DIR}/libgui.a
|
||||
${NAPPGUI_LIB_DIR}/libosapp.a
|
||||
${NAPPGUI_LIB_DIR}/libosgui.a
|
||||
${NAPPGUI_LIB_DIR}/libdraw2d.a
|
||||
${NAPPGUI_LIB_DIR}/libgeom2d.a
|
||||
${NAPPGUI_LIB_DIR}/libcore.a
|
||||
${NAPPGUI_LIB_DIR}/libosbs.a
|
||||
${NAPPGUI_LIB_DIR}/libsewer.a
|
||||
${NAPPGUI_LIB_DIR}/libosapp.a
|
||||
${NAPPGUI_LIB_DIR}/libencode.a
|
||||
${GTK3_LIBRARIES})
|
||||
@@ -0,0 +1,604 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <nappgui.h>
|
||||
#include <gui/guiall.h>
|
||||
|
||||
#include "addeditaction.h"
|
||||
#include "testaction.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "uiconfighelper.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../gameloop/gameloop.h"
|
||||
#include "../gameloop/loopdata.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
|
||||
test_loop_args* test_loop_data;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static Layout *i_modal_layout(AddDeviceData *data, App* app, MonocoqueSettings* ms, enum device_action dev_action, int confignum, int devicenum);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static AddDeviceData *i_modal_data(Window *parent)
|
||||
{
|
||||
AddDeviceData *data = heap_new0(AddDeviceData);
|
||||
data->parent = parent;
|
||||
data->type = UINT32_MAX;
|
||||
return data;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_destroy_modal_data(AddDeviceData **data)
|
||||
{
|
||||
AddDeviceData* d = *data;
|
||||
DeviceSettings ds = *d->ds;
|
||||
settingsfree(ds);
|
||||
free(d->ds);
|
||||
heap_delete(data, AddDeviceData);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnTestClose(App *app, Event *e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void update_device_data_from_controls(AddDeviceData* data)
|
||||
{
|
||||
data->ds->dev_type = combo_get_selected(data->combo_select_device_class);
|
||||
data->ds->dev_subtype = combo_get_selected(data->combo_select_device_subtype);
|
||||
uint32_t device_selected = combo_get_selected(data->combo_select_device);
|
||||
data->ds->dev = strdup(combo_get_text(data->combo_select_device, device_selected));
|
||||
if(data->ds->dev_type == SIMDEV_SERIAL)
|
||||
{
|
||||
data->ds->dev_subtype = combo_get_selected(data->combo_select_device_subtype) + SerialDevicesOffset;
|
||||
}
|
||||
if(data->ds->dev_type == SIMDEV_USB)
|
||||
{
|
||||
data->ds->dev_subtype = combo_get_selected(data->combo_select_device_subtype) + USBDevicesOffset;
|
||||
}
|
||||
data->ds->hapticsettings.tyre = combo_get_selected(data->combo_select_tyre);
|
||||
data->ds->hapticsettings.effect_type = combo_get_selected(data->combo_select_effect);
|
||||
data->ds->hapticsettings.modulation = combo_get_selected(data->combo_select_modulation);
|
||||
}
|
||||
|
||||
|
||||
static void i_OnTestDevice(AddDeviceData *data, Event *e)
|
||||
{
|
||||
update_device_data_from_controls(data);
|
||||
|
||||
Panel *panel = NULL;
|
||||
|
||||
data->apppointer->window3 = window_create(ekWINDOW_STDRES);
|
||||
|
||||
SimData* t_simdata = malloc(sizeof(SimData));
|
||||
|
||||
set_basic_simdata(t_simdata);
|
||||
set_wheel_spin_simdata(t_simdata);
|
||||
if(data->ds->has_haptic_effects == true)
|
||||
{
|
||||
if(data->ds->hapticsettings.effect_type == EFFECT_TYRELOCK)
|
||||
{
|
||||
set_wheel_lock_simdata(t_simdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test_loop_data = malloc(sizeof(test_loop_args));
|
||||
test_loop_data->ms = data->ms;
|
||||
test_loop_data->confignum = data->confignum;
|
||||
test_loop_data->devicenum = data->devicenum;
|
||||
test_loop_data->ds = data->ds;
|
||||
test_loop_data->simdata = t_simdata;
|
||||
|
||||
start_test(test_loop_data);
|
||||
panel = test_window(data->apppointer->window3, data->apppointer);
|
||||
|
||||
window_panel(data->apppointer->window3, panel);
|
||||
window_origin(data->apppointer->window3, v2df(800, 200));
|
||||
window_title(data->apppointer->window3, "monocoque");
|
||||
window_OnClose(data->apppointer->window3, listener(data->apppointer, i_OnTestClose, App));
|
||||
|
||||
window_modal(data->apppointer->window3, data->apppointer->window);
|
||||
|
||||
window_destroy(&data->apppointer->window3);
|
||||
|
||||
free(t_simdata);
|
||||
free(test_loop_data);
|
||||
}
|
||||
|
||||
static void addHapticDeviceLayout(AddDeviceData* data)
|
||||
{
|
||||
struct _add_device_t* subwindow = data;
|
||||
subwindow->haptic_effect_sublayout = layout_create(8, 3);
|
||||
|
||||
subwindow->label_select_effect = label_create();
|
||||
subwindow->combo_select_effect = combo_create();
|
||||
subwindow->label_select_modulation = label_create();
|
||||
subwindow->combo_select_modulation = combo_create();
|
||||
subwindow->label_select_tyre = label_create();
|
||||
subwindow->combo_select_tyre = combo_create();
|
||||
subwindow->label_motorposition = label_create();
|
||||
subwindow->edit_motorposition = edit_create();
|
||||
|
||||
subwindow->label_frequency = label_create();
|
||||
subwindow->edit_frequency = edit_create();
|
||||
subwindow->label_amplitude = label_create();
|
||||
subwindow->edit_amplitude = edit_create();
|
||||
|
||||
subwindow->label_frequencyMax = label_create();
|
||||
subwindow->edit_frequencyMax = edit_create();
|
||||
subwindow->label_amplitudeMax = label_create();
|
||||
subwindow->edit_amplitudeMax = edit_create();
|
||||
subwindow->label_threshold = label_create();
|
||||
subwindow->edit_threshold = edit_create();
|
||||
subwindow->label_duration = label_create();
|
||||
subwindow->edit_duration = edit_create();
|
||||
|
||||
label_text(subwindow->label_select_effect, "Effect:");
|
||||
label_text(subwindow->label_select_modulation, "Modulation:");
|
||||
label_text(subwindow->label_select_tyre, "Tyre:");
|
||||
label_text(subwindow->label_motorposition, "Motor Position:");
|
||||
label_text(subwindow->label_frequency, "Frequency:");
|
||||
label_text(subwindow->label_amplitude, "Amplitude:");
|
||||
label_text(subwindow->label_frequencyMax, "Max Frequency:");
|
||||
label_text(subwindow->label_amplitudeMax, "Max Amplitude:");
|
||||
label_text(subwindow->label_threshold, "Threshold:");
|
||||
label_text(subwindow->label_duration, "Duration:");
|
||||
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_select_effect, 0, 0);
|
||||
layout_combo(subwindow->haptic_effect_sublayout, subwindow->combo_select_effect, 1, 0);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_select_modulation, 2, 0);
|
||||
layout_combo(subwindow->haptic_effect_sublayout, subwindow->combo_select_modulation, 3, 0);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_select_tyre, 4, 0);
|
||||
layout_combo(subwindow->haptic_effect_sublayout, subwindow->combo_select_tyre, 5, 0);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_motorposition, 6, 0);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_motorposition, 7, 0);
|
||||
|
||||
combo_add_elem(subwindow->combo_select_effect, "Engine", NULL);
|
||||
combo_add_elem(subwindow->combo_select_effect, "Gear", NULL);
|
||||
combo_add_elem(subwindow->combo_select_effect, "ABS", NULL);
|
||||
combo_add_elem(subwindow->combo_select_effect, "TyreSlip", NULL);
|
||||
combo_add_elem(subwindow->combo_select_effect, "TyreLock", NULL);
|
||||
combo_add_elem(subwindow->combo_select_effect, "Suspension", NULL);
|
||||
|
||||
combo_add_elem(subwindow->combo_select_modulation, "None", NULL);
|
||||
combo_add_elem(subwindow->combo_select_modulation, "Frequency", NULL);
|
||||
combo_add_elem(subwindow->combo_select_modulation, "Amplitude", NULL);
|
||||
|
||||
combo_add_elem(subwindow->combo_select_tyre, "FrontLeft", NULL);
|
||||
combo_add_elem(subwindow->combo_select_tyre, "FrontRight", NULL);
|
||||
combo_add_elem(subwindow->combo_select_tyre, "RearLeft", NULL);
|
||||
combo_add_elem(subwindow->combo_select_tyre, "RearRight", NULL);
|
||||
combo_add_elem(subwindow->combo_select_tyre, "Fronts", NULL);
|
||||
combo_add_elem(subwindow->combo_select_tyre, "Rears", NULL);
|
||||
combo_add_elem(subwindow->combo_select_tyre, "All", NULL);
|
||||
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_frequency, 0, 1);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_frequency, 1, 1);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_amplitude, 2, 1);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_amplitude, 3, 1);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_frequencyMax, 6, 1);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_frequencyMax, 7, 1);
|
||||
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_amplitudeMax, 0, 2);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_amplitudeMax, 1, 2);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_threshold, 2, 2);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_threshold, 3, 2);
|
||||
layout_label(subwindow->haptic_effect_sublayout, subwindow->label_duration, 4, 2);
|
||||
layout_edit(subwindow->haptic_effect_sublayout, subwindow->edit_duration, 5, 2);
|
||||
|
||||
|
||||
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 1, 1), HapticEffectSettings, uint32_t, frequency);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 3, 1), HapticEffectSettings, uint32_t, amplitude);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 7, 1), HapticEffectSettings, uint32_t, frequencyMax);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 1, 2), HapticEffectSettings, uint32_t, amplitudeMax);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 7, 0), HapticEffectSettings, uint32_t, motorposition);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 3, 2), HapticEffectSettings, real64_t, threshold);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 5, 2), HapticEffectSettings, real64_t, duration);
|
||||
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 3, 0), HapticEffectSettings, uint32_t, modulation);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 5, 0), HapticEffectSettings, uint32_t, tyre);
|
||||
cell_dbind(layout_cell(subwindow->haptic_effect_sublayout, 1, 0), HapticEffectSettings, uint32_t, effect_type);
|
||||
layout_dbind(subwindow->haptic_effect_sublayout, NULL, HapticEffectSettings);
|
||||
layout_dbind_obj(subwindow->haptic_effect_sublayout, &data->ds->hapticsettings, HapticEffectSettings);
|
||||
|
||||
// can i get this from the dbind
|
||||
combo_selected(subwindow->combo_select_tyre, data->ds->hapticsettings.tyre);
|
||||
combo_selected(subwindow->combo_select_effect, data->ds->hapticsettings.effect_type);
|
||||
combo_selected(subwindow->combo_select_modulation, data->ds->hapticsettings.modulation);
|
||||
|
||||
for (uint32_t row = 0; row < 3; row++)
|
||||
{
|
||||
for (uint32_t col = 1; col < 8; col += 2)
|
||||
{
|
||||
layout_halign(subwindow->haptic_effect_sublayout, col, row, ekJUSTIFY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void addSerialDeviceLayout(AddDeviceData* data)
|
||||
{
|
||||
struct _add_device_t* subwindow = data;
|
||||
subwindow->serial_device_sublayout = layout_create(4, 1);
|
||||
subwindow->edit_baud = edit_create();
|
||||
subwindow->label_baud = label_create();
|
||||
label_text(subwindow->label_baud, "baud: ");
|
||||
layout_label(subwindow->serial_device_sublayout, subwindow->label_baud, 0, 0);
|
||||
layout_edit(subwindow->serial_device_sublayout, subwindow->edit_baud, 1, 0);
|
||||
|
||||
cell_dbind(layout_cell(subwindow->serial_device_sublayout, 1, 0), SerialDeviceSettings, uint32_t, baud);
|
||||
layout_dbind(subwindow->serial_device_sublayout, NULL, SerialDeviceSettings);
|
||||
layout_dbind_obj(subwindow->serial_device_sublayout, &data->ds->serialdevsettings, SerialDeviceSettings);
|
||||
|
||||
layout_update(subwindow->serial_device_sublayout);
|
||||
}
|
||||
|
||||
static void addSoundDeviceLayout(AddDeviceData* data)
|
||||
{
|
||||
struct _add_device_t* subwindow = data;
|
||||
|
||||
subwindow->sound_device_sublayout = layout_create(6, 1);
|
||||
|
||||
subwindow->edit_channel = edit_create();
|
||||
subwindow->edit_channels = edit_create();
|
||||
subwindow->label_channel = label_create();
|
||||
subwindow->label_channels = label_create();
|
||||
subwindow->label_volume = label_create();
|
||||
subwindow->edit_volume = edit_create();
|
||||
|
||||
label_text(subwindow->label_channel, "Channel: ");
|
||||
label_text(subwindow->label_channels, "Channels: ");
|
||||
label_text(subwindow->label_volume, "Volume:");
|
||||
|
||||
layout_label(subwindow->sound_device_sublayout, subwindow->label_channel, 0, 0);
|
||||
layout_label(subwindow->sound_device_sublayout, subwindow->label_channels, 2, 0);
|
||||
layout_label(subwindow->sound_device_sublayout, subwindow->label_volume, 4, 0);
|
||||
|
||||
layout_edit(subwindow->sound_device_sublayout, subwindow->edit_channel, 1, 0);
|
||||
layout_edit(subwindow->sound_device_sublayout, subwindow->edit_channels, 3, 0);
|
||||
layout_edit(subwindow->sound_device_sublayout, subwindow->edit_volume, 5, 0);
|
||||
|
||||
|
||||
cell_dbind(layout_cell(subwindow->sound_device_sublayout, 1, 0), SoundDeviceSettings, uint32_t, pan);
|
||||
cell_dbind(layout_cell(subwindow->sound_device_sublayout, 3, 0), SoundDeviceSettings, uint32_t, channels);
|
||||
cell_dbind(layout_cell(subwindow->sound_device_sublayout, 5, 0), SoundDeviceSettings, uint32_t, volume);
|
||||
layout_dbind(subwindow->sound_device_sublayout, NULL, SoundDeviceSettings);
|
||||
layout_dbind_obj(subwindow->sound_device_sublayout, &data->ds->sounddevsettings, SoundDeviceSettings);
|
||||
|
||||
|
||||
layout_update(subwindow->sound_device_sublayout);
|
||||
}
|
||||
|
||||
static void addLedDeviceLayout(AddDeviceData* data)
|
||||
{
|
||||
struct _add_device_t* subwindow = data;
|
||||
|
||||
subwindow->led_device_sublayout = layout_create(6,1);
|
||||
|
||||
subwindow->edit_num_leds = edit_create();
|
||||
subwindow->edit_start_led = edit_create();
|
||||
subwindow->edit_end_led = edit_create();
|
||||
|
||||
subwindow->label_num_leds = label_create();
|
||||
subwindow->label_start_led = label_create();
|
||||
subwindow->label_end_led = label_create();
|
||||
|
||||
|
||||
label_text(subwindow->label_num_leds, "Leds: ");
|
||||
label_text(subwindow->label_start_led, "Start Led: ");
|
||||
label_text(subwindow->label_end_led, "End Led: ");
|
||||
|
||||
layout_label(subwindow->led_device_sublayout, subwindow->label_num_leds, 0, 0);
|
||||
layout_label(subwindow->led_device_sublayout, subwindow->label_start_led, 2, 0);
|
||||
layout_label(subwindow->led_device_sublayout, subwindow->label_end_led, 4, 0);
|
||||
|
||||
layout_edit(subwindow->led_device_sublayout, subwindow->edit_num_leds, 1, 0);
|
||||
layout_edit(subwindow->led_device_sublayout, subwindow->edit_start_led, 3, 0);
|
||||
layout_edit(subwindow->led_device_sublayout, subwindow->edit_end_led, 5, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cell_dbind(layout_cell(subwindow->led_device_sublayout, 1, 0), SerialDeviceSettings, uint32_t, numleds);
|
||||
cell_dbind(layout_cell(subwindow->led_device_sublayout, 3, 0), SerialDeviceSettings, uint32_t, startled);
|
||||
cell_dbind(layout_cell(subwindow->led_device_sublayout, 5, 0), SerialDeviceSettings, uint32_t, endled);
|
||||
layout_dbind(subwindow->led_device_sublayout, NULL, SerialDeviceSettings);
|
||||
layout_dbind_obj(subwindow->led_device_sublayout, &data->ds->serialdevsettings, SerialDeviceSettings);
|
||||
|
||||
|
||||
layout_update(subwindow->led_device_sublayout);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnSaveDevice(AddDeviceData *data, Event *e)
|
||||
{
|
||||
update_device_data_from_controls(data);
|
||||
slogd("Attempting save of device class %i device type %i device %s", data->ds->dev_type, data->ds->dev_subtype, data->ds->dev);
|
||||
save_device_config(data->ms->cfg, data->ms->config_str, data->confignum, data->devicenum, data->ds);
|
||||
}
|
||||
|
||||
static void i_OnDeviceSubtypeSelect(AddDeviceData *data, Event *e)
|
||||
{
|
||||
const EvButton *p = event_params(e, EvButton);
|
||||
cell_visible(data->cell_led_device_layout, false);
|
||||
cell_visible(data->cell_haptic_effect_layout, false);
|
||||
data->ds->has_led_effects = false;
|
||||
data->ds->has_haptic_effects = false;
|
||||
uint32_t selected = combo_get_selected(data->combo_select_device_subtype);
|
||||
const char_t *text = combo_get_text(data->combo_select_device_subtype, selected);
|
||||
|
||||
if (text != NULL && strcmp(text, "SIMLED") == 0)
|
||||
{
|
||||
cell_visible(data->cell_led_device_layout, true);
|
||||
data->ds->has_led_effects = true;
|
||||
}
|
||||
if (text != NULL && strcmp(text, "SOUNDHAPTIC") == 0)
|
||||
{
|
||||
cell_visible(data->cell_haptic_effect_layout, true);
|
||||
data->ds->has_haptic_effects = true;
|
||||
}
|
||||
panel_update(data->panel);
|
||||
}
|
||||
|
||||
static void populateSerialSubTypesCombo(Combo* combo)
|
||||
{
|
||||
combo_add_elem(combo, "ShiftLights", NULL);
|
||||
combo_add_elem(combo, "SimWind", NULL);
|
||||
combo_add_elem(combo, "Haptic", NULL);
|
||||
combo_add_elem(combo, "Wheel", NULL);
|
||||
combo_add_elem(combo, "SimLed", NULL);
|
||||
combo_add_elem(combo, "Custom", NULL);
|
||||
}
|
||||
|
||||
|
||||
static void i_OnDeviceClassSelect(AddDeviceData *data, Event *e)
|
||||
{
|
||||
const EvButton *p = event_params(e, EvButton);
|
||||
|
||||
panel_visible_layout(data->device_specific_panel, 0);
|
||||
cell_visible(data->cell_led_device_layout, false);
|
||||
cell_visible(data->cell_haptic_effect_layout, false);
|
||||
panel_update(data->device_specific_panel);
|
||||
combo_clear(data->combo_select_device);
|
||||
combo_text(data->combo_select_device, "");
|
||||
combo_clear(data->combo_select_device_subtype);
|
||||
combo_text(data->combo_select_device_subtype, "");
|
||||
uint32_t selected = combo_get_selected(data->combo_select_device_class);
|
||||
const char_t *text = combo_get_text(data->combo_select_device_class, selected);
|
||||
if (text != NULL && strcmp(text, "Serial") == 0)
|
||||
{
|
||||
add_serial_devices_to_combo(data->combo_select_device);
|
||||
populateSerialSubTypesCombo(data->combo_select_device_subtype);
|
||||
panel_visible_layout(data->device_specific_panel, 1);
|
||||
// since SIMLED will be selected we will show led settings
|
||||
cell_visible(data->cell_led_device_layout, true);
|
||||
data->ds->has_led_effects = true;
|
||||
}
|
||||
if (text != NULL && strcmp(text, "Sound") == 0)
|
||||
{
|
||||
add_sound_devices_to_combo(data->combo_select_device);
|
||||
combo_add_elem(data->combo_select_device_subtype, "Haptic", NULL);
|
||||
panel_visible_layout(data->device_specific_panel, 2);
|
||||
// since HAPTIC will be selected we will show haptic settings
|
||||
cell_visible(data->cell_haptic_effect_layout, true);
|
||||
data->ds->has_haptic_effects = true;
|
||||
}
|
||||
combo_selected(data->combo_select_device, 0);
|
||||
combo_selected(data->combo_select_device_subtype, 0);
|
||||
panel_update(data->device_specific_panel);
|
||||
panel_update(data->panel);
|
||||
}
|
||||
|
||||
static Panel* device_specific_panel_create(AddDeviceData *data)
|
||||
{
|
||||
Panel *panel = panel_create();
|
||||
data->empty_device_sublayout = layout_create(4, 1);
|
||||
|
||||
addSerialDeviceLayout(data);
|
||||
addSoundDeviceLayout(data);
|
||||
|
||||
panel_layout(panel, data->empty_device_sublayout);
|
||||
panel_layout(panel, data->serial_device_sublayout);
|
||||
panel_layout(panel, data->sound_device_sublayout);
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
static Layout *i_modal_layout(AddDeviceData *data, App* app, MonocoqueSettings* ms, enum device_action dev_action, int confignum, int devicenum)
|
||||
{
|
||||
|
||||
struct _add_device_t* subwindow = data;
|
||||
|
||||
subwindow->main_outer_layout = layout_create(1,11);
|
||||
subwindow->top_selection_layout = layout_create(4,1);
|
||||
subwindow->general_settings_layout = layout_create(4, 1);
|
||||
|
||||
|
||||
// device class specific settings ( max 1 row so far )
|
||||
// possible led specific settings ( 1 row )
|
||||
// possible haptic specific settings ( 3 rows )
|
||||
|
||||
subwindow->add_save_test_layout = layout_create(2,1);
|
||||
|
||||
subwindow->combo_select_device_class = combo_create();
|
||||
subwindow->combo_select_device_subtype = combo_create();
|
||||
subwindow->combo_select_device = combo_create();
|
||||
subwindow->label_select_device_class = label_create();
|
||||
subwindow->label_select_device_subtype = label_create();
|
||||
subwindow->label_select_device = label_create();
|
||||
label_text(subwindow->label_select_device_class, "Device Class: ");
|
||||
label_text(subwindow->label_select_device_subtype, "Device SubType: ");
|
||||
label_text(subwindow->label_select_device, "Device: ");
|
||||
layout_label(subwindow->top_selection_layout, subwindow->label_select_device_class, 0, 0);
|
||||
layout_combo(subwindow->top_selection_layout, subwindow->combo_select_device_class, 1, 0);
|
||||
layout_label(subwindow->top_selection_layout, subwindow->label_select_device_subtype, 2, 0);
|
||||
layout_combo(subwindow->top_selection_layout, subwindow->combo_select_device_subtype, 3, 0);
|
||||
|
||||
|
||||
|
||||
layout_label(subwindow->general_settings_layout, subwindow->label_select_device, 2, 0);
|
||||
layout_combo(subwindow->general_settings_layout, subwindow->combo_select_device, 3, 0);
|
||||
subwindow->edit_fps = edit_create();
|
||||
subwindow->label_fps = label_create();
|
||||
label_text(subwindow->label_fps, "fps: ");
|
||||
layout_label(subwindow->general_settings_layout, subwindow->label_fps, 0, 0);
|
||||
layout_edit(subwindow->general_settings_layout, subwindow->edit_fps, 1, 0);
|
||||
|
||||
|
||||
cell_dbind(layout_cell(subwindow->top_selection_layout, 1, 0), DeviceSettings, uint32_t, dev_type);
|
||||
cell_dbind(layout_cell(subwindow->top_selection_layout, 3, 0), DeviceSettings, uint32_t, dev_subtype);
|
||||
cell_dbind(layout_cell(subwindow->general_settings_layout, 1, 0), DeviceSettings, uint32_t, fps);
|
||||
layout_dbind(subwindow->general_settings_layout, NULL, DeviceSettings);
|
||||
layout_dbind(subwindow->top_selection_layout, NULL, DeviceSettings);
|
||||
layout_dbind_obj(subwindow->general_settings_layout, data->ds, DeviceSettings);
|
||||
|
||||
subwindow->device_specific_panel = device_specific_panel_create(data);
|
||||
panel_visible_layout(data->device_specific_panel, 0);
|
||||
|
||||
addLedDeviceLayout(data);
|
||||
addHapticDeviceLayout(data);
|
||||
|
||||
|
||||
subwindow->test_button = button_push();
|
||||
subwindow->save_button = button_push();
|
||||
button_text(subwindow->test_button, "Test");
|
||||
button_text(subwindow->save_button, "Save");
|
||||
layout_button(subwindow->add_save_test_layout, subwindow->test_button, 0, 0);
|
||||
layout_button(subwindow->add_save_test_layout, subwindow->save_button, 1, 0);
|
||||
button_OnClick(subwindow->test_button, listener(data, i_OnTestDevice, AddDeviceData));
|
||||
button_OnClick(subwindow->save_button, listener(data, i_OnSaveDevice, AddDeviceData));
|
||||
|
||||
|
||||
|
||||
layout_layout(subwindow->main_outer_layout, subwindow->top_selection_layout, 0, 0);
|
||||
layout_layout(subwindow->main_outer_layout, subwindow->general_settings_layout, 0, 1);
|
||||
layout_panel(subwindow->main_outer_layout, subwindow->device_specific_panel, 0, 2);
|
||||
layout_layout(subwindow->main_outer_layout, subwindow->led_device_sublayout, 0, 3);
|
||||
layout_layout(subwindow->main_outer_layout, subwindow->haptic_effect_sublayout, 0, 4);
|
||||
layout_layout(subwindow->main_outer_layout, subwindow->add_save_test_layout, 0, 7);
|
||||
|
||||
subwindow->cell_led_device_layout = layout_cell(subwindow->main_outer_layout, 0, 3);
|
||||
subwindow->cell_haptic_effect_layout = layout_cell(subwindow->main_outer_layout, 0, 4);
|
||||
cell_visible(subwindow->cell_led_device_layout, false);
|
||||
cell_visible(subwindow->cell_haptic_effect_layout, false);
|
||||
|
||||
|
||||
|
||||
|
||||
if(dev_action == DEVICE_ACTION_ADD)
|
||||
{
|
||||
combo_add_elem(subwindow->combo_select_device_class, "USB", NULL);
|
||||
combo_add_elem(subwindow->combo_select_device_class, "Sound", NULL);
|
||||
combo_add_elem(subwindow->combo_select_device_class, "Serial", NULL);
|
||||
|
||||
|
||||
combo_OnSelect(subwindow->combo_select_device_class, listener(data, i_OnDeviceClassSelect, AddDeviceData));
|
||||
combo_OnSelect(subwindow->combo_select_device_subtype, listener(data, i_OnDeviceSubtypeSelect, AddDeviceData));
|
||||
|
||||
|
||||
return subwindow->main_outer_layout;
|
||||
}
|
||||
|
||||
char str0[255];
|
||||
sprintf(str0, "%s", data->ds->dev);
|
||||
combo_add_elem(subwindow->combo_select_device, str0, NULL);
|
||||
|
||||
|
||||
subwindow->cell_top_selection_layout = layout_cell(subwindow->main_outer_layout, 0, 0);
|
||||
cell_enabled(subwindow->cell_top_selection_layout, false);
|
||||
|
||||
if(data->ds->dev_type == SIMDEV_SERIAL)
|
||||
{
|
||||
combo_add_elem(subwindow->combo_select_device_class, "Serial", NULL);
|
||||
add_serial_devices_to_combo(data->combo_select_device);
|
||||
populateSerialSubTypesCombo(data->combo_select_device_subtype);
|
||||
combo_selected(subwindow->combo_select_device_subtype, data->ds->dev_subtype - SerialDevicesOffset);
|
||||
panel_visible_layout(data->device_specific_panel, 1);
|
||||
}
|
||||
if(data->ds->dev_type == SIMDEV_SOUND)
|
||||
{
|
||||
combo_add_elem(subwindow->combo_select_device_class, "Sound", NULL);
|
||||
add_sound_devices_to_combo(data->combo_select_device);
|
||||
combo_add_elem(data->combo_select_device_subtype, "Haptic", NULL);
|
||||
combo_selected(subwindow->combo_select_device_subtype, data->ds->dev_subtype);
|
||||
panel_visible_layout(data->device_specific_panel, 2);
|
||||
cell_visible(data->cell_haptic_effect_layout, true);
|
||||
}
|
||||
if(data->ds->dev_type == SIMDEV_USB)
|
||||
{
|
||||
combo_selected(subwindow->combo_select_device_subtype, data->ds->dev_subtype - USBDevicesOffset);
|
||||
panel_visible_layout(data->device_specific_panel, 2);
|
||||
}
|
||||
|
||||
if(data->ds->dev_subtype == SIMDEVTYPE_SIMLED) {
|
||||
cell_visible(data->cell_led_device_layout, true);
|
||||
}
|
||||
|
||||
combo_selected(subwindow->combo_select_device_class, 0);
|
||||
return subwindow->main_outer_layout;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
Panel *adddevice_window(Window *parent, App* app, MonocoqueSettings* ms, enum device_action dev_action, int confignum, int devicenum)
|
||||
{
|
||||
Panel *panel = panel_create();
|
||||
AddDeviceData *data = i_modal_data(parent);
|
||||
data->panel = panel;
|
||||
|
||||
data->devicenum = devicenum;
|
||||
data->confignum = confignum;
|
||||
data->ds = malloc(sizeof(DeviceSettings));
|
||||
|
||||
// move this somewhere better or use dbind to set this stuff
|
||||
data->ds->dev_type = 0;
|
||||
data->ds->dev_subtype = 0;
|
||||
data->ds->dev_subsubtype = 0;
|
||||
data->ds->dev = NULL;
|
||||
data->ds->fps = 60;
|
||||
data->ds->specific_config_file = NULL;
|
||||
data->ds->has_config = false;
|
||||
data->ds->serialdevsettings.baud = 115200;
|
||||
data->ds->serialdevsettings.startled = 0;
|
||||
data->ds->serialdevsettings.endled = 0;
|
||||
data->ds->serialdevsettings.numleds = 0;
|
||||
data->ds->sounddevsettings.channels = 2;
|
||||
data->ds->sounddevsettings.pan = 0;
|
||||
data->ds->sounddevsettings.volume = 50;
|
||||
data->ds->sounddevsettings.noise = 0;
|
||||
data->ds->hapticsettings.frequency = 32;
|
||||
data->ds->hapticsettings.amplitude = 50;
|
||||
data->ds->hapticsettings.frequencyMax = 0;
|
||||
data->ds->hapticsettings.amplitudeMax = 0;
|
||||
data->ds->hapticsettings.motorposition = 0;
|
||||
data->ds->hapticsettings.threshold = 0.0;
|
||||
data->ds->hapticsettings.duration = 0.0;
|
||||
data->ds->hapticsettings.modulation = 1;
|
||||
data->ds->hapticsettings.tyre = 0;
|
||||
data->ds->hapticsettings.effect_type = 0;
|
||||
data->ds->has_led_effects = false;
|
||||
data->ds->has_haptic_effects = false;
|
||||
|
||||
data->ms = ms;
|
||||
data->apppointer = app;
|
||||
if(dev_action == DEVICE_ACTION_EDIT)
|
||||
{
|
||||
int numdevices = getsingledevice(ms->config_str, confignum, devicenum, ms, data->ds);
|
||||
}
|
||||
|
||||
Layout *layout = i_modal_layout(data, app, ms, dev_action, confignum, devicenum);
|
||||
panel_layout(panel, layout);
|
||||
panel_data(panel, &data, i_destroy_modal_data, AddDeviceData);
|
||||
return panel;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include <gui/gui.hxx>
|
||||
#include "mainwindow.h"
|
||||
|
||||
Panel *adddevice_window(Window *parent, App* app, MonocoqueSettings* ms, enum device_action dev_action, int confignum, int devicenum);
|
||||
|
||||
typedef struct _add_device_t AddDeviceData;
|
||||
|
||||
struct _add_device_t
|
||||
{
|
||||
Layout* main_outer_layout;
|
||||
|
||||
Layout* top_selection_layout;
|
||||
Label* label_select_device_class;
|
||||
Label* label_select_device_subtype;
|
||||
Label* label_select_device;
|
||||
Combo* combo_select_device_class;
|
||||
Combo* combo_select_device_subtype;
|
||||
Combo* combo_select_device;
|
||||
|
||||
Edit* edit_select_device;
|
||||
|
||||
Layout* general_settings_layout;
|
||||
Label* label_fps;
|
||||
Edit* edit_fps;
|
||||
Button* check_use_lua;
|
||||
|
||||
Layout* empty_device_sublayout;
|
||||
|
||||
Panel* device_specific_panel;
|
||||
|
||||
// sound sublayout
|
||||
Layout* sound_device_sublayout;
|
||||
Label* label_channel;
|
||||
Label* label_channels;
|
||||
Label* label_volume;
|
||||
Edit* edit_channel;
|
||||
Edit* edit_channels;
|
||||
Edit* edit_volume;
|
||||
|
||||
// serial sublayout
|
||||
Layout* serial_device_sublayout;
|
||||
Label* label_baud;
|
||||
Edit* edit_baud;
|
||||
|
||||
// led sublayout
|
||||
Layout* led_device_sublayout;
|
||||
Label* label_num_leds;
|
||||
Label* label_start_led;
|
||||
Label* label_end_led;
|
||||
Edit* edit_num_leds;
|
||||
Edit* edit_start_led;
|
||||
Edit* edit_end_led;
|
||||
|
||||
Layout* haptic_effect_sublayout;
|
||||
Label* label_select_effect;
|
||||
Combo* combo_select_effect;
|
||||
Label* label_select_modulation;
|
||||
Combo* combo_select_modulation;
|
||||
Label* label_select_tyre;
|
||||
Combo* combo_select_tyre;
|
||||
|
||||
Label* label_motorposition;
|
||||
Edit* edit_motorposition;
|
||||
Label* label_frequency;
|
||||
Edit* edit_frequency;
|
||||
Label* label_amplitude;
|
||||
Edit* edit_amplitude;
|
||||
|
||||
Label* label_frequencyMax;
|
||||
Edit* edit_frequencyMax;
|
||||
Label* label_amplitudeMax;
|
||||
Edit* edit_amplitudeMax;
|
||||
Label* label_threshold;
|
||||
Edit* edit_threshold;
|
||||
Label* label_duration;
|
||||
Edit* edit_duration;
|
||||
|
||||
|
||||
|
||||
Layout* add_save_test_layout;
|
||||
Button* test_button;
|
||||
Button* save_button;
|
||||
|
||||
Cell* cell_top_selection_layout;
|
||||
Cell* cell_led_device_layout;
|
||||
Cell* cell_haptic_effect_layout;
|
||||
|
||||
uint32_t type;
|
||||
Label *label;
|
||||
MonocoqueSettings* ms;
|
||||
DeviceSettings* ds;
|
||||
Panel* panel;
|
||||
App* apppointer;
|
||||
int confignum;
|
||||
int devicenum;
|
||||
Window *parent;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "../helper/confighelper.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
enum device_action {
|
||||
DEVICE_ACTION_ADD, DEVICE_ACTION_EDIT, DEVICE_ACTION_DELETE
|
||||
};
|
||||
|
||||
typedef struct _app_t App;
|
||||
struct _app_t
|
||||
{
|
||||
bool_t is_running;
|
||||
|
||||
Panel *main_panel;
|
||||
Panel *subpanel;
|
||||
|
||||
|
||||
Layout *layout1;
|
||||
Layout *layout2;
|
||||
Layout *layout3;
|
||||
Layout *layout4;
|
||||
Layout *sub_layout;
|
||||
|
||||
|
||||
Window *window;
|
||||
Window *window2;
|
||||
Window *window3;
|
||||
Layout* layout;
|
||||
|
||||
Combo* combo_configurations;
|
||||
ListBox* listbox_devices;
|
||||
|
||||
Button *button_startstop;
|
||||
Button *button_add;
|
||||
Button *button_edit;
|
||||
Button *button_del;
|
||||
Button *button_test;
|
||||
|
||||
Label *label_configurations;
|
||||
Label *label_game_status;
|
||||
Label *label_simd_status;
|
||||
|
||||
Cell* devices_subpanel;
|
||||
};
|
||||
Submodule
+1
Submodule src/monocoque/mgui/nappgui_src added at 29c7bd3e02
@@ -0,0 +1,188 @@
|
||||
/* Listboxes */
|
||||
|
||||
#include "testaction.h"
|
||||
#include "../gameloop/gameloop.h"
|
||||
#include "mainwindow.h"
|
||||
#include <gui/guiall.h>
|
||||
|
||||
typedef struct _modal_data_t gModalData;
|
||||
|
||||
struct _modal_data_t
|
||||
{
|
||||
uint32_t type;
|
||||
Label *label;
|
||||
Window *parent;
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static Layout *i_modal_layout(gModalData *data, Window *window, App *app);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static gModalData *i_modal_data(Window *parent)
|
||||
{
|
||||
gModalData *data = heap_new0(gModalData);
|
||||
data->parent = parent;
|
||||
data->type = UINT32_MAX;
|
||||
return data;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void i_OnTestDone(Window *window, Event *e)
|
||||
{
|
||||
Button *button = event_sender(e, Button);
|
||||
window_stop_modal(window, button_get_tag(button));
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnTestDataUpdate(Window* window, Event* e)
|
||||
{
|
||||
Button *button = event_sender(e, Button);
|
||||
//SimData* simdata = get_test_simdata();
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_destroy_modal_data(gModalData **data)
|
||||
{
|
||||
monocoque_testloop_stop();
|
||||
heap_delete(data, gModalData);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static Layout *i_modal_layout(gModalData *data, Window* window, App *app)
|
||||
{
|
||||
struct _test_device_t subwindow;
|
||||
subwindow.main_outer_layout = layout_create(1,7);
|
||||
subwindow.data_edit_layout = layout_create(8,6);
|
||||
subwindow.add_save_test_layout = layout_create(2,1);
|
||||
|
||||
|
||||
subwindow.edit_gear = edit_create();
|
||||
subwindow.edit_velocity = edit_create();
|
||||
subwindow.edit_maxrpm = edit_create();
|
||||
subwindow.edit_rpm = edit_create();
|
||||
|
||||
subwindow.label_gear = label_create();
|
||||
subwindow.label_velocity = label_create();
|
||||
subwindow.label_maxrpm = label_create();
|
||||
subwindow.label_rpm = label_create();
|
||||
|
||||
|
||||
subwindow.label_tyre_diameter_1 = label_create();
|
||||
subwindow.label_tyre_diameter_2 = label_create();
|
||||
subwindow.label_tyre_diameter_3 = label_create();
|
||||
subwindow.label_tyre_diameter_4 = label_create();
|
||||
subwindow.label_tyre_rps_1 = label_create();
|
||||
subwindow.label_tyre_rps_2 = label_create();
|
||||
subwindow.label_tyre_rps_3 = label_create();
|
||||
subwindow.label_tyre_rps_4 = label_create();
|
||||
|
||||
subwindow.edit_tyre_diameter_1 = edit_create();
|
||||
subwindow.edit_tyre_diameter_2 = edit_create();
|
||||
subwindow.edit_tyre_diameter_3 = edit_create();
|
||||
subwindow.edit_tyre_diameter_4 = edit_create();
|
||||
subwindow.edit_tyre_rps_1 = edit_create();
|
||||
subwindow.edit_tyre_rps_2 = edit_create();
|
||||
subwindow.edit_tyre_rps_3 = edit_create();
|
||||
subwindow.edit_tyre_rps_4 = edit_create();
|
||||
|
||||
subwindow.update_button = button_push();
|
||||
subwindow.done_button = button_push();
|
||||
|
||||
label_text(subwindow.label_gear, "gear: ");
|
||||
label_text(subwindow.label_velocity, "velocity: ");
|
||||
label_text(subwindow.label_maxrpm, "max rpm: ");
|
||||
label_text(subwindow.label_rpm, "rpm: ");
|
||||
|
||||
|
||||
button_text(subwindow.update_button, "Update");
|
||||
button_text(subwindow.done_button, "Done");
|
||||
button_OnClick(subwindow.done_button, listener(window, i_OnTestDone, Window));
|
||||
button_OnClick(subwindow.update_button, listener(window, i_OnTestDataUpdate, Window));
|
||||
|
||||
layout_layout(subwindow.main_outer_layout, subwindow.data_edit_layout, 0, 2);
|
||||
layout_layout(subwindow.main_outer_layout, subwindow.add_save_test_layout, 0, 5);
|
||||
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_gear, 0, 0);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_velocity, 2, 0);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_maxrpm, 0, 1);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_rpm, 2, 1);
|
||||
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_gear, 1, 0);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_velocity, 3, 0);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_maxrpm, 1, 1);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_rpm, 3, 1);
|
||||
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_rps_1, 0, 2);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_rps_2, 2, 2);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_rps_3, 4, 2);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_rps_4, 6, 2);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_diameter_1, 0, 3);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_diameter_2, 2, 3);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_diameter_3, 4, 3);
|
||||
layout_label(subwindow.data_edit_layout, subwindow.label_tyre_diameter_4, 6, 3);
|
||||
label_text(subwindow.label_tyre_rps_1, "rps_lf");
|
||||
label_text(subwindow.label_tyre_rps_2, "rps_rf");
|
||||
label_text(subwindow.label_tyre_rps_3, "rps_lr");
|
||||
label_text(subwindow.label_tyre_rps_4, "rps_rr");
|
||||
label_text(subwindow.label_tyre_diameter_1, "diameter_lf");
|
||||
label_text(subwindow.label_tyre_diameter_2, "diameter_rf");
|
||||
label_text(subwindow.label_tyre_diameter_3, "diameter_lr");
|
||||
label_text(subwindow.label_tyre_diameter_4, "diameter_rr");
|
||||
|
||||
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_rps_1, 1, 2);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_rps_2, 3, 2);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_rps_3, 5, 2);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_rps_4, 7, 2);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_diameter_1, 1, 3);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_diameter_2, 3, 3);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_diameter_3, 5, 3);
|
||||
layout_edit(subwindow.data_edit_layout, subwindow.edit_tyre_diameter_4, 7, 3);
|
||||
|
||||
|
||||
|
||||
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 1, 0), SimData, uint32_t, gear);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 3, 0), SimData, uint32_t, velocity);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 1, 1), SimData, uint32_t, maxrpm);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 3, 1), SimData, uint32_t, rpms);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 1, 2), SimData, real64_t, tyreRPS[0]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 3, 2), SimData, real64_t, tyreRPS[1]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 5, 2), SimData, real64_t, tyreRPS[2]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 7, 2), SimData, real64_t, tyreRPS[3]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 1, 3), SimData, real64_t, tyrediameter[0]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 3, 3), SimData, real64_t, tyrediameter[1]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 5, 3), SimData, real64_t, tyrediameter[2]);
|
||||
cell_dbind(layout_cell(subwindow.data_edit_layout, 7, 3), SimData, real64_t, tyrediameter[3]);
|
||||
|
||||
|
||||
SimData* simdata = get_test_simdata();
|
||||
layout_dbind(subwindow.data_edit_layout, NULL, SimData);
|
||||
layout_dbind_obj(subwindow.data_edit_layout, simdata, SimData);
|
||||
|
||||
|
||||
layout_button(subwindow.add_save_test_layout, subwindow.update_button, 0, 0);
|
||||
layout_button(subwindow.add_save_test_layout, subwindow.done_button, 1, 0);
|
||||
|
||||
return subwindow.main_outer_layout;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
Panel *test_window(Window *parent, App* app)
|
||||
{
|
||||
Panel *panel = panel_create();
|
||||
gModalData *data = i_modal_data(parent);
|
||||
Layout *layout = i_modal_layout(data, parent, app);
|
||||
panel_layout(panel, layout);
|
||||
panel_data(panel, &data, i_destroy_modal_data, gModalData);
|
||||
return panel;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <gui/gui.hxx>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
Panel *test_window(Window *parent, App* app);
|
||||
|
||||
|
||||
struct _test_device_t
|
||||
{
|
||||
Layout* main_outer_layout;
|
||||
|
||||
Layout* data_edit_layout;
|
||||
Layout* add_save_test_layout;
|
||||
|
||||
Label* label_gear;
|
||||
Label* label_velocity;
|
||||
Label* label_maxrpm;
|
||||
Label* label_rpm;
|
||||
Edit* edit_gear;
|
||||
Edit* edit_velocity;
|
||||
Edit* edit_maxrpm;
|
||||
Edit* edit_rpm;
|
||||
|
||||
Label* label_tyre_diameter_1;
|
||||
Label* label_tyre_diameter_2;
|
||||
Label* label_tyre_diameter_3;
|
||||
Label* label_tyre_diameter_4;
|
||||
Label* label_tyre_rps_1;
|
||||
Label* label_tyre_rps_2;
|
||||
Label* label_tyre_rps_3;
|
||||
Label* label_tyre_rps_4;
|
||||
|
||||
Edit* edit_tyre_diameter_1;
|
||||
Edit* edit_tyre_diameter_2;
|
||||
Edit* edit_tyre_diameter_3;
|
||||
Edit* edit_tyre_diameter_4;
|
||||
Edit* edit_tyre_rps_1;
|
||||
Edit* edit_tyre_rps_2;
|
||||
Edit* edit_tyre_rps_3;
|
||||
Edit* edit_tyre_rps_4;
|
||||
|
||||
Button* update_button;
|
||||
Button* done_button;
|
||||
};
|
||||
@@ -0,0 +1,311 @@
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gui/combo.h>
|
||||
#include <gui/listbox.h>
|
||||
|
||||
#include <libserialport.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "../helper/confighelper.h"
|
||||
|
||||
typedef struct pa_devicelist {
|
||||
uint8_t initialized;
|
||||
char name[512];
|
||||
uint32_t index;
|
||||
char description[256];
|
||||
} pa_devicelist_t;
|
||||
|
||||
int find_default_config(config_setting_t *configs)
|
||||
{
|
||||
int count = config_setting_length(configs);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
config_setting_t *entry = config_setting_get_elem(configs, i);
|
||||
|
||||
const char *sim;
|
||||
const char *api;
|
||||
const char *car;
|
||||
|
||||
if (!config_setting_lookup_string(entry, "sim", &sim))
|
||||
continue;
|
||||
if (!config_setting_lookup_string(entry, "api", &api))
|
||||
continue;
|
||||
if (!config_setting_lookup_string(entry, "car", &car))
|
||||
continue;
|
||||
|
||||
if ((strcmp(sim, "default") == 0 || strcmp(sim, "all") == 0) &&
|
||||
(strcmp(api, "default") == 0 || strcmp(api, "all") == 0) &&
|
||||
(strcmp(car, "default") == 0 || strcmp(car, "all") == 0))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int add_serial_devices_to_combo(Combo *combo)
|
||||
{
|
||||
// from libserialport examples
|
||||
struct sp_port **port_list;
|
||||
|
||||
enum sp_return result = sp_list_ports(&port_list);
|
||||
|
||||
if (result != SP_OK)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; port_list[i] != NULL; i++)
|
||||
{
|
||||
struct sp_port *port = port_list[i];
|
||||
|
||||
char port_name[256];
|
||||
const char *name_ptr = sp_get_port_name(port);
|
||||
|
||||
if (name_ptr != NULL)
|
||||
{
|
||||
snprintf(port_name, sizeof(port_name), "%s", name_ptr);
|
||||
combo_add_elem(combo, port_name, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
port_name[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sp_free_port_list(port_list);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void populate_combo_box(Combo* combo, config_t* cfg)
|
||||
{
|
||||
config_setting_t *configs;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
configs = config_lookup(cfg, "configs");
|
||||
if (configs == NULL || !config_setting_is_list(configs))
|
||||
return;
|
||||
|
||||
count = config_setting_length(configs);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
config_setting_t *cfg_entry;
|
||||
const char *sim = "";
|
||||
const char *car = "";
|
||||
const char *api = "";
|
||||
char text[256];
|
||||
|
||||
cfg_entry = config_setting_get_elem(configs, i);
|
||||
|
||||
config_setting_lookup_string(cfg_entry, "sim", &sim);
|
||||
config_setting_lookup_string(cfg_entry, "car", &car);
|
||||
config_setting_lookup_string(cfg_entry, "api", &api);
|
||||
|
||||
snprintf(text, sizeof(text), "%s / %s / %s", sim, car, api);
|
||||
|
||||
combo_add_elem(combo, text, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void populate_device_list(ListBox *listbox, config_t* cfg)
|
||||
{
|
||||
int count;
|
||||
config_setting_t* devices;
|
||||
devices = config_lookup(cfg, "configs");
|
||||
if (devices == NULL)
|
||||
{
|
||||
fprintf(stderr, "No configs section found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
config_setting_t* config = NULL;
|
||||
config = config_lookup(cfg, "configs");
|
||||
|
||||
int config_num = find_default_config(config);
|
||||
|
||||
config_setting_t* selectedconfig = config_setting_get_elem(config, config_num);
|
||||
config_setting_t* config_devices = NULL;
|
||||
config_devices = config_setting_lookup(selectedconfig, "devices");
|
||||
|
||||
|
||||
count = config_setting_length(config_devices);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
config_setting_t *dev = config_setting_get_elem(config_devices, i);
|
||||
|
||||
const char *device = "";
|
||||
const char *type = "";
|
||||
const char *subtype = "";
|
||||
const char *effect = "";
|
||||
const char *tyre = "";
|
||||
|
||||
config_setting_lookup_string(dev, "device", &device);
|
||||
|
||||
char text[256];
|
||||
|
||||
if (strcasecmp(device, "sound") == 0)
|
||||
{
|
||||
config_setting_lookup_string(dev, "effect", &effect);
|
||||
config_setting_lookup_string(dev, "tyre", &tyre);
|
||||
|
||||
snprintf(text, sizeof(text), "%s - %s - %s",
|
||||
device, effect, tyre);
|
||||
}
|
||||
else
|
||||
{
|
||||
config_setting_lookup_string(dev, "type", &type);
|
||||
config_setting_lookup_string(dev, "subtype", &subtype);
|
||||
|
||||
snprintf(text, sizeof(text), "%s - %s - %s",
|
||||
device, type, subtype);
|
||||
}
|
||||
|
||||
listbox_add_elem(listbox, text, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pa_sinklist_cb(pa_context *c, const pa_sink_info *l, int eol, void *userdata) {
|
||||
pa_devicelist_t *pa_devicelist = userdata;
|
||||
int ctr = 0;
|
||||
|
||||
// If eol is set to a positive number, you're at the end of the list
|
||||
if (eol > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We know we've allocated 16 slots to hold devices. Loop through our
|
||||
// structure and find the first one that's "uninitialized." Copy the
|
||||
// contents into it and we're done. If we receive more than 16 devices,
|
||||
// they're going to get dropped. You could make this dynamically allocate
|
||||
// space for the device list, but this is a simple example.
|
||||
for (ctr = 0; ctr < 16; ctr++) {
|
||||
if (! pa_devicelist[ctr].initialized) {
|
||||
strncpy(pa_devicelist[ctr].name, l->name, 511);
|
||||
strncpy(pa_devicelist[ctr].description, l->description, 255);
|
||||
pa_devicelist[ctr].index = l->index;
|
||||
pa_devicelist[ctr].initialized = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int add_sound_devices_to_combo(Combo *combo)
|
||||
{
|
||||
pa_mainloop *mainloop;
|
||||
pa_context *context;
|
||||
pa_operation *operation;
|
||||
pa_context_state_t state;
|
||||
pa_devicelist_t output[16] = {0};
|
||||
int retval;
|
||||
//pa_devicelist_t* output = malloc(sizeof(pa_devicelist_t) * 16);
|
||||
//memset(output, 0, sizeof(pa_devicelist_t) * 16);
|
||||
mainloop = pa_mainloop_new();
|
||||
|
||||
if (mainloop == NULL)
|
||||
return 0;
|
||||
|
||||
context = pa_context_new(
|
||||
pa_mainloop_get_api(mainloop),
|
||||
"Monocoque");
|
||||
|
||||
if (context == NULL)
|
||||
{
|
||||
pa_mainloop_free(mainloop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pa_context_connect(context, NULL, 0, NULL) < 0)
|
||||
{
|
||||
pa_context_unref(context);
|
||||
pa_mainloop_free(mainloop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for PulseAudio to become ready.
|
||||
*/
|
||||
while (1)
|
||||
{
|
||||
if (pa_mainloop_iterate(mainloop, 1, &retval) < 0)
|
||||
goto error;
|
||||
|
||||
state = pa_context_get_state(context);
|
||||
|
||||
if (state == PA_CONTEXT_READY)
|
||||
break;
|
||||
|
||||
if (!PA_CONTEXT_IS_GOOD(state))
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enumerate all PulseAudio output devices (sinks).
|
||||
*/
|
||||
operation = pa_context_get_sink_info_list(
|
||||
context,
|
||||
pa_sinklist_cb,
|
||||
&output);
|
||||
|
||||
if (operation == NULL)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* Run the mainloop until enumeration is complete.
|
||||
*/
|
||||
while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
|
||||
{
|
||||
if (pa_mainloop_iterate(mainloop, 1, &retval) < 0)
|
||||
{
|
||||
pa_operation_unref(operation);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
{
|
||||
if (!output[i].initialized)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (output[i].name[0] == '\0')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
combo_add_elem(combo, output[i].name, NULL);
|
||||
}
|
||||
|
||||
pa_operation_unref(operation);
|
||||
|
||||
pa_context_disconnect(context);
|
||||
pa_context_unref(context);
|
||||
pa_mainloop_free(mainloop);
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
|
||||
pa_context_disconnect(context);
|
||||
pa_context_unref(context);
|
||||
pa_mainloop_free(mainloop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/combo.h>
|
||||
#include <gui/listbox.h>
|
||||
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "../helper/confighelper.h"
|
||||
|
||||
int find_default_config(config_setting_t *configs);
|
||||
void populate_combo_box(Combo* combo, config_t* cfg);
|
||||
void populate_device_list(ListBox *listbox, config_t* cfg);
|
||||
void add_serial_devices_to_combo(Combo *combo);
|
||||
void add_sound_devices_to_combo(Combo *combo);
|
||||
@@ -0,0 +1,337 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <basedir_fs.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "gameloop/gameloop.h"
|
||||
#include "gameloop/tachconfig.h"
|
||||
#include "devices/simdevice.h"
|
||||
#include "devices/sound.h"
|
||||
#include "helper/parameters.h"
|
||||
#include "helper/dirhelper.h"
|
||||
#include "helper/confighelper.h"
|
||||
#include "simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "slog/slog.h"
|
||||
|
||||
#define PROGRAM_NAME "monocoque"
|
||||
|
||||
int appstate = 0;
|
||||
|
||||
void display_banner()
|
||||
{
|
||||
printf("______ ______________ ___________________________________ ___________\n");
|
||||
printf("___ |/ /_ __ \\__ | / /_ __ \\_ ____/_ __ \\_ __ \\_ / / /__ ____/\n");
|
||||
printf("__ /|_/ /_ / / /_ |/ /_ / / / / _ / / / / / / / / /__ __/ \n");
|
||||
printf("_ / / / / /_/ /_ /| / / /_/ // /___ / /_/ // /_/ // /_/ / _ /___ \n");
|
||||
printf("/_/ /_/ \\____/ /_/ |_/ \\____/ \\____/ \\____/ \\___\\_\\\\____/ /_____/ \n");
|
||||
}
|
||||
|
||||
void SetSettingsFromParameters(Parameters* p, MonocoqueSettings* ms, char* configdir_str, char* cachedir_str)
|
||||
{
|
||||
|
||||
if(p->user_specified_config_file == true && does_file_exist(p->config_filepath))
|
||||
{
|
||||
ms->config_str = strdup(p->config_filepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(p->user_specified_config_dir == true && does_directory_exist(p->config_dirpath))
|
||||
{
|
||||
asprintf(&ms->config_str, "%s/%s", p->config_dirpath, "monocoque.config");
|
||||
}
|
||||
else
|
||||
{
|
||||
asprintf(&ms->config_str, "%s%s", configdir_str, "monocoque.config");
|
||||
}
|
||||
}
|
||||
|
||||
if(p->user_specified_log_file == true && does_file_exist(p->log_fullfilename_str))
|
||||
{
|
||||
ms->log_dirname_str = strdup(p->log_dirname_str);
|
||||
ms->log_filename_str = strdup(p->log_filename_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
ms->log_dirname_str = strdup(cachedir_str);
|
||||
ms->log_filename_str = strdup("monocoque.log");
|
||||
}
|
||||
|
||||
ms->fps = p->fps;
|
||||
|
||||
ms->verbosity_count = p->verbosity_count;
|
||||
ms->program_action = A_TEST;
|
||||
if (p->program_action == A_PLAY)
|
||||
{
|
||||
ms->program_action = A_PLAY;
|
||||
}
|
||||
if (p->program_action == A_CONFIG_TACH)
|
||||
{
|
||||
ms->program_action = A_CONFIG_TACH;
|
||||
}
|
||||
|
||||
ms->force_udp_mode = false;
|
||||
ms->disable_audio = p->disable_audio;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
appstate = 0;
|
||||
display_banner();
|
||||
|
||||
char* home_dir_str = gethome();
|
||||
if(home_dir_str == NULL)
|
||||
{
|
||||
fprintf(stderr, "You need a home directory");
|
||||
return 0;
|
||||
}
|
||||
Parameters* p = NULL;
|
||||
p = malloc(sizeof(Parameters));
|
||||
MonocoqueSettings* ms = malloc(sizeof(MonocoqueSettings));;
|
||||
|
||||
ConfigError ppe = getParameters(argc, argv, p);
|
||||
if (ppe == E_SUCCESS_AND_EXIT || ppe == E_SOMETHING_BAD)
|
||||
{
|
||||
printf("invalid parameters\n");
|
||||
goto cleanup_final;
|
||||
}
|
||||
|
||||
xdgHandle xdg;
|
||||
if(!xdgInitHandle(&xdg))
|
||||
{
|
||||
fprintf(stderr, "Function xdgInitHandle() failed, is $HOME unset?\n");
|
||||
goto cleanup_final;
|
||||
}
|
||||
|
||||
const char* config_home_str = xdgConfigHome(&xdg);
|
||||
const char* cache_home_str = xdgCacheHome(&xdg);
|
||||
|
||||
char* cachedir_str = NULL;
|
||||
char* configdir_str = NULL;
|
||||
|
||||
if(p->user_specified_config_file == false && p->user_specified_config_dir == false)
|
||||
{
|
||||
create_xdg_dir(config_home_str);
|
||||
configdir_str = create_user_dir(home_dir_str, ".config", PROGRAM_NAME);
|
||||
}
|
||||
if(p->user_specified_log_file == false)
|
||||
{
|
||||
create_xdg_dir(cache_home_str);
|
||||
cachedir_str = create_user_dir(home_dir_str, ".cache", PROGRAM_NAME);
|
||||
}
|
||||
|
||||
fprintf(stderr, "applying settings\n");
|
||||
SetSettingsFromParameters(p, ms, configdir_str, cachedir_str);
|
||||
|
||||
if(cachedir_str != NULL)
|
||||
{
|
||||
free(cachedir_str);
|
||||
}
|
||||
if(configdir_str != NULL)
|
||||
{
|
||||
free(configdir_str);
|
||||
}
|
||||
fprintf(stderr, "settings applied\n");
|
||||
|
||||
|
||||
slog_init("monocoque", SLOG_FLAGS_ALL, 1);
|
||||
slog_config_t slgCfg;
|
||||
slog_config_get(&slgCfg);
|
||||
slgCfg.eColorFormat = SLOG_COLORING_TAG;
|
||||
slgCfg.eDateControl = SLOG_TIME_ONLY;
|
||||
strcpy(slgCfg.sFileName, ms->log_filename_str);
|
||||
strcpy(slgCfg.sFilePath, ms->log_dirname_str);
|
||||
slgCfg.nTraceTid = 0;
|
||||
slgCfg.nToScreen = 1;
|
||||
slgCfg.nUseHeap = 0;
|
||||
slgCfg.nToFile = 1;
|
||||
slgCfg.nFlush = 0;
|
||||
slgCfg.nFlags = SLOG_FLAGS_ALL;
|
||||
slog_config_set(&slgCfg);
|
||||
if (ms->verbosity_count < 2)
|
||||
{
|
||||
slog_disable(SLOG_TRACE);
|
||||
}
|
||||
if (ms->verbosity_count < 1)
|
||||
{
|
||||
slog_disable(SLOG_DEBUG);
|
||||
}
|
||||
xdgWipeHandle(&xdg);
|
||||
|
||||
slogi("checking for diameters config");
|
||||
char* diameters_file_str;
|
||||
asprintf(&diameters_file_str, "%s/.config/monocoque/diameters.config", home_dir_str);
|
||||
ms->tyre_diameter_config = strdup(diameters_file_str);
|
||||
free(diameters_file_str);
|
||||
|
||||
ms->useconfig = 0;
|
||||
ms->configcheck = 0;
|
||||
|
||||
|
||||
slogi("Testing monocoque config file: %s", ms->config_str);
|
||||
slogd("using diameters file %s %i", ms->tyre_diameter_config, ms->configcheck);
|
||||
config_t cfg;
|
||||
config_init(&cfg);
|
||||
config_setting_t* config_devices = NULL;
|
||||
if (!config_read_file(&cfg, ms->config_str))
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("Opened and validated monocoque configuration file");
|
||||
}
|
||||
config_destroy(&cfg);
|
||||
|
||||
|
||||
|
||||
if (ms->program_action == A_CONFIG_TACH)
|
||||
{
|
||||
int error = 0;
|
||||
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);
|
||||
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
sloge("Could not proceed with tachometer configuration due to error: %i", error);
|
||||
}
|
||||
else
|
||||
{
|
||||
int devices = 0;
|
||||
|
||||
devices = devinit(tachdev, siminfo, 1, ds, ms);
|
||||
if(devices < 1)
|
||||
{
|
||||
error = MONOCOQUE_ERROR_INVALID_DEV;
|
||||
}
|
||||
}
|
||||
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
sloge("Could not proceed with tachometer configuration due to error: %i", error);
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("configuring tachometer with max revs: %i, granularity: %i, saving to %s", p->max_revs, p->granularity, p->save_file);
|
||||
config_tachometer(p->max_revs, p->granularity, p->save_file, tachdev, sdata);
|
||||
}
|
||||
|
||||
slogt("freeing devices if necessary");
|
||||
if(tachdev->initialized == true)
|
||||
{
|
||||
slogt("freeing tachmoeter device");
|
||||
tachdev->free(tachdev);
|
||||
}
|
||||
//free(tachdev);
|
||||
free(sdata);
|
||||
free(ds);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
int error = 0;
|
||||
error = MONOCOQUE_ERROR_NONE;
|
||||
//setupsound();
|
||||
bool pulseaudio = false;
|
||||
|
||||
if (ms->program_action == A_PLAY)
|
||||
{
|
||||
ms->useconfig = 1;
|
||||
slogi("running monocoque in gameloop mode..");
|
||||
//#ifdef USE_PULSEAUDIO
|
||||
//pa_threaded_mainloop_unlock(mainloop);
|
||||
pulseaudio = true;
|
||||
//#endif
|
||||
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
setupsound();
|
||||
}
|
||||
//error = looper(devices, numdevices, p);
|
||||
error = monocoque_mainloop(ms);
|
||||
if (error == MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
slogi("Game loop exited succesfully with error code: %i", error);
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Game loop exited with error code: %i", error);
|
||||
}
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
freesound();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("running monocoque in test mode...");
|
||||
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
setupsound();
|
||||
}
|
||||
ms->useconfig = 0;
|
||||
|
||||
int configs = getNumberOfConfigs(ms->config_str);
|
||||
int confignum = getconfigtouse(ms->config_str, "default", configs-1);
|
||||
int configureddevices;
|
||||
configcheck(ms->config_str, confignum, &configureddevices);
|
||||
|
||||
DeviceSettings* ds = malloc(configureddevices * sizeof(DeviceSettings));
|
||||
slogd("loading confignum %i, with %i devices.", confignum, configureddevices);
|
||||
|
||||
int numdevices = uiloadconfig(ms->config_str, confignum, configureddevices, ms, ds);
|
||||
SimDevice* simdevices = malloc(numdevices * sizeof(SimDevice));
|
||||
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]);
|
||||
}
|
||||
free(ds);
|
||||
error = tester(simdevices, numdevices);
|
||||
if (error == MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
slogi("Test exited succesfully with error code: %i", error);
|
||||
}
|
||||
else
|
||||
{
|
||||
sloge("Test exited with error code: %i", error);
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (simdevices[x].initialized == true)
|
||||
{
|
||||
simdevices[x].free(&simdevices[x]);
|
||||
}
|
||||
}
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
freesound();
|
||||
}
|
||||
}
|
||||
slog_destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
cleanup_final:
|
||||
monocoquesettingsfree(ms);
|
||||
free(ms);
|
||||
freeparams(p);
|
||||
free(p);
|
||||
exit(0);
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <basedir_fs.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "mgui/uiconfighelper.h"
|
||||
#include "mgui/addeditaction.h"
|
||||
#include "mgui/mainwindow.h"
|
||||
|
||||
#include "gameloop/gameloop.h"
|
||||
#include "gameloop/loopdata.h"
|
||||
#include "gameloop/tachconfig.h"
|
||||
#include "devices/simdevice.h"
|
||||
#include "devices/sound.h"
|
||||
#include "helper/parameters.h"
|
||||
#include "helper/dirhelper.h"
|
||||
#include "helper/confighelper.h"
|
||||
#include "simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "slog/slog.h"
|
||||
|
||||
#include <nappgui.h>
|
||||
#include <gui/guiall.h>
|
||||
|
||||
|
||||
#define PROGRAM_NAME "monocoque"
|
||||
MonocoqueSettings ms;
|
||||
Parameters* p;
|
||||
|
||||
char **m_argv;
|
||||
int m_argc;
|
||||
int appstate = 0;
|
||||
|
||||
void SetSettingsFromParameters(Parameters* p, MonocoqueSettings* ms, char* configdir_str, char* cachedir_str)
|
||||
{
|
||||
|
||||
if(p->user_specified_config_file == true && does_file_exist(p->config_filepath))
|
||||
{
|
||||
ms->config_str = strdup(p->config_filepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(p->user_specified_config_dir == true && does_directory_exist(p->config_dirpath))
|
||||
{
|
||||
asprintf(&ms->config_str, "%s/%s", p->config_dirpath, "monocoque.config");
|
||||
}
|
||||
else
|
||||
{
|
||||
asprintf(&ms->config_str, "%s%s", configdir_str, "monocoque.config");
|
||||
}
|
||||
}
|
||||
|
||||
if(p->user_specified_log_file == true && does_file_exist(p->log_fullfilename_str))
|
||||
{
|
||||
ms->log_dirname_str = strdup(p->log_dirname_str);
|
||||
ms->log_filename_str = strdup(p->log_filename_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
ms->log_dirname_str = strdup(cachedir_str);
|
||||
ms->log_filename_str = strdup("monocoque.log");
|
||||
}
|
||||
|
||||
ms->fps = p->fps;
|
||||
|
||||
ms->verbosity_count = p->verbosity_count;
|
||||
ms->program_action = A_TEST;
|
||||
if (p->program_action == A_PLAY)
|
||||
{
|
||||
ms->program_action = A_PLAY;
|
||||
}
|
||||
if (p->program_action == A_CONFIG_TACH)
|
||||
{
|
||||
ms->program_action = A_CONFIG_TACH;
|
||||
}
|
||||
|
||||
ms->force_udp_mode = false;
|
||||
ms->disable_audio = p->disable_audio;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
int monocoque_initialize(int argc, char** argv)
|
||||
{
|
||||
|
||||
char* home_dir_str = gethome();
|
||||
if(home_dir_str == NULL)
|
||||
{
|
||||
fprintf(stderr, "You need a home directory");
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = NULL;
|
||||
p = malloc(sizeof(Parameters));
|
||||
p->config_dirpath = NULL;
|
||||
p->config_filepath = NULL;
|
||||
p->log_filename_str = NULL;
|
||||
p->log_fullfilename_str = NULL;
|
||||
p->log_dirname_str = NULL;
|
||||
|
||||
ConfigError ppe = getParameters(argc, argv, p);
|
||||
if (ppe == E_SUCCESS_AND_EXIT || ppe == E_SOMETHING_BAD)
|
||||
{
|
||||
printf("invalid parameters\n");
|
||||
//goto cleanup_final;
|
||||
}
|
||||
|
||||
xdgHandle xdg;
|
||||
if(!xdgInitHandle(&xdg))
|
||||
{
|
||||
fprintf(stderr, "Function xdgInitHandle() failed, is $HOME unset?\n");
|
||||
//goto cleanup_final;
|
||||
}
|
||||
const char* config_home_str = xdgConfigHome(&xdg);
|
||||
const char* cache_home_str = xdgCacheHome(&xdg);
|
||||
|
||||
char* cachedir_str = NULL;
|
||||
char* configdir_str = NULL;
|
||||
|
||||
if(p->user_specified_config_file == false && p->user_specified_config_dir == false)
|
||||
{
|
||||
create_xdg_dir(config_home_str);
|
||||
configdir_str = create_user_dir(home_dir_str, ".config", PROGRAM_NAME);
|
||||
}
|
||||
if(p->user_specified_log_file == false)
|
||||
{
|
||||
create_xdg_dir(cache_home_str);
|
||||
cachedir_str = create_user_dir(home_dir_str, ".cache", PROGRAM_NAME);
|
||||
}
|
||||
|
||||
SetSettingsFromParameters(p, &ms, configdir_str, cachedir_str);
|
||||
|
||||
if(cachedir_str != NULL)
|
||||
{
|
||||
free(cachedir_str);
|
||||
}
|
||||
if(configdir_str != NULL)
|
||||
{
|
||||
free(configdir_str);
|
||||
}
|
||||
|
||||
slog_init("monocoque", SLOG_FLAGS_ALL, 1);
|
||||
slog_config_t slgCfg;
|
||||
slog_config_get(&slgCfg);
|
||||
slgCfg.eColorFormat = SLOG_COLORING_TAG;
|
||||
slgCfg.eDateControl = SLOG_TIME_ONLY;
|
||||
strcpy(slgCfg.sFileName, ms.log_filename_str);
|
||||
strcpy(slgCfg.sFilePath, ms.log_dirname_str);
|
||||
slgCfg.nTraceTid = 0;
|
||||
slgCfg.nToScreen = 1;
|
||||
slgCfg.nUseHeap = 0;
|
||||
slgCfg.nToFile = 1;
|
||||
slgCfg.nFlush = 0;
|
||||
slgCfg.nFlags = SLOG_FLAGS_ALL;
|
||||
slog_config_set(&slgCfg);
|
||||
if (ms.verbosity_count < 2)
|
||||
{
|
||||
slog_disable(SLOG_TRACE);
|
||||
}
|
||||
if (ms.verbosity_count < 1)
|
||||
{
|
||||
slog_disable(SLOG_DEBUG);
|
||||
}
|
||||
xdgWipeHandle(&xdg);
|
||||
|
||||
|
||||
|
||||
|
||||
if(ms.disable_audio == false)
|
||||
{
|
||||
setupsound();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
int monocoque_gameloop_start()
|
||||
{
|
||||
start_loop(&ms);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnStart(App *app, Event *e)
|
||||
{
|
||||
unref(e);
|
||||
app->is_running = TRUE;
|
||||
|
||||
int rc = 0;
|
||||
if(appstate == 0)
|
||||
{
|
||||
rc = monocoque_gameloop_start();
|
||||
}
|
||||
else
|
||||
{
|
||||
monocoque_mainloop_stop(&ms);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnStop(App *app, Event *e)
|
||||
{
|
||||
monocoque_mainloop_stop(&ms);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnClose(App *app, Event *e)
|
||||
{
|
||||
close_monocoque_config(ms.cfg);
|
||||
monocoquesettingsfree(&ms);
|
||||
|
||||
freeparams(p);
|
||||
free(p);
|
||||
|
||||
for (int i = 0; i < (uint32_t)m_argc; ++i)
|
||||
free(m_argv[i]);
|
||||
free(m_argv);
|
||||
|
||||
osapp_finish();
|
||||
unref(app);
|
||||
unref(e);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnAddClose(App *app, Event *e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void i_OnDelete(App* app, Event *e)
|
||||
{
|
||||
int devicenum = listbox_get_selected(app->listbox_devices);
|
||||
if(devicenum == UINT32_MAX)
|
||||
{
|
||||
return;
|
||||
}
|
||||
delete_device_config(ms.cfg, ms.config_str, 0, devicenum);
|
||||
|
||||
listbox_clear(app->listbox_devices);
|
||||
combo_clear(app->combo_configurations);
|
||||
populate_device_list(app->listbox_devices, ms.cfg);
|
||||
populate_combo_box(app->combo_configurations, ms.cfg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnAddEdit(App* app, Event *e, enum device_action device_action)
|
||||
{
|
||||
Panel *panel = NULL;
|
||||
|
||||
int devicenum = listbox_get_selected(app->listbox_devices);
|
||||
if(devicenum == UINT32_MAX && device_action == DEVICE_ACTION_EDIT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(device_action == DEVICE_ACTION_ADD)
|
||||
{
|
||||
devicenum = listbox_count(app->listbox_devices);
|
||||
}
|
||||
app->window2 = window_create(ekWINDOW_STDRES);
|
||||
|
||||
panel = adddevice_window(app->window2, app, &ms, device_action, 0, devicenum);
|
||||
|
||||
window_panel(app->window2, panel);
|
||||
window_origin(app->window2, v2df(800, 200));
|
||||
window_title(app->window2, "monocoque");
|
||||
window_OnClose(app->window2, listener(app, i_OnAddClose, App));
|
||||
|
||||
window_modal(app->window2, app->window);
|
||||
|
||||
window_destroy(&app->window2);
|
||||
|
||||
listbox_clear(app->listbox_devices);
|
||||
combo_clear(app->combo_configurations);
|
||||
populate_device_list(app->listbox_devices, ms.cfg);
|
||||
populate_combo_box(app->combo_configurations, ms.cfg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnAdd(App *app, Event *e)
|
||||
{
|
||||
i_OnAddEdit(app, e, DEVICE_ACTION_ADD);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_OnEdit(App *app, Event *e)
|
||||
{
|
||||
i_OnAddEdit(app, e, DEVICE_ACTION_EDIT);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
static void set_bottom_label_status(Label* label)
|
||||
{
|
||||
char status_string[256];
|
||||
snprintf(status_string, 256, "Game: %s Game Status: None Simd: %s", get_simexe_name(), get_simd_onoff());
|
||||
label_text(label, status_string);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static Panel *i_panel(App *app, MonocoqueSettings* ms)
|
||||
{
|
||||
app->main_panel = panel_create();
|
||||
app->subpanel = panel_scroll(FALSE, TRUE);
|
||||
|
||||
app->layout = layout_create(8,5);
|
||||
|
||||
|
||||
app->listbox_devices = listbox_create();
|
||||
listbox_size(app->listbox_devices, s2df(50, 50));
|
||||
app->combo_configurations = combo_create();
|
||||
app->label_configurations = label_create();
|
||||
label_text(app->label_configurations, "Configuration: ");
|
||||
app->label_game_status = label_create();
|
||||
|
||||
app->button_startstop = button_push();
|
||||
app->button_add = button_push();
|
||||
app->button_edit = button_push();
|
||||
app->button_del = button_push();
|
||||
|
||||
app->layout1 = layout_create(8,1);
|
||||
app->layout2 = layout_create(8,1);
|
||||
app->layout3 = layout_create(1,1);
|
||||
app->layout4 = layout_create(1,2);
|
||||
|
||||
layout_layout(app->layout, app->layout1, 0, 0);
|
||||
layout_layout(app->layout, app->layout2, 0, 1);
|
||||
layout_layout(app->layout, app->layout3, 0, 2);
|
||||
layout_layout(app->layout, app->layout4, 0, 3);
|
||||
|
||||
appstate = 0;
|
||||
|
||||
set_bottom_label_status(app->label_game_status);
|
||||
populate_device_list(app->listbox_devices, ms->cfg);
|
||||
listbox_select(app->listbox_devices, 0, true);
|
||||
populate_combo_box(app->combo_configurations, ms->cfg);
|
||||
|
||||
|
||||
button_text(app->button_startstop, "Start");
|
||||
button_text(app->button_add, "Add Device");
|
||||
button_text(app->button_del, "Delete Device");
|
||||
button_text(app->button_edit, "Edit Device");
|
||||
button_OnClick(app->button_startstop, listener(app, i_OnStart, App));
|
||||
button_OnClick(app->button_add, listener(app, i_OnAdd, App));
|
||||
button_OnClick(app->button_edit, listener(app, i_OnEdit, App));
|
||||
button_OnClick(app->button_del, listener(app, i_OnDelete, App));
|
||||
|
||||
|
||||
layout_label(app->layout1, app->label_configurations, 0, 0);
|
||||
layout_combo(app->layout1, app->combo_configurations, 1, 0);
|
||||
|
||||
layout_button(app->layout2, app->button_add, 3, 0);
|
||||
layout_button(app->layout2, app->button_edit, 4, 0);
|
||||
layout_button(app->layout2, app->button_del, 5, 0);
|
||||
|
||||
layout_listbox(app->layout3, app->listbox_devices, 0, 0);
|
||||
|
||||
layout_button(app->layout4, app->button_startstop, 0, 0);
|
||||
layout_label(app->layout4, app->label_game_status, 0, 1);
|
||||
|
||||
panel_layout(app->subpanel, app->layout3);
|
||||
layout_panel(app->layout, app->subpanel, 0, 2);
|
||||
|
||||
panel_layout(app->main_panel, app->layout);
|
||||
|
||||
|
||||
app->devices_subpanel = layout_cell(app->layout, 0, 2);
|
||||
|
||||
// spacing
|
||||
|
||||
layout_valign(app->layout4, 0, 0, ekBOTTOM);
|
||||
layout_valign(app->layout4, 0, 1, ekBOTTOM);
|
||||
|
||||
layout_halign(app->layout4, 0, 0, ekJUSTIFY);
|
||||
layout_halign(app->layout4, 0, 1, ekJUSTIFY);
|
||||
|
||||
layout_hexpand(app->layout, 0);
|
||||
layout_hexpand(app->layout4, 0);
|
||||
|
||||
layout_vexpand(app->layout, 0);
|
||||
layout_vexpand(app->layout, 2);
|
||||
layout_vexpand(app->layout4, 0);
|
||||
|
||||
button_vpadding(app->button_startstop, 0);
|
||||
button_hpadding(app->button_startstop, 0);
|
||||
layout_hexpand(app->layout1, 1);
|
||||
|
||||
return app->main_panel;
|
||||
}
|
||||
|
||||
|
||||
static App *i_create(void)
|
||||
{
|
||||
uint32_t i;
|
||||
int old_argc = (int)osapp_argc();
|
||||
m_argc = old_argc + 1;
|
||||
|
||||
m_argv = malloc((m_argc+1) * sizeof(char *));
|
||||
m_argv[m_argc] = NULL;
|
||||
for (i = 0; i < (uint32_t)m_argc; ++i)
|
||||
{
|
||||
char buffer[128];
|
||||
m_argv[i] = NULL;
|
||||
if (i == 1)
|
||||
{
|
||||
m_argv[i] = strdup("play");
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t old_i = (i > 1) ? i - 1 : i;
|
||||
osapp_argv(old_i, buffer, sizeof(buffer));
|
||||
m_argv[i] = strdup(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// do some monocoque things here
|
||||
ms.tyre_diameter_config = NULL;
|
||||
ms.config_str = NULL;
|
||||
ms.log_filename_str = NULL;
|
||||
ms.log_dirname_str = NULL;
|
||||
|
||||
monocoque_initialize(m_argc, m_argv);
|
||||
ms.cfg = open_monocoque_config(ms.config_str);
|
||||
|
||||
// find a better spot for this
|
||||
dbind(SimData, uint32_t, velocity);
|
||||
dbind(SimData, uint32_t, rpms);
|
||||
dbind(SimData, uint32_t, gear);
|
||||
dbind(SimData, uint32_t, maxrpm);
|
||||
dbind(SimData, real64_t, tyreRPS[0]);
|
||||
dbind(SimData, real64_t, tyreRPS[1]);
|
||||
dbind(SimData, real64_t, tyreRPS[2]);
|
||||
dbind(SimData, real64_t, tyreRPS[3]);
|
||||
dbind(SimData, real64_t, tyrediameter[0]);
|
||||
dbind(SimData, real64_t, tyrediameter[1]);
|
||||
dbind(SimData, real64_t, tyrediameter[2]);
|
||||
dbind(SimData, real64_t, tyrediameter[3]);
|
||||
|
||||
dbind(DeviceSettings, HapticEffectSettings, hapticsettings);
|
||||
dbind(HapticEffectSettings, uint32_t, frequency);
|
||||
dbind(HapticEffectSettings, uint32_t, frequencyMax);
|
||||
dbind(HapticEffectSettings, uint32_t, amplitude);
|
||||
dbind(HapticEffectSettings, uint32_t, amplitudeMax);
|
||||
dbind(HapticEffectSettings, uint32_t, motorposition);
|
||||
dbind(HapticEffectSettings, real64_t, threshold);
|
||||
dbind(HapticEffectSettings, real64_t, duration);
|
||||
dbind_enum(VibrationEffectType, EFFECT_ENGINERPM, "Engine RPM");
|
||||
dbind_enum(VibrationEffectType, EFFECT_GEARSHIFT, "Gear Shift");
|
||||
dbind_enum(VibrationEffectType, EFFECT_ABSBRAKES, "ABS Brakes");
|
||||
dbind_enum(VibrationEffectType, EFFECT_TYRESLIP, "Tyre Slip");
|
||||
dbind_enum(VibrationEffectType, EFFECT_TYRELOCK, "Tyre Lock");
|
||||
dbind_enum(VibrationEffectType, EFFECT_SUSPENSION, "Suspension");
|
||||
dbind_enum(EffectModulationType, EFFECT_MODULATION_NONE, "None");
|
||||
dbind_enum(EffectModulationType, EFFECT_MODULATION_FREQUENCY, "Frequency");
|
||||
dbind_enum(EffectModulationType, EFFECT_MODULATION_AMPLIFY, "Amplify");
|
||||
dbind_enum(MonocoqueTyreIdentifier, FRONTLEFT, "Front Left");
|
||||
dbind_enum(MonocoqueTyreIdentifier, FRONTRIGHT, "Front Right");
|
||||
dbind_enum(MonocoqueTyreIdentifier, REARLEFT, "Rear Left");
|
||||
dbind_enum(MonocoqueTyreIdentifier, REARRIGHT, "Rear Right");
|
||||
dbind_enum(MonocoqueTyreIdentifier, FRONTS, "Fronts");
|
||||
dbind_enum(MonocoqueTyreIdentifier, REARS, "Rears");
|
||||
dbind_enum(MonocoqueTyreIdentifier, ALLFOUR, "All Four");
|
||||
dbind(HapticEffectSettings, uint32_t, modulation);
|
||||
dbind(HapticEffectSettings, uint32_t, tyre);
|
||||
dbind(HapticEffectSettings, uint32_t, effect_type);
|
||||
dbind(DeviceSettings, SerialDeviceSettings, serialdevsettings);
|
||||
dbind(SerialDeviceSettings, uint32_t, baud);
|
||||
dbind(SoundDeviceSettings, uint32_t, pan);
|
||||
dbind(SoundDeviceSettings, uint32_t, channels);
|
||||
dbind(SoundDeviceSettings, uint32_t, volume);
|
||||
dbind(DeviceSettings, SerialDeviceSettings, serialdevsettings);
|
||||
dbind(SerialDeviceSettings, uint32_t, startled);
|
||||
dbind(SerialDeviceSettings, uint32_t, numleds);
|
||||
dbind(SerialDeviceSettings, uint32_t, endled);
|
||||
dbind_enum(DeviceType, SIMDEV_USB, "USB");
|
||||
dbind_enum(DeviceType, SIMDEV_SOUND, "Sound");
|
||||
dbind_enum(DeviceType, SIMDEV_SERIAL, "Serial");
|
||||
dbind(DeviceSettings, DeviceType, dev_type);
|
||||
dbind(DeviceSettings, uint32_t, dev_subtype);
|
||||
dbind(DeviceSettings, uint32_t, fps);
|
||||
//gui stuff
|
||||
App *app = heap_new0(App);
|
||||
|
||||
Panel *panel = i_panel(app, &ms);
|
||||
app->window = window_create(ekWINDOW_STDRES);
|
||||
window_panel(app->window, panel);
|
||||
window_origin(app->window, v2df(800, 200));
|
||||
window_title(app->window, "monocoque");
|
||||
window_OnClose(app->window, listener(app, i_OnClose, App));
|
||||
window_show(app->window);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static void i_destroy(App **app)
|
||||
{
|
||||
//monocoquesettingsfree(&ms);
|
||||
//freeparams(p);
|
||||
//free(p);
|
||||
osapp_finish();
|
||||
window_destroy(&(*app)->window);
|
||||
heap_delete(app, App);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
static void i_update(App *app, const real64_t prtime, const real64_t ctime)
|
||||
{
|
||||
if (app->is_running == TRUE)
|
||||
{
|
||||
if(appstate == 2)
|
||||
{
|
||||
button_text(app->button_startstop, "Playing... Press to Stop");
|
||||
cell_enabled(app->devices_subpanel, false);
|
||||
}
|
||||
if(appstate == 1)
|
||||
{
|
||||
button_text(app->button_startstop, "Searching for data... Press to Stop");
|
||||
cell_enabled(app->devices_subpanel, false);
|
||||
}
|
||||
if(appstate <= 0)
|
||||
{
|
||||
button_text(app->button_startstop, "Start");
|
||||
cell_enabled(app->devices_subpanel, true);
|
||||
}
|
||||
set_bottom_label_status(app->label_game_status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <osapp/osmain.h>
|
||||
osmain_sync(.04, i_create, i_destroy, i_update, "", App)
|
||||
+65
-32
@@ -68,6 +68,9 @@ void SetSettingsFromParameters(Parameters* p, MonocoqueSettings* ms, char* confi
|
||||
{
|
||||
ms->program_action = A_CONFIG_TACH;
|
||||
}
|
||||
|
||||
ms->force_udp_mode = false;
|
||||
ms->disable_audio = p->disable_audio;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -80,19 +83,22 @@ int main(int argc, char** argv)
|
||||
fprintf(stderr, "You need a home directory");
|
||||
return 0;
|
||||
}
|
||||
Parameters* p = malloc(sizeof(Parameters));
|
||||
Parameters* p = NULL;
|
||||
p = malloc(sizeof(Parameters));
|
||||
MonocoqueSettings* ms = malloc(sizeof(MonocoqueSettings));;
|
||||
|
||||
ConfigError ppe = getParameters(argc, argv, p);
|
||||
if (ppe == E_SUCCESS_AND_EXIT)
|
||||
if (ppe == E_SUCCESS_AND_EXIT || ppe == E_SOMETHING_BAD)
|
||||
{
|
||||
printf("invalid parameters\n");
|
||||
goto cleanup_final;
|
||||
}
|
||||
|
||||
xdgHandle xdg;
|
||||
if(!xdgInitHandle(&xdg))
|
||||
{
|
||||
fprintf(stderr, "Function xdgInitHandle() failed, is $HOME unset?");
|
||||
fprintf(stderr, "Function xdgInitHandle() failed, is $HOME unset?\n");
|
||||
goto cleanup_final;
|
||||
}
|
||||
|
||||
const char* config_home_str = xdgConfigHome(&xdg);
|
||||
@@ -112,17 +118,21 @@ int main(int argc, char** argv)
|
||||
cachedir_str = create_user_dir(home_dir_str, ".cache", PROGRAM_NAME);
|
||||
}
|
||||
|
||||
fprintf(stderr, "applying settings\n");
|
||||
SetSettingsFromParameters(p, ms, configdir_str, cachedir_str);
|
||||
freeparams(p);
|
||||
free(p);
|
||||
|
||||
//char* config_file_str = ( char* ) malloc(1 + strlen(home_dir_str) + strlen("/.config/") + strlen("monocoque/monocoque.config"));
|
||||
|
||||
size_t diameters_file_sz = snprintf(NULL, 0, "%s/.config/monocoque/diameters.config", home_dir_str);
|
||||
diameters_file_sz += 1;
|
||||
char* diameters_file_str = ( char* ) malloc(diameters_file_sz);
|
||||
snprintf(diameters_file_str, diameters_file_sz, "%s/.config/monocoque/diameters.config", home_dir_str);
|
||||
if(cachedir_str != NULL)
|
||||
{
|
||||
free(cachedir_str);
|
||||
}
|
||||
if(configdir_str != NULL)
|
||||
{
|
||||
free(configdir_str);
|
||||
}
|
||||
fprintf(stderr, "settings applied\n");
|
||||
|
||||
|
||||
slog_init("monocoque", SLOG_FLAGS_ALL, 1);
|
||||
slog_config_t slgCfg;
|
||||
slog_config_get(&slgCfg);
|
||||
slgCfg.eColorFormat = SLOG_COLORING_TAG;
|
||||
@@ -144,11 +154,17 @@ int main(int argc, char** argv)
|
||||
{
|
||||
slog_disable(SLOG_DEBUG);
|
||||
}
|
||||
xdgWipeHandle(&xdg);
|
||||
|
||||
slogi("checking for diameters config");
|
||||
char* diameters_file_str;
|
||||
asprintf(&diameters_file_str, "%s/.config/monocoque/diameters.config", home_dir_str);
|
||||
ms->tyre_diameter_config = strdup(diameters_file_str);
|
||||
free(diameters_file_str);
|
||||
|
||||
ms->useconfig = 0;
|
||||
ms->configcheck = 0;
|
||||
free(diameters_file_str);
|
||||
|
||||
|
||||
slogi("Testing monocoque config file: %s", ms->config_str);
|
||||
slogd("using diameters file %s %i", ms->tyre_diameter_config, ms->configcheck);
|
||||
@@ -157,13 +173,17 @@ 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;
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("Openend monocoque configuration file");
|
||||
slogi("Opened and validated monocoque configuration file");
|
||||
}
|
||||
config_destroy(&cfg);
|
||||
|
||||
|
||||
|
||||
@@ -171,7 +191,10 @@ int main(int argc, char** argv)
|
||||
{
|
||||
int error = 0;
|
||||
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);
|
||||
@@ -183,7 +206,8 @@ int main(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
int devices = 0;
|
||||
devices = devinit(tachdev, 1, ds, ms);
|
||||
|
||||
devices = devinit(tachdev, siminfo, 1, ds, ms);
|
||||
if(devices < 1)
|
||||
{
|
||||
error = MONOCOQUE_ERROR_INVALID_DEV;
|
||||
@@ -215,18 +239,22 @@ int main(int argc, char** argv)
|
||||
|
||||
int error = 0;
|
||||
error = MONOCOQUE_ERROR_NONE;
|
||||
setupsound();
|
||||
//setupsound();
|
||||
bool pulseaudio = false;
|
||||
|
||||
if (ms->program_action == A_PLAY)
|
||||
{
|
||||
ms->useconfig = 1;
|
||||
slogi("running monocoque in gameloop mode..");
|
||||
#ifdef USE_PULSEAUDIO
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
//#ifdef USE_PULSEAUDIO
|
||||
//pa_threaded_mainloop_unlock(mainloop);
|
||||
pulseaudio = true;
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
setupsound();
|
||||
}
|
||||
//error = looper(devices, numdevices, p);
|
||||
error = monocoque_mainloop(ms);
|
||||
if (error == MONOCOQUE_ERROR_NONE)
|
||||
@@ -237,16 +265,19 @@ int main(int argc, char** argv)
|
||||
{
|
||||
sloge("Game loop exited with error code: %i", error);
|
||||
}
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
freesound();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slogi("running monocoque in test mode...");
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
pa_threaded_mainloop_unlock(mainloop);
|
||||
pulseaudio = true;
|
||||
#endif
|
||||
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
setupsound();
|
||||
}
|
||||
ms->useconfig = 0;
|
||||
|
||||
int configs = getNumberOfConfigs(ms->config_str);
|
||||
@@ -259,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]);
|
||||
@@ -281,20 +314,20 @@ int main(int argc, char** argv)
|
||||
simdevices[x].free(&simdevices[x]);
|
||||
}
|
||||
}
|
||||
if(ms->disable_audio == false)
|
||||
{
|
||||
freesound();
|
||||
}
|
||||
}
|
||||
if(pulseaudio == true)
|
||||
{
|
||||
freesound();
|
||||
}
|
||||
slog_destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
cleanup_final:
|
||||
|
||||
monocoquesettingsfree(ms);
|
||||
free(ms);
|
||||
freeparams(p);
|
||||
free(p);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,16 +6,42 @@ set(simulatorapi_source_files
|
||||
simapi/include/acdata.h
|
||||
simapi/include/rf2data.h
|
||||
simapi/include/pcars2data.h
|
||||
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
|
||||
simapi/simapi/ac.h
|
||||
simapi/simapi/rf2.h
|
||||
simapi/simapi/dirt2.h
|
||||
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})
|
||||
|
||||
set_property(TARGET simulatorapi PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
Submodule src/monocoque/simulatorapi/simapi updated: ce13b736e1...50fd181681
@@ -4,3 +4,5 @@ set(slog_source_files
|
||||
)
|
||||
|
||||
add_library(slog STATIC ${slog_source_files})
|
||||
|
||||
set_property(TARGET slog PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ int main(int argc, char* argv[])
|
||||
pid = getpid();
|
||||
|
||||
// get shared memory file descriptor (NOT a file)
|
||||
fd = shm_open(TEST_MEM_FILE_LOCATION, O_RDONLY, S_IRUSR | S_IWUSR);
|
||||
fd = shm_open(SIMAPI_MEM_FILE, O_RDONLY, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1)
|
||||
{
|
||||
return 10;
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
pid = getpid();
|
||||
|
||||
fd = shm_open(TEST_MEM_FILE_LOCATION, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
fd = shm_open(SIMAPI_MEM_FILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("open");
|
||||
@@ -99,7 +99,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||
|
||||
fd = shm_unlink(TEST_MEM_FILE_LOCATION);
|
||||
fd = shm_unlink(SIMAPI_MEM_FILE);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("unlink");
|
||||
|
||||
+207
-66
@@ -1,75 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <libserialport.h>
|
||||
#include "../src/arduino/shiftlights/shiftlights.h"
|
||||
|
||||
/* Helper function for error handling. */
|
||||
int check(enum sp_return result);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
char* port_name = "/dev/ttyACM0";
|
||||
|
||||
/* The ports we will use. */
|
||||
struct sp_port* port;
|
||||
|
||||
/* Open and configure each port. */
|
||||
printf("Looking for port %s.\n", port_name);
|
||||
check(sp_get_port_by_name(port_name, &port));
|
||||
|
||||
printf("Opening port.\n");
|
||||
check(sp_open(port, SP_MODE_READ_WRITE));
|
||||
|
||||
printf("Setting port to 115200 8N1, no flow control.\n");
|
||||
check(sp_set_baudrate(port, 115200));
|
||||
check(sp_set_bits(port, 8));
|
||||
check(sp_set_parity(port, SP_PARITY_NONE));
|
||||
check(sp_set_stopbits(port, 1));
|
||||
check(sp_set_flowcontrol(port, SP_FLOWCONTROL_NONE));
|
||||
|
||||
ShiftLightsData sd;
|
||||
|
||||
|
||||
int result;
|
||||
unsigned int timeout = 2000;
|
||||
size_t size = sizeof(ShiftLightsData);
|
||||
for( sd.litleds = 0; sd.litleds < 7; sd.litleds++)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/* On success, sp_blocking_write() and sp_blocking_read()
|
||||
* return the number of bytes sent/received before the
|
||||
* timeout expired. We'll store that result here. */
|
||||
|
||||
|
||||
|
||||
/* Send data. */
|
||||
result = check(sp_blocking_write(port, &sd, size, timeout));
|
||||
|
||||
/* Check whether we sent all of the data. */
|
||||
if (result == size)
|
||||
{
|
||||
printf("Sent %d bytes successfully, %i lit leds.\n", size, sd.litleds);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Timed out, %d/%d bytes sent.\n", result, size);
|
||||
}
|
||||
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
sd.litleds = 0;
|
||||
result = check(sp_blocking_write(port, &sd, size, timeout));
|
||||
|
||||
check(sp_close(port));
|
||||
sp_free_port(port);
|
||||
}
|
||||
|
||||
/* Helper function for error handling. */
|
||||
int check(enum sp_return result)
|
||||
{
|
||||
@@ -97,3 +32,209 @@ int check(enum sp_return result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int WaitForEventOnPort(struct sp_port* port, int event)
|
||||
{
|
||||
int retval;
|
||||
struct sp_event_set* eventSet = NULL;
|
||||
|
||||
retval = sp_new_event_set(&eventSet);
|
||||
if (retval == SP_OK)
|
||||
{
|
||||
retval = sp_add_port_events(eventSet, port, event);
|
||||
if (retval == SP_OK)
|
||||
{
|
||||
printf("set event on port\n");
|
||||
retval = sp_wait(eventSet, 5000);
|
||||
}
|
||||
else
|
||||
{
|
||||
puts("Unable to add events to port.");
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
puts("Unable to create new event set.");
|
||||
retval = -1;
|
||||
}
|
||||
sp_free_event_set(eventSet);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// the input event waiting and flushing is the right way to do this
|
||||
// most of the time i'm just "bit blasting" and the only receiving
|
||||
// happens initially to get the number of lights
|
||||
int ReadFromPort(struct sp_port* port, int* numlights)
|
||||
{
|
||||
int count = 0;
|
||||
int bytesWaiting;
|
||||
char buf[256];
|
||||
int retval = 0;
|
||||
int i;
|
||||
|
||||
sp_flush(port, SP_BUF_INPUT);
|
||||
|
||||
while (count < 4)
|
||||
{
|
||||
printf("Attempting to retrieve num lights from port...\n");
|
||||
|
||||
size_t bufsize1 = 11;
|
||||
size_t recv_bufsize1 = 5;
|
||||
char recv_buf1[recv_bufsize1];
|
||||
char bytes1[bufsize1];
|
||||
|
||||
for(int j = 0; j < bufsize1; j++)
|
||||
{
|
||||
bytes1[j] = 0x00;
|
||||
}
|
||||
bytes1[0] = 0xff;
|
||||
bytes1[1] = 0xff;
|
||||
bytes1[2] = 0xff;
|
||||
bytes1[3] = 0xff;
|
||||
bytes1[4] = 0xff;
|
||||
bytes1[5] = 0xff;
|
||||
bytes1[6] = 0x6c;
|
||||
bytes1[7] = 0x65;
|
||||
bytes1[8] = 0x64;
|
||||
bytes1[9] = 0x73;
|
||||
bytes1[10] = 0x63;
|
||||
|
||||
int result = 0;
|
||||
unsigned int timeout = 6000;
|
||||
printf("Sending message to get num lights\n");
|
||||
WaitForEventOnPort(port, 6);
|
||||
|
||||
result = check(sp_blocking_write(port, &bytes1, bufsize1, timeout));
|
||||
|
||||
printf("Attempting to receive response\n");
|
||||
|
||||
|
||||
WaitForEventOnPort(port, 5);
|
||||
bytesWaiting = sp_input_waiting(port);
|
||||
if (bytesWaiting > 0)
|
||||
{
|
||||
memset(buf, 0, sizeof(buf));
|
||||
//printf("bytes found on port\n");
|
||||
retval = sp_blocking_read(port, buf, sizeof(buf)-1, 10);
|
||||
if (retval < 0)
|
||||
{
|
||||
printf("Error reading from serial port: %d\r\n", retval);
|
||||
retval = -1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0; i<retval; i++)
|
||||
{
|
||||
printf("%c", buf[i]);
|
||||
if (buf[i] == 13)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
int ret = atoi(buf);
|
||||
*numlights = ret;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (bytesWaiting < 0)
|
||||
{
|
||||
printf("Error getting bytes available from serial port: %d\r\n", bytesWaiting);
|
||||
retval = -1;
|
||||
break;
|
||||
}
|
||||
printf("didn't get nothing\n");
|
||||
//count++;
|
||||
retval = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
char* port_name = "/dev/ttyACM0";
|
||||
|
||||
/* The ports we will use. */
|
||||
struct sp_port* port;
|
||||
|
||||
/* Open and configure each port. */
|
||||
printf("Looking for port %s.\n", port_name);
|
||||
check(sp_get_port_by_name(port_name, &port));
|
||||
printf("Using %s\r\n", sp_get_port_name(port));
|
||||
printf("Opening port.\n");
|
||||
check(sp_open(port, SP_MODE_READ | SP_MODE_WRITE));
|
||||
|
||||
printf("Setting port to 115200 8N1, no flow control.\n");
|
||||
check(sp_set_baudrate(port, 115200));
|
||||
check(sp_set_bits(port, 8));
|
||||
check(sp_set_parity(port, SP_PARITY_NONE));
|
||||
check(sp_set_stopbits(port, 1));
|
||||
check(sp_set_flowcontrol(port, SP_FLOWCONTROL_NONE));
|
||||
check(sp_set_rts(port, 1));
|
||||
check(sp_set_dtr(port, 1));
|
||||
|
||||
ShiftLightsData sd;
|
||||
|
||||
int result = 0;
|
||||
int numlights = 0;
|
||||
result = ReadFromPort(port, &numlights);
|
||||
|
||||
int timeout = 2000;
|
||||
size_t bufsize = (numlights * 3) + 14;
|
||||
char bytes[bufsize];
|
||||
for(int j = 0; j < bufsize; j++)
|
||||
{
|
||||
bytes[j] = 0x00;
|
||||
}
|
||||
bytes[0] = 0xff;
|
||||
bytes[1] = 0xff;
|
||||
bytes[2] = 0xff;
|
||||
bytes[3] = 0xff;
|
||||
bytes[4] = 0xff;
|
||||
bytes[5] = 0xff;
|
||||
bytes[6] = 0x73;
|
||||
bytes[7] = 0x6c;
|
||||
bytes[8] = 0x65;
|
||||
bytes[9] = 0x64;
|
||||
bytes[10] = 0x73;
|
||||
bytes[bufsize-1] = 0xfd;
|
||||
bytes[bufsize-2] = 0xfe;
|
||||
bytes[bufsize-3] = 0xff;
|
||||
|
||||
|
||||
for( int i = 0; i < numlights; i++)
|
||||
{
|
||||
bytes[(i * 3) + 11 + 1] = 0xff;
|
||||
|
||||
/* Send data. */
|
||||
result = check(sp_blocking_write(port, &bytes, bufsize, timeout));
|
||||
|
||||
/* Check whether we sent all of the data. */
|
||||
if (result == bufsize)
|
||||
{
|
||||
printf("Sent %d bytes successfully, %i lit leds.\n", bufsize, numlights);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Timed out, %d/%d bytes sent.\n", result, bufsize);
|
||||
}
|
||||
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
for( int i = 0; i < numlights; i++)
|
||||
{
|
||||
bytes[(i * 3) + 11 + 1] = 0x00;
|
||||
}
|
||||
result = check(sp_blocking_write(port, &bytes, bufsize, timeout));
|
||||
|
||||
check(sp_close(port));
|
||||
sp_free_port(port);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user