Compare commits

..
19 Commits
Author SHA1 Message Date
Paul Dino Jones 6d4567facf Only add gui subdirectory on gui builds 2026-06-25 19:35:09 -04:00
Paul Dino Jones 7f52462b68 Add mgui when building gui. Compile as PIE. Add nappgui submodule 2026-06-25 16:28:10 -04:00
Paul Dino Jones 945a04ee66 Add mgui when building gui 2026-06-25 16:24:05 -04:00
Paul Dino Jones 4a30a9735e Add targets for library, cli and gui components 2026-06-25 13:27:19 -04:00
Paul Dino Jones 27b7da8c89 disable arch builds for now 2026-06-24 16:16:27 -04:00
Paul Dino Jones 78cc80064a Fix issue with new haptic code on usb devices and consolidate some function calls 2026-06-23 20:07:53 -04:00
Paul Dino Jones 8eb433f01e Refactor haptic code and devices that rely on it, to more easily allow devices to use the haptic attributes 2026-06-23 13:29:49 -04:00
Paul Dino Jones c4fa9e4138 custom nspawn script for arch build 2026-06-22 13:09:50 -04:00
Paul Dino Jones a9f49d91b9 update to use parent arch pkgbuild workflow action 2026-06-22 12:54:14 -04:00
Paul Dino Jones 87818b6a22 specify correct arch build action 2026-06-22 12:44:31 -04:00
Paul Dino Jones 17dcdcde23 fix path to PKGBUILD 2026-06-22 12:34:38 -04:00
Paul Dino Jones 5c0f871415 Update path to PKGBUILD 2026-06-22 12:32:47 -04:00
Paul Dino Jones 44b9dce139 Add arch build to CI 2026-06-22 12:27:52 -04:00
Paul Dino Jones a776085b76 Add arch build to CI 2026-06-22 12:25:49 -04:00
Paul Dino Jones 0d30170de0 Set buffer size to 64 bytes for simnet pedals. Send 0 for frequency and amplitude when no effect is playing 2026-06-11 18:28:21 -04:00
Paul Dino Jones 2aee847d7c update to latest simapi for ac evo 2026-06-09 13:05:59 -04:00
Paul Dino Jones 9712396c6f Add initial support for simnet pedals 2026-06-01 16:00:13 -04:00
Paul Dino Jones 6a36c2825f further fix return codes on serial devices 2026-05-29 18:21:52 -04:00
Paul Dino Jones 2b787cba00 cleanup the way errors are returned for arduino type devices 2026-05-29 14:28:24 -04:00
37 changed files with 1525 additions and 392 deletions
+18
View File
@@ -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[@]}"
+20
View File
@@ -79,3 +79,23 @@ jobs:
with:
files: monocoque-${{ matrix.os }}.rpm
#arch-build:
# runs-on: ubuntu-latest
# container:
# image: archlinux
# options: --privileged
# steps:
# - uses: actions/checkout@v3
# - name: Set proper repository url in PKGBUILD
# run: sed -i "s|%URL%|${{ github.server_url }}/${{ github.repository }}|" $GITHUB_WORKSPACE/tools/distro/arch/git/PKGBUILD
# - run: echo "$GITHUB_WORKSPACE/.github/bin" >> "$GITHUB_PATH"
# - name: Build Arch Linux package
# uses: FFY00/build-arch-package@v1
# with:
# BUILD_SCRIPT: extra-x86_64-build
# PKGBUILD: $GITHUB_WORKSPACE/tools/distro/arch/git/PKGBUILD
# OUTDIR: $HOME/arch-packages
# - name: Release the Package
# uses: softprops/action-gh-release@v1
# with:
# files: $HOME/arch-packages/monocoque*.zst
+3
View File
@@ -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
+22 -2
View File
@@ -10,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)
@@ -50,7 +53,17 @@ endif()
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(BUILD_SHARED)
add_library(monocoque SHARED src/monocoque/monocoque.c)
else()
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()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBPROCPS libprocps)
@@ -75,8 +88,15 @@ endif()
message("Using pulseaudio backend...")
add_compile_definitions(USE_PULSEAUDIO=true)
target_link_libraries(monocoque m hidapi-hidraw pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir Lua::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)
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})
add_subdirectory(src/monocoque/mgui)
endif()
add_subdirectory(src/monocoque/gameloop)
add_subdirectory(src/monocoque/simulatorapi)
+4 -2
View File
@@ -13,8 +13,6 @@ set(devices_source_files
tachdevice.c
wheeldevice.h
wheeldevice.c
usbhapticdevice.h
usbhapticdevice.c
hapticeffect.h
hapticeffect.c
sound.h
@@ -25,6 +23,8 @@ set(devices_source_files
usb/cslelitev3.c
usb/simagicp1000.h
usb/simagicp1000.c
usb/simnetpedals.h
usb/simnetpedals.c
usb/wheels/logitechg29.h
usb/wheels/logitechg29.c
usb/wheels/cammusc5.h
@@ -49,3 +49,5 @@ set(devices_source_files
include_directories("." "usb" "sound" "serial")
add_library(devices STATIC ${devices_source_files})
set_property(TARGET devices PROPERTY POSITION_INDEPENDENT_CODE ON)
+62 -4
View File
@@ -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"
@@ -194,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;
@@ -212,7 +270,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
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);
//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)
{
@@ -246,7 +304,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
case EFFECT_SUSPENSION:
break;
default:
slogd("Unknown effect type");
slogw("Unknown effect type %i", effecttype);
}
if(simdata->Yvelocity <= 0)
{
+34 -3
View File
@@ -2,21 +2,52 @@
#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);
+6 -7
View File
@@ -128,21 +128,20 @@ int GetNumberOfLeds(SerialDevice* serialdevice, int* numlights)
int arduino_init(SerialDevice* serialdevice, const char* portdev)
{
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
return serialdevice->id;
int id = monocoque_serial_open(serialdevice, portdev);
if (id < 0) return id;
serialdevice->id = id;
return 0;
}
int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const char* luafile, bool uselights)
{
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
int error = arduino_init(serialdevice, portdev);
int numlights = 0;
monocoque_serial_device serialdev = monocoque_serial_devices[serialdevice->id];
int error = 0;
if(uselights == true)
{
error = GetNumberOfLeds(serialdevice, &numlights);
@@ -179,7 +178,7 @@ int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const c
slogi("LUA config setup successful.");
return serialdevice->id;
return 0;
}
+10 -26
View File
@@ -145,7 +145,7 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
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;
@@ -155,9 +155,9 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
}
uint8_t effectspeed = ceil(255 * play);
uint8_t 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)
@@ -173,7 +173,7 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
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, 3, rplay, serialdevice->ampfactor);
}
serialdevice->state = play;
serialdevice->hapticstate = play;
}
size_t size = sizeof(SimHapticData);
@@ -197,7 +197,7 @@ int serialdev_free(SimDevice* this)
serialdevice->u.simhapticdata.motor3 = 1;
serialdevice->u.simhapticdata.effect4 = 0;
serialdevice->u.simhapticdata.motor4 = 1;
serialdevice->state = 0;
serialdevice->hapticstate = 0;
size_t size = sizeof(SimHapticData);
monocoque_serial_write_block(serialdevice->id, &serialdevice->u.simhapticdata, size, 9000);
@@ -261,10 +261,6 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds, SimInfo* simi
{
free(serialdevice->m.device_specific_config_file);
}
if(error > 0)
{
error = 0;
}
break;
case ARDUINODEV__CUSTOM:
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
@@ -273,24 +269,12 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds, SimInfo* simi
{
free(serialdevice->m.device_specific_config_file);
}
if(error > 0)
{
error = 0;
}
break;
case ARDUINODEV__SIMLED:
error = arduino_custom_init(serialdevice, ds->serialdevsettings.portdev, NULL, false);
if(error > 0)
{
error = 0;
}
break;
default:
error = arduino_init(serialdevice, ds->serialdevsettings.portdev);
if(error > 0)
{
error = 0;
}
break;
}
@@ -372,7 +356,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
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.");
@@ -404,10 +388,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
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;
+10 -8
View File
@@ -67,7 +67,7 @@ typedef struct
int baudrate;
double ampfactor;
double fanpower;
double state;
double hapticstate;
union
{
SimWindData simwinddata;
@@ -88,10 +88,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
/********* 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;
@@ -100,12 +100,14 @@ typedef struct
SimDevice m;
int id;
hid_device* handle;
FILE* filehandle;
char* dev;
double hapticstate;
USBType type;
union
{
TachDevice tachdevice;
WheelDevice wheeldevice;
USBGenericHapticDevice hapticdevice;
} u;
}
USBDevice;
@@ -122,7 +124,6 @@ typedef struct
SimDevice m;
int id;
int configcheck;
SoundEffectModulationType modulationType;
SoundData sounddata;
//#ifdef USE_PULSEAUDIO
pa_stream *stream;
@@ -154,7 +155,8 @@ int simdevfree(SimDevice* this);
/****** USB SubTypes ****************/
int wheeldev_update(USBDevice* usbdevice, SimData* simdata);
int wheelhapticdev_update(SimDevice* this, SimData* simdata);
int wheeldev_update(SimDevice* this, SimData* simdata);
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds);
int wheeldev_free(USBDevice* usbdevice);
+37 -87
View File
@@ -15,13 +15,15 @@
#include "../helper/parameters.h"
#include "../slog/slog.h"
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
int gear_sound_set(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
{
//sounddevice->sounddata.gear_sound_data = 3.14;
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
sounddevice->sounddata.curr_duration = 0;
}
sounddevice->sounddata.last_gear = simdata->gear;
@@ -30,27 +32,29 @@ int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
}
double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulationType modulation)
double modulate(SimDevice* this, double raw_effect, HapticEffectModulationType modulation)
{
SoundDevice* sounddevice = (void *) this->derived;
double modulated_effect = raw_effect;
switch (modulation)
{
case SOUND_EFFECT_MODULATION_FREQUENCY:
modulated_effect = ((sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect) + sounddevice->sounddata.frequency;
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 = sounddevice->sounddata.amplitude;
slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, sounddevice->sounddata.frequency);
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, this->hapticeffect.basefrequency);
break;
case SOUND_EFFECT_MODULATION_AMPLIFY:
modulated_effect = ((sounddevice->sounddata.amplitudeMax - sounddevice->sounddata.amplitude) * raw_effect) + sounddevice->sounddata.amplitude;
case HAPTIC_EFFECT_MODULATION_AMPLIFY:
modulated_effect = ((this->hapticeffect.amplitudeMax - this->hapticeffect.baseamplitude) * raw_effect) + this->hapticeffect.baseamplitude;
sounddevice->sounddata.curr_amplitude = modulated_effect;
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, sounddevice->sounddata.amplitude);
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, this->hapticeffect.baseamplitude);
break;
case SOUND_EFFECT_MODULATION_NONE:
case HAPTIC_EFFECT_MODULATION_NONE:
default:
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
break;
}
@@ -64,19 +68,19 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60);
slogt("Set base effect of %f from rpms of %i", effect, simdata->rpms);
modulate(sounddevice, effect, sounddevice->modulationType);
modulate(this, effect, this->hapticeffect.modulationType);
}
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original tyre slip effect %f", effect);
double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original %i tyre slip effect %f", this->hapticeffect.effecttype, effect);
if (effect > 0)
{
modulate(sounddevice, effect, sounddevice->modulationType);
modulate(this, effect, this->hapticeffect.modulationType);
}
else
{
@@ -91,12 +95,12 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original tyre lock effect %f", play);
if (play > 0)
{
modulate(sounddevice, play, sounddevice->modulationType);
modulate(this, play, this->hapticeffect.modulationType);
}
else
{
@@ -109,12 +113,12 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original abs effect %f", play);
if (play > 0)
{
modulate(sounddevice, play, sounddevice->modulationType);
modulate(this, play, this->hapticeffect.modulationType);
}
else
{
@@ -128,13 +132,13 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
effect = effect * 10;
slogt("Updating sound device output from original suspension travel effect %f", effect);
if (effect > 0)
{
effect = modulate(sounddevice, effect, sounddevice->modulationType);
effect = modulate(this, effect, this->hapticeffect.modulationType);
}
else
{
@@ -147,9 +151,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
gear_sound_set(sounddevice, simdata);
gear_sound_set(this, simdata);
}
@@ -163,28 +165,17 @@ int sounddev_free(SimDevice* this)
return 0;
}
int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreIdentifier tyre, SoundDeviceSettings sds)
int sounddev_init(SoundDevice* sounddevice, const char* devname, SoundDeviceSettings sds)
{
slogi("initializing standalone sound device...");
slogi("volume is: %i", sds.volume);
slogi("Modulation type: %i", sds.modulation);
slogi("frequency is: %i", sds.frequency);
slogi("frequency Max is: %i", sds.frequencyMax);
slogi("amplitude is: %i", sds.amplitude);
slogi("amplitude Max is: %i", sds.amplitudeMax);
slogi("pan is: %i", sds.pan);
slogi("channels is: %i", sds.channels);
slogi("duration is: %f", sds.duration);
slogi("noise is: %i", sds.noise);
sounddevice->modulationType = sds.modulation;
sounddevice->sounddata.frequency = sds.frequency;
sounddevice->sounddata.frequencyMax = sds.frequencyMax;
sounddevice->sounddata.amplitude = sds.amplitude;
sounddevice->sounddata.amplitudeMax = sds.amplitudeMax;
sounddevice->sounddata.noise = (double)sds.noise;
sounddevice->sounddata.curr_duration = 0;
@@ -240,7 +231,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
this->m.derived = this;
int error = 0;
switch (ds->effect_type)
switch (ds->hapticsettings.effect_type)
{
case (EFFECT_TYRESLIP):
case (EFFECT_TYRELOCK):
@@ -258,73 +249,32 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
if(error == 0)
{
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type);
switch (ds->effect_type)
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.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;
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.");
slogi("Initializing sound device for tyre lock vibrations.");
break;
case (EFFECT_ABSBRAKES):
this->m.hapticeffect.effecttype = EFFECT_ABSBRAKES;
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.threshold = ds->threshold;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
this->m.vtable = &absbrakes_sound_simdevice_vtable;
slogi("Initializing sound device for abs vibrations.");
break;
case (EFFECT_SUSPENSION):
this->m.hapticeffect.effecttype = EFFECT_SUSPENSION;
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.threshold = ds->threshold;
slogt("Haptic effect: %i %i on tyre %i", this->m.hapticeffect.effecttype, ds->effect_type, ds->tyre);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
this->m.vtable = &suspension_sound_simdevice_vtable;
slogi("Initializing sound device for suspension vibrations.");
break;
@@ -334,7 +284,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
if(error == 0)
{
slogt("Attempting to use sound device %s", ds->sounddevsettings.dev);
error = sounddev_init(this, ds->sounddevsettings.dev, ds->tyre, ds->sounddevsettings);
error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings);
}
if (error != 0)
-12
View File
@@ -8,23 +8,11 @@
//#endif
typedef enum
{
SOUND_EFFECT_MODULATION_NONE = 0,
SOUND_EFFECT_MODULATION_FREQUENCY = 1,
SOUND_EFFECT_MODULATION_AMPLIFY = 2,
}
SoundEffectModulationType;
#define MAX_TABLE_SIZE (6000)
typedef struct
{
uint8_t last_gear;
int volume;
uint32_t frequency;
uint32_t frequencyMax;
uint32_t amplitude;
uint32_t amplitudeMax;
double duration;
double curr_frequency;
uint32_t curr_amplitude;
+12 -13
View File
@@ -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;
+6 -3
View File
@@ -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
+17 -17
View File
@@ -3,7 +3,7 @@
#include <string.h>
#include <hidapi/hidapi.h>
#include "usbhapticdevice.h"
#include "simagicp1000.h"
#include "../../helper/confighelper.h"
#include "../slog/slog.h"
@@ -14,12 +14,12 @@
const size_t SIMAGIC_P1000_BUFSIZE = 49;
const char* SIMAGICP1000DEVSTRING = "SIMAGIC P1000 Pedals";
int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, size_t bufsize)
int senddevreport(USBDevice* usbdevice, unsigned char* buf, size_t bufsize)
{
int res = 0;
if (usbhapticdevice->handle)
if (usbdevice->handle)
{
res = hid_send_feature_report(usbhapticdevice->handle, buf, SIMAGIC_P1000_BUFSIZE);
res = hid_send_feature_report(usbdevice->handle, buf, SIMAGIC_P1000_BUFSIZE);
slogd("sent %i bytes to %s", bufsize, SIMAGICP1000DEVSTRING);
slogt("sent bytes %02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
}
@@ -30,7 +30,7 @@ int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, s
return res != bufsize;
}
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play)
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play)
{
int res = 0;
@@ -54,17 +54,17 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
{
case (EFFECT_TYRESLIP):
bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break;
case (EFFECT_TYRELOCK):
bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break;
case (EFFECT_ABSBRAKES):
bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break;
}
}
@@ -72,19 +72,19 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
{
bytes[0] = 241;
bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
}
return res;
}
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
int simagicp1000_free(USBDevice* usbdevice)
{
int res = 0;
hid_close(usbhapticdevice->handle);
hid_close(usbdevice->handle);
res = hid_exit();
return res;
@@ -92,7 +92,7 @@ int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
return res;
}
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
int simagicp1000_init(USBDevice* usbdevice)
{
slogi("initializing %s...", SIMAGICP1000DEVSTRING);
@@ -100,9 +100,9 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
res = hid_init();
usbhapticdevice->handle = hid_open(SIMAGIC_VENDOR_ID, SIMAGIC_PRODUCT_ID_P1000, NULL);
usbdevice->handle = hid_open(SIMAGIC_VENDOR_ID, SIMAGIC_PRODUCT_ID_P1000, NULL);
if (!usbhapticdevice->handle)
if (!usbdevice->handle)
{
sloge("Could not find attached %s", SIMAGICP1000DEVSTRING);
res = hid_exit();
@@ -123,7 +123,7 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
bytes[5] = 0x00;
bytes[6] = 0x01;
bytes[7] = 0x02;
res = senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
res = senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
slogd("Initialization returned %i", res);
if(res != 0)
{
+6 -3
View File
@@ -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
+90
View File
@@ -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;
}
+11
View File
@@ -0,0 +1,11 @@
#ifndef _SIMNETPEDALS_H
#define _SIMNETPEDALS_H
#include "../wheeldevice.h"
#include "../simdevice.h"
int simnetpedals_update(USBDevice* usbdevice, int effecttype, int play, int motorposition, int frequency, int amplitude);
int simnetpedals_init(USBDevice* usbdevice);
int simnetpedals_free(USBDevice* usbdevice);
#endif
@@ -2,7 +2,6 @@
#define _CAMMUSC12_H
#include "../../wheeldevice.h"
#include "../../simdevice.h"
int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
+27 -29
View File
@@ -19,11 +19,9 @@ int usbdev_update(SimDevice* this, SimData* simdata)
case USBDEV_TACHOMETER :
tachdev_update(usbdevice, simdata);
break;
case USBDEV_WHEEL :
wheeldev_update(usbdevice, simdata);
break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
case USBDEV_WHEEL_OR_PEDALS :
// this should be directed via vtable to wheeldevice.c
//wheeldev_update(usbdevice, simdata);
break;
}
@@ -41,12 +39,9 @@ int usbdev_free(SimDevice* this)
case USBDEV_TACHOMETER :
tachdev_free(usbdevice);
break;
case USBDEV_WHEEL :
case USBDEV_WHEEL_OR_PEDALS :
wheeldev_free(usbdevice);
break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_free(&usbdevice->u.hapticdevice);
break;
}
free(usbdevice);
@@ -66,53 +61,56 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds, SimInfo* siminfo)
case USBDEV_TACHOMETER :
error = tachdev_init(usbdevice, ds);
break;
case USBDEV_WHEEL :
case USBDEV_WHEEL_OR_PEDALS :
error = wheeldev_init(usbdevice, ds);
break;
case USBDEV_GENERICHAPTIC :
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds, siminfo);
break;
}
return error;
}
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, siminfo);
error = usbdev_init(this, ds, siminfo);
if (error != 0)
{
+20 -24
View File
@@ -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,6 +69,9 @@ int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
case USBHAPTIC_SIMAGICP1000PEDALS:
simagicp1000_free(usbhapticdevice);
break;
case USBHAPTIC_SIMNETPEDALS:
simnetpedals_free(usbhapticdevice);
break;
}
return 0;
@@ -76,25 +86,7 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
}
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(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;
}
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
slogi("initializing standalone usb haptic device...");
// detection of usb device model
@@ -107,6 +99,10 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
usbhapticdevice->type = USBHAPTIC_CSLELITEV3PEDALS;
error = cslelitev3_init(usbhapticdevice);
break;
case (SIMDEVSUBTYPE_SIMNETPEDALS):
usbhapticdevice->type = USBHAPTIC_SIMNETPEDALS;
error = simnetpedals_init(usbhapticdevice);
break;
default:
slogw("Possibly unknown device");
}
+2 -7
View File
@@ -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;
+80 -7
View File
@@ -2,20 +2,73 @@
#include <stdlib.h>
#include <string.h>
#include "usb/wheels/logitechg29.h"
#include "usb/wheels/cammusc5.h"
#include "usb/wheels/cammusc12.h"
#include "usb/wheels/gtneo.h"
#include "serial/moza.h"
#include "usb/cslelitev3.h"
#include "usb/simagicp1000.h"
#include "usb/simnetpedals.h"
#include "simdevice.h"
#include "../helper/confighelper.h"
#include "../simulatorapi/simapi/simapi/simdata.h"
#include "../slog/slog.h"
int wheeldev_update(USBDevice* usbdevice, SimData* simdata)
int wheelhapticdev_update(SimDevice* this, SimData* simdata)
{
USBDevice* usbdevice = (void *) this->derived;
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
if (play != usbdevice->hapticstate)
{
int rplay = 0;
if(play > 0)
{
rplay = 1;
switch ( wheeldevice->type )
{
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_update(usbdevice, this->hapticeffect.effecttype, rplay, this->hapticeffect.motorposition, this->hapticeffect.basefrequency, this->hapticeffect.baseamplitude);
break;
}
}
else
{
switch ( wheeldevice->type )
{
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_update(usbdevice, this->hapticeffect.effecttype, rplay, this->hapticeffect.motorposition, 0, 0);
break;
}
}
usbdevice->hapticstate = play;
}
return 0;
}
int wheeldev_update(SimDevice* this, SimData* simdata)
{
USBDevice* usbdevice = (void *) this->derived;
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
switch ( wheeldevice->type )
{
case WHEELDEV_UNKNOWN :
@@ -72,6 +125,15 @@ int wheeldev_free(USBDevice* usbdevice)
free(usbdevice->m.device_specific_config_file);
}
break;
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_free(usbdevice);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_free(usbdevice);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_free(usbdevice);
break;
}
return 0;
@@ -79,8 +141,9 @@ int wheeldev_free(USBDevice* usbdevice)
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
{
slogi("initializing wheel device...");
slogi("initializing wheel or pedals device...");
int error = 0;
usbdevice->hapticstate = 0;
// detection of wheel model
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
switch (ds->dev_subsubtype) {
@@ -138,11 +201,21 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
error = -1;
}
break;
default:
wheeldevice->type = WHEELDEV_UNKNOWN;
slogw("Unknown cammus wheel detected, trying C5");
error = cammusc5_init(usbdevice);
case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS):
wheeldevice->type = WHEELDEV_SIMAGICP1000PEDALS;
error = simagicp1000_init(usbdevice);
break;
case (SIMDEVSUBTYPE_CSLELITEV3PEDALS):
slogi("Attempting to initialize CSL Elite V3 Pedals");
wheeldevice->type = WHEELDEV_CSLELITEV3PEDALS;
error = cslelitev3_init(usbdevice);
break;
case (SIMDEVSUBTYPE_SIMNETPEDALS):
wheeldevice->type = WHEELDEV_SIMNETPEDALS;
error = simnetpedals_init(usbdevice);
break;
default:
slogw("Possibly unknown wheel device");
}
+9 -6
View File
@@ -8,12 +8,15 @@
typedef enum
{
WHEELDEV_UNKNOWN = 0,
WHEELDEV_CAMMUSC5 = 1,
WHEELDEV_CAMMUSC12 = 2,
WHEELDEV_MOZAR5 = 3,
WHEELDEV_SIMAGICGTNEO = 4,
WHEELDEV_LOGITECHG29 = 5
WHEELDEV_UNKNOWN = 0,
WHEELDEV_CAMMUSC5 = 1,
WHEELDEV_CAMMUSC12 = 2,
WHEELDEV_MOZAR5 = 3,
WHEELDEV_SIMAGICGTNEO = 4,
WHEELDEV_LOGITECHG29 = 5,
WHEELDEV_CSLELITEV3PEDALS = 6,
WHEELDEV_SIMAGICP1000PEDALS = 7,
WHEELDEV_SIMNETPEDALS = 8
}
WheelType;
+2
View File
@@ -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)
+79 -4
View File
@@ -24,6 +24,10 @@ bool go = false;
bool go2 = false;
struct sigaction act;
SimData* simdata;
SimMap* simmap;
loop_data* baton;
uv_idle_t idler;
uv_timer_t datachecktimer;
@@ -33,7 +37,7 @@ uv_timer_t tyrediametertimer;
uv_udp_t recv_socket;
bool doui = false;
int appstate = 0;
void shmdatamapcallback(uv_timer_t* handle);
void showstatscallback(uv_timer_t* handle);
@@ -628,12 +632,83 @@ void cb(uv_poll_t* handle, int status, int events)
}
int monocoque_mainloop_start(MonocoqueSettings* ms)
{
simdata = malloc(sizeof(SimData));
simmap = simapi_simmap_create();
char ch;
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->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 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);
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
return 0;
}
int monocoque_mainloop_stop(MonocoqueSettings* ms)
{
uv_stop(uv_default_loop());
//uv_walk(uv_default_loop(), close_walk_cb, NULL);
uv_loop_close(uv_default_loop());
uv_library_shutdown();
slogi("All threads stopped...");
free(baton);
free(simdata);
free(simmap);
return 0;
}
int monocoque_mainloop(MonocoqueSettings* ms)
{
SimData* simdata = malloc(sizeof(SimData));
SimMap* simmap = simapi_simmap_create();
simdata = malloc(sizeof(SimData));
simmap = simapi_simmap_create();
struct termios newsettings, canonicalmode;
tcgetattr(0, &canonicalmode);
@@ -647,7 +722,7 @@ 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;
+4
View File
@@ -1,7 +1,11 @@
#include "../devices/simdevice.h"
#include "../helper/parameters.h"
extern int appstate;
int tester(SimDevice* devices, int numdevices);
int looper(SimDevice* devices, int numdevices, Parameters* p);
int monocoque_mainloop(MonocoqueSettings* ms);
int monocoque_mainloop_start(MonocoqueSettings* ms);
int monocoque_mainloop_stop(MonocoqueSettings* ms);
+2
View File
@@ -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)
+141 -114
View File
@@ -37,35 +37,35 @@ int strtoeffecttype(const char* effect, DeviceSettings* ds)
if (strcicmp(effect, "Engine") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_ENGINERPM;
ds->hapticsettings.effect_type = EFFECT_ENGINERPM;
}
if (strcicmp(effect, "Gear") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_GEARSHIFT;
ds->hapticsettings.effect_type = EFFECT_GEARSHIFT;
}
if (strcicmp(effect, "Suspension") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_SUSPENSION;
ds->hapticsettings.effect_type = EFFECT_SUSPENSION;
}
if (strcicmp(effect, "ABS") == 0)
{
ds->is_valid = true;
slogt("found abas effect set");
ds->effect_type = EFFECT_ABSBRAKES;
ds->hapticsettings.effect_type = EFFECT_ABSBRAKES;
}
if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0))
{
ds->is_valid = true;
slogt("found tyreslip effect set");
ds->effect_type = EFFECT_TYRESLIP;
ds->hapticsettings.effect_type = EFFECT_TYRESLIP;
}
if ((strcicmp(effect, "LOCK") == 0) || (strcicmp(effect, "TYRELOCK") == 0) || (strcicmp(effect, "TIRELOCK") == 0))
{
ds->is_valid = true;
slogt("found tyreslock effect set");
ds->effect_type = EFFECT_TYRELOCK;
ds->hapticsettings.effect_type = EFFECT_TYRELOCK;
}
if (ds->is_valid == false)
@@ -128,6 +128,11 @@ int strtodevsubsubtype(const char* device_subsubtype, DeviceSettings* ds)
ds->dev_subsubtype = SIMDEVSUBTYPE_CSLELITEV3PEDALS;
devfound = true;
}
if (strcicmp(device_subsubtype, "SIMNETPEDALS") == 0)
{
ds->dev_subsubtype = SIMDEVSUBTYPE_SIMNETPEDALS;
devfound = true;
}
if (strcicmp(device_subsubtype, "SIMAGICP1000PEDALS") == 0)
{
ds->dev_subsubtype = SIMDEVSUBTYPE_SIMAGICP1000PEDALS;
@@ -586,31 +591,31 @@ int gettyre(config_setting_t* device_settings, DeviceSettings* ds) {
const char* temp;
int found = config_setting_lookup_string(device_settings, "tyre", &temp);
ds->tyre = ALLFOUR;
ds->hapticsettings.tyre = ALLFOUR;
if (strcicmp(temp, "FRONTS") == 0)
{
ds->tyre = FRONTS;
ds->hapticsettings.tyre = FRONTS;
}
if (strcicmp(temp, "REARS") == 0)
{
ds->tyre = REARS;
ds->hapticsettings.tyre = REARS;
}
if (strcicmp(temp, "FRONTLEFT") == 0)
{
ds->tyre = FRONTLEFT;
ds->hapticsettings.tyre = FRONTLEFT;
}
if (strcicmp(temp, "FRONTRIGHT") == 0)
{
ds->tyre = FRONTRIGHT;
ds->hapticsettings.tyre = FRONTRIGHT;
}
if (strcicmp(temp, "REARLEFT") == 0)
{
ds->tyre = REARLEFT;
ds->hapticsettings.tyre = REARLEFT;
}
if (strcicmp(temp, "REARRIGHT") == 0)
{
ds->tyre = REARRIGHT;
ds->hapticsettings.tyre = REARRIGHT;
}
}
@@ -720,110 +725,15 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
}
}
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_subtype == SIMDEVTYPE_USBWHEEL || ds->dev_subtype == SIMDEVTYPE_SERIALWHEEL)
if (ds->dev_type == SIMDEV_USB)
{
// logic for different devices
int b = 0;
const char* temp;
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
if(temp != NULL && found > 0)
if (device_settings != NULL)
{
b = strtodevsubsubtype(temp, ds);
}
}
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
{
slogt("analysing haptic effect settings");
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES || ds->effect_type == EFFECT_SUSPENSION )
{
gettyre(device_settings, ds);
ds->threshold = 0;
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
}
if (ds->dev_type == SIMDEV_SOUND)
{
slogi("reading configured sound device settings");
ds->sounddevsettings.frequency = 0;
ds->sounddevsettings.frequencyMax = 0;
ds->sounddevsettings.amplitude = 50;
ds->sounddevsettings.amplitudeMax = 50;
ds->sounddevsettings.volume = 0;
ds->sounddevsettings.pan = 0;
ds->sounddevsettings.channels = 1;
ds->sounddevsettings.duration = 2.0;
ds->sounddevsettings.noise = 0;
if (ds->effect_type == EFFECT_GEARSHIFT)
const char* temp;
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
if(temp != NULL && found > 0)
{
ds->sounddevsettings.duration = .125;
}
if (device_settings != NULL)
{
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency);
config_setting_lookup_int(device_settings, "frequencyMax", &ds->sounddevsettings.frequencyMax);
config_setting_lookup_int(device_settings, "amplitude", &ds->sounddevsettings.amplitude);
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->sounddevsettings.amplitudeMax);
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise);
const char* temp = NULL;
int found = 0;
found = config_setting_lookup_string(device_settings, "devid", &temp);
if (found == CONFIG_FALSE)
{
ds->sounddevsettings.dev = NULL;
}
else
{
if(temp != NULL)
{
ds->sounddevsettings.dev = strdup(temp);
}
}
found = config_setting_lookup_string(device_settings, "modulation", &temp);
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
if (found == 0)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
slogd("Effect modulation not found, set to none");
}
else
{
if(strcicmp(temp, "FREQUENCY") == 0)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_FREQUENCY;
if(ds->sounddevsettings.frequencyMax == 0 || ds->sounddevsettings.frequencyMax < ds->sounddevsettings.frequency)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
slogw("Falling back to no frequency modulation since frequencyMax is either not set or set below target frequency");
}
else
{
slogi("Effect modulation found, set to FREQUENCY");
}
}
else if(strcicmp(temp, "AMPLIFY") == 0)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_AMPLIFY;
slogi("Effect modulation found, set to AMPLIFY");
}
else
{
slogw("%s is not a valid modulation type, falling back to no effect modulation");
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
}
}
strtodevsubsubtype(temp, ds);
}
}
}
@@ -881,6 +791,123 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
}
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_subtype == SIMDEVTYPE_USBWHEEL || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
{
slogt("analysing haptic effect settings");
ds->has_haptic_effects = true;
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
if (ds->hapticsettings.effect_type == EFFECT_TYRESLIP || ds->hapticsettings.effect_type == EFFECT_TYRELOCK || ds->hapticsettings.effect_type == EFFECT_ABSBRAKES || ds->hapticsettings.effect_type == EFFECT_SUSPENSION )
{
gettyre(device_settings, ds);
ds->threshold = 0;
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
}
slogi("reading configured haptic effect settings");
ds->hapticsettings.frequency = 0;
ds->hapticsettings.frequencyMax = 0;
ds->hapticsettings.amplitude = 50;
ds->hapticsettings.amplitudeMax = 50;
ds->hapticsettings.volume = 0;
if (ds->hapticsettings.effect_type == EFFECT_GEARSHIFT)
{
ds->hapticsettings.duration = .125;
}
if (device_settings != NULL)
{
config_setting_lookup_int(device_settings, "volume", &ds->hapticsettings.volume);
config_setting_lookup_int(device_settings, "frequency", &ds->hapticsettings.frequency);
config_setting_lookup_int(device_settings, "frequencyMax", &ds->hapticsettings.frequencyMax);
config_setting_lookup_int(device_settings, "amplitude", &ds->hapticsettings.amplitude);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->hapticsettings.amplitudeMax);
const char* temp = NULL;
int found = 0;
found = config_setting_lookup_string(device_settings, "modulation", &temp);
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
if (found == 0)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
slogd("Effect modulation not found, set to none");
}
else
{
if(strcicmp(temp, "FREQUENCY") == 0)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_FREQUENCY;
if(ds->hapticsettings.frequencyMax == 0 || ds->hapticsettings.frequencyMax < ds->hapticsettings.frequency)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
slogw("Falling back to no frequency modulation since frequencyMax is either not set or set below target frequency");
}
else
{
slogi("Effect modulation found, set to FREQUENCY");
}
}
else if(strcicmp(temp, "AMPLIFY") == 0)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_AMPLIFY;
slogi("Effect modulation found, set to AMPLIFY");
}
else
{
slogw("%s is not a valid modulation type, falling back to no effect modulation");
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
}
}
ds->hapticsettings.motorposition = 0;
int motorposition = 1;
config_setting_lookup_int(device_settings, "motors", &motorposition);
ds->hapticsettings.motorposition = motorposition;
}
if (ds->dev_type == SIMDEV_SOUND)
{
slogi("reading configured sound device settings");
ds->sounddevsettings.volume = 0;
ds->sounddevsettings.pan = 0;
ds->sounddevsettings.channels = 1;
ds->sounddevsettings.noise = 0;
if (ds->hapticsettings.effect_type == EFFECT_GEARSHIFT)
{
ds->sounddevsettings.duration = .125;
}
if (device_settings != NULL)
{
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise);
const char* temp = NULL;
int found = 0;
found = config_setting_lookup_string(device_settings, "devid", &temp);
if (found == CONFIG_FALSE)
{
ds->sounddevsettings.dev = NULL;
}
else
{
if(temp != NULL)
{
ds->sounddevsettings.dev = strdup(temp);
}
}
}
}
}
return error;
}
+31 -12
View File
@@ -46,7 +46,8 @@ typedef enum
SIMDEVSUBTYPE_SIMAGICGTNEO = 6,
SIMDEVSUBTYPE_MOZA_NEW = 7,
SIMDEVSUBTYPE_LOGITECH_G29 = 8,
SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL = 9
SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL = 9,
SIMDEVSUBTYPE_SIMNETPEDALS = 10
}
DeviceSubSubType;
@@ -73,6 +74,14 @@ typedef enum
}
VibrationEffectType;
typedef enum
{
EFFECT_MODULATION_NONE = 0,
EFFECT_MODULATION_FREQUENCY = 1,
EFFECT_MODULATION_AMPLIFY = 2,
}
EffectModulationType;
typedef enum
{
MOTOR_1 = 0,
@@ -176,26 +185,35 @@ SerialDeviceSettings;
typedef struct
{
uint32_t frequency;
uint32_t volume;
int lowbound_frequency;
int upperbound_frequency;
uint32_t frequencyMax;
uint32_t amplitudeMax;
uint32_t amplitude;
int pan;
int channels;
double duration;
char* dev;
SoundEffectModulationType modulation;
int noise;
}
SoundDeviceSettings;
typedef struct
{
int value0;
int value1;
uint32_t frequency;
uint32_t amplitude;
uint32_t volume;
uint32_t frequencyMax;
uint32_t amplitudeMax;
double threshold;
double duration;
MotorPosition motorposition;
VibrationEffectType effect_type;
MonocoqueTyreIdentifier tyre;
EffectModulationType modulation;
}
HapticEffectSettings;
typedef struct
{
char* dev;
}
USBDeviceSettings;
@@ -207,14 +225,15 @@ typedef struct
DeviceType dev_type;
DeviceSubType dev_subtype;
DeviceSubSubType dev_subsubtype;
bool has_haptic_effects;
// to get really fancy move the effect information to it's own structure that would be a member of
// any device settings member structure that can carry an effect
VibrationEffectType effect_type;
MonocoqueTyreIdentifier tyre;
double threshold;
bool has_config;
char* specific_config_file;
// union?
HapticEffectSettings hapticsettings;
TachometerSettings tachsettings;
SerialDeviceSettings serialdevsettings;
SoundDeviceSettings sounddevsettings;
+30
View File
@@ -0,0 +1,30 @@
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 ${gui_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})
+337
View File
@@ -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);
}
+387
View File
@@ -0,0 +1,387 @@
#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/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"
#define PROGRAM_NAME "monocoque"
MonocoqueSettings* ms;
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 monocoque_main(int argc, char** argv)
{
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));
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);
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_start(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();
//}
//}
}
#include <nappgui.h>
#define NUM_BRICKS 40
Button *start_button;
Button *stop_button;
Label *game_status;
Label *simd_status;
typedef struct _app_t App;
struct _app_t
{
bool_t is_running;
Cell *button;
Slider *slider;
View *view;
Window *window;
};
/*---------------------------------------------------------------------------*/
static void i_OnStart(App *app, Event *e)
{
appstate = 0;
unref(e);
app->is_running = TRUE;
cell_enabled(app->button, FALSE);
uint32_t i;
int argc = (int)osapp_argc();
char **argv = malloc(argc * sizeof(char *));
for (i = 0; i < (uint32_t)argc; ++i)
{
char buffer[128];
osapp_argv(i, buffer, sizeof(buffer));
argv[i] = strdup(buffer); /* allocate a copy */
}
int rc = monocoque_main(argc, argv);
fprintf(stderr, "monocoque mainloop started");
/* cleanup */
for (i = 0; i < (uint32_t)argc; ++i)
free(argv[i]);
free(argv);
}
static void i_OnStop(App *app, Event *e)
{
monocoque_mainloop_stop(ms);
}
/*---------------------------------------------------------------------------*/
static Panel *i_panel(App *app)
{
Panel *panel = panel_create();
Layout *layout = layout_create(1, 4);
View *view = view_create();
Slider *slider = slider_create();
game_status = label_create();
start_button = button_push();
stop_button = button_push();
view_size(view, s2df(800, 600));
//view_OnDraw(view, listener(app, i_OnDraw, App));
//slider_OnMoved(slider, listener(app, i_OnSlider, App));
label_text(game_status, "Game: None Detected Simd: Not Detected");
button_text(start_button, "Start");
button_text(stop_button, "Stop");
button_OnClick(start_button, listener(app, i_OnStart, App));
button_OnClick(stop_button, listener(app, i_OnStop, App));
layout_view(layout, view, 0, 0);
//layout_slider(layout, slider, 0, 1);
layout_label(layout, game_status, 0, 3);
layout_button(layout, start_button, 0, 1);
layout_button(layout, stop_button, 0, 2);
layout_vexpand(layout, 0);
layout_vmargin(layout, 0, 10);
layout_vmargin(layout, 2, 10);
layout_margin(layout, 10);
panel_layout(panel, layout);
app->view = view;
app->slider = slider;
app->button = layout_cell(layout, 0, 3);
return panel;
}
/*---------------------------------------------------------------------------*/
static void i_OnClose(App *app, Event *e)
{
osapp_finish();
unref(app);
unref(e);
}
/*---------------------------------------------------------------------------*/
static App *i_create(void)
{
App *app = heap_new0(App);
Panel *panel = i_panel(app);
app->window = window_create(ekWINDOW_STDRES);
window_panel(app->window, panel);
window_origin(app->window, v2df(200, 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)
{
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(start_button, "Playing... Press to Stop");
}
if(appstate == 1)
{
button_text(start_button, "Searching for data... Press to Stop");
}
if(appstate == 0)
{
button_text(start_button, "Start");
}
label_text(game_status, "Game: (Searching) None Detected Simd: Not Detected");
}
view_update(app->view);
}
/*---------------------------------------------------------------------------*/
#include <osapp/osmain.h>
osmain_sync(.04, i_create, i_destroy, i_update, "", App)
@@ -43,3 +43,5 @@ set(simulatorapi_source_files
)
add_library(simulatorapi STATIC ${simulatorapi_source_files})
set_property(TARGET simulatorapi PROPERTY POSITION_INDEPENDENT_CODE ON)
+2
View File
@@ -4,3 +4,5 @@ set(slog_source_files
)
add_library(slog STATIC ${slog_source_files})
set_property(TARGET slog PROPERTY POSITION_INDEPENDENT_CODE ON)