Compare commits
30 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
e94208880e | |
|
|
5b17aa3e34 | |
|
|
e58e235256 | |
|
|
aac41aa882 | |
|
|
bf6eec8c26 | |
|
|
33d0b44f98 | |
|
|
34e9ba4405 | |
|
|
e29cc12ab4 | |
|
|
eb18a05c51 | |
|
|
d2e0bebc4e | |
|
|
46adafd5f0 | |
|
|
b51d570b73 | |
|
|
0e96eb27ae | |
|
|
218baed2ed | |
|
|
c44af52ad5 | |
|
|
084babb919 | |
|
|
b3067e520d | |
|
|
b4f459a539 | |
|
|
b4ca18c351 | |
|
|
67d0423997 | |
|
|
784f71b831 | |
|
|
be7d13efbc | |
|
|
208833b052 | |
|
|
edf8116872 | |
|
|
744ff916a8 | |
|
|
4d403c6955 | |
|
|
7a75c9999d | |
|
|
9860139158 | |
|
|
fe22aef0c3 | |
|
|
2fc81f24fe |
|
|
@ -1,3 +1,4 @@
|
||||||
[submodule "src/monocoque/simulatorapi/simapi"]
|
[submodule "src/monocoque/simulatorapi/simapi"]
|
||||||
path = src/monocoque/simulatorapi/simapi
|
path = src/monocoque/simulatorapi/simapi
|
||||||
url = git@github.com:spacefreak18/simapi
|
url = https://github.com/spacefreak18/simapi
|
||||||
|
# url = git@github.com:spacefreak18/simapi # ssh is better but Microsoft requires an account
|
||||||
|
|
|
||||||
|
|
@ -33,16 +33,24 @@ FIND_LIBRARY(LIBUSB_LIBRARY NAMES usb-1.0
|
||||||
set(HIDAPI_WITH_LIBUSB TRUE) # surely will be used only on Linux
|
set(HIDAPI_WITH_LIBUSB TRUE) # surely will be used only on Linux
|
||||||
set(BUILD_SHARED_LIBS TRUE) # HIDAPI as static library on all platforms
|
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 ${LIBUSB_LIBRARY} hidapi-libusb pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi)
|
||||||
|
else()
|
||||||
|
message("Using portaudio backend...")
|
||||||
|
target_link_libraries(monocoque m ${LIBUSB_LIBRARY} hidapi-libusb portaudio serialport xml2 argtable2 config gameloop helper devices slog simulatorapi)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_include_directories(monocoque PUBLIC config ${LIBUSB_INCLUDE_DIR} ${LIBXML_INCLUDE_DIR})
|
||||||
|
|
||||||
add_subdirectory(src/monocoque/gameloop)
|
add_subdirectory(src/monocoque/gameloop)
|
||||||
add_subdirectory(src/monocoque/simulatorapi)
|
add_subdirectory(src/monocoque/simulatorapi)
|
||||||
add_subdirectory(src/monocoque/helper)
|
add_subdirectory(src/monocoque/helper)
|
||||||
add_subdirectory(src/monocoque/devices)
|
add_subdirectory(src/monocoque/devices)
|
||||||
add_subdirectory(src/monocoque/slog)
|
add_subdirectory(src/monocoque/slog)
|
||||||
|
|
||||||
add_executable(monocoque src/monocoque/monocoque.c)
|
|
||||||
target_include_directories(monocoque PUBLIC config ${LIBUSB_INCLUDE_DIR} ${LIBXML_INCLUDE_DIR})
|
|
||||||
target_link_libraries(monocoque m ${LIBUSB_LIBRARY} hidapi-libusb portaudio serialport xml2 argtable2 config gameloop helper devices slog simulatorapi)
|
|
||||||
|
|
||||||
add_executable(listusb tests/testlibusb.c)
|
add_executable(listusb tests/testlibusb.c)
|
||||||
target_include_directories(listusb PUBLIC ${LIBUSB_INCLUDE_DIR})
|
target_include_directories(listusb PUBLIC ${LIBUSB_INCLUDE_DIR})
|
||||||
target_link_libraries(listusb ${LIBUSB_LIBRARY} portaudio)
|
target_link_libraries(listusb ${LIBUSB_LIBRARY} portaudio)
|
||||||
|
|
|
||||||
42
README.md
42
README.md
|
|
@ -16,18 +16,20 @@ Cross Platform device manager for driving and flight simulators, for use with co
|
||||||
- Includes utility to configure revburner tachometer
|
- 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.
|
- Can send data to any serial device. So far only tested with arduino. Includes sample arduino sketch for sim lights.
|
||||||
- The support for haptic bass shakers is limited and needs the most work. So far the engine rev is a simple sine wave, which I find convincing. The gear shift event works but not convincing enough for me.
|
- The support for haptic bass shakers is limited and needs the most work. So far the engine rev is a simple sine wave, which I find convincing. The gear shift event works but not convincing enough for me.
|
||||||
|
- Choice of Portaudio or Pulseaudio backend.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
- libserialport - arduino serial devices
|
- libserialport - arduino serial devices
|
||||||
- hidapi - usb hid devices
|
- hidapi - usb hid devices
|
||||||
- libusb - used by hidapi
|
- libusb - used by hidapi
|
||||||
- portaudio - sound devices (haptic bass shakers)
|
- portaudio - sound devices (haptic bass shakers)
|
||||||
|
- pulseaudio - sound devices (haptic bass shakers)
|
||||||
- libenet - UDP support (not yet implemented)
|
- libenet - UDP support (not yet implemented)
|
||||||
- libxml2
|
- libxml2
|
||||||
- argtable2
|
- argtable2
|
||||||
- libconfig
|
- libconfig
|
||||||
- [slog](https://github.com/kala13x/slog) (static)
|
- [slog](https://github.com/kala13x/slog) (static)
|
||||||
- [wine-linux-shm-adapter](https://github.com/spacefreak18/simshmbridge) - for sims that need shared memory mapping like AC.
|
- [simshmbridge](https://github.com/spacefreak18/simshmbridge) - for sims that need shared memory mapping like AC and Project Cars related.
|
||||||
- [simapi](https://github.com/spacefreak18/simapi)
|
- [simapi](https://github.com/spacefreak18/simapi)
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
@ -36,15 +38,49 @@ This code depends on the shared memory data headers in the simapi [repo](https:/
|
||||||
git submodule sync --recursive
|
git submodule sync --recursive
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
```
|
```
|
||||||
|
|
||||||
Then to compile simply:
|
Then to compile simply:
|
||||||
```
|
```
|
||||||
mkdir build; cd build
|
mkdir build; cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
## Testing
|
|
||||||
|
|
||||||
### Setting up Your Arduino Device
|
to use the pulseaudio backend use this cmake command
|
||||||
|
```
|
||||||
|
cmake -DUSE_PULSEAUDIO=YES ..
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
### Static Analysis
|
### Static Analysis
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,18 @@ devices = ( { device = "USB";
|
||||||
granularity = 4;
|
granularity = 4;
|
||||||
config = "/home/paul/.config/monocoque/revburner1.xml"; },
|
config = "/home/paul/.config/monocoque/revburner1.xml"; },
|
||||||
{ device = "Sound";
|
{ device = "Sound";
|
||||||
type = "Engine"
|
type = "Engine";
|
||||||
devid = "98FD:83AC"; },
|
devid = "alsa_output.usb-Generic_USB2.0_Device_20170726905959-00.analog-stereo";
|
||||||
|
pan = 1;
|
||||||
|
volume = 90;
|
||||||
|
frequency = 27; },
|
||||||
{ device = "Sound";
|
{ device = "Sound";
|
||||||
type = "Gear"
|
type = "Gear"
|
||||||
devid = "98FD:83AC"; },
|
devid = "alsa_output.usb-Generic_USB2.0_Device_20170726905959-00.analog-stereo";
|
||||||
|
pan = 1;
|
||||||
|
duration = .25;
|
||||||
|
volume = 100;
|
||||||
|
frequency = 27; },
|
||||||
{ device = "Serial";
|
{ device = "Serial";
|
||||||
type = "ShiftLights";
|
type = "ShiftLights";
|
||||||
config = "None";
|
config = "None";
|
||||||
|
|
|
||||||
|
|
@ -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,27 @@
|
||||||
|
#ifndef _SHIFTLIGHTSDATA_H
|
||||||
|
#define _SHIFTLIGHTSDATA_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char color_1_red;
|
||||||
|
unsigned char color_1_green;
|
||||||
|
unsigned char color_1_blue;
|
||||||
|
unsigned char color_2_red;
|
||||||
|
unsigned char color_2_green;
|
||||||
|
unsigned char color_2_blue;
|
||||||
|
unsigned char color_3_red;
|
||||||
|
unsigned char color_3_green;
|
||||||
|
unsigned char color_3_blue;
|
||||||
|
unsigned char space_1;
|
||||||
|
unsigned char space_2;
|
||||||
|
unsigned char space_3;
|
||||||
|
uint32_t maxrpm;
|
||||||
|
uint32_t rpm;
|
||||||
|
}
|
||||||
|
ShiftLightsData;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,14 +1,24 @@
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#include "simdata.h"
|
#include "shiftlights.h"
|
||||||
|
|
||||||
#define SIMDATA_SIZE sizeof(SimData)
|
#define SIMDATA_SIZE sizeof(ShiftLightsData)
|
||||||
|
|
||||||
#define LED_PIN 7
|
#define LED_PIN 7
|
||||||
#define NUM_LEDS 6
|
#define NUM_LEDS 6
|
||||||
#define BRIGHTNESS 40
|
#define BRIGHTNESS 40
|
||||||
|
|
||||||
|
#define COLOR1A 0
|
||||||
|
#define COLOR1B 0
|
||||||
|
#define COLOR1C 255
|
||||||
|
#define COLOR2A 0
|
||||||
|
#define COLOR2B 255
|
||||||
|
#define COLOR2C 0
|
||||||
|
#define COLOR3A 255
|
||||||
|
#define COLOR3B 0
|
||||||
|
#define COLOR3C 0
|
||||||
|
|
||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
SimData sd;
|
ShiftLightsData sd;
|
||||||
int maxrpm = 0;
|
int maxrpm = 0;
|
||||||
int rpm = 0;
|
int rpm = 0;
|
||||||
int numlights = NUM_LEDS;
|
int numlights = NUM_LEDS;
|
||||||
|
|
@ -29,11 +39,8 @@ void setup()
|
||||||
}
|
}
|
||||||
FastLED.clear();
|
FastLED.clear();
|
||||||
|
|
||||||
sd.rpms = 0;
|
sd.rpm = 0;
|
||||||
sd.maxrpm = 6500;
|
sd.maxrpm = 6500;
|
||||||
sd.altitude = 10;
|
|
||||||
sd.pulses = 40000;
|
|
||||||
sd.velocity = 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
@ -45,12 +52,10 @@ void loop()
|
||||||
{
|
{
|
||||||
Serial.readBytes(buff, SIMDATA_SIZE);
|
Serial.readBytes(buff, SIMDATA_SIZE);
|
||||||
memcpy(&sd, &buff, SIMDATA_SIZE);
|
memcpy(&sd, &buff, SIMDATA_SIZE);
|
||||||
rpm = sd.rpms;
|
rpm = sd.rpm;
|
||||||
maxrpm = sd.maxrpm;
|
maxrpm = sd.maxrpm;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while (l < numlights)
|
while (l < numlights)
|
||||||
{
|
{
|
||||||
lights[l] = 0;
|
lights[l] = 0;
|
||||||
|
|
@ -75,15 +80,15 @@ void loop()
|
||||||
|
|
||||||
if (l >= numlights / 2)
|
if (l >= numlights / 2)
|
||||||
{
|
{
|
||||||
leds[l] = CRGB ( 0, 0, 255);
|
leds[l] = CRGB ( COLOR1A, COLOR1B, COLOR1C);
|
||||||
}
|
}
|
||||||
if (l < numlights / 2)
|
if (l < numlights / 2)
|
||||||
{
|
{
|
||||||
leds[l] = CRGB ( 0, 255, 0);
|
leds[l] = CRGB ( COLOR2A, COLOR2B, COLOR2C);
|
||||||
}
|
}
|
||||||
if (l == numlights - 1)
|
if (l == numlights - 1)
|
||||||
{
|
{
|
||||||
leds[l] = CRGB ( 255, 0, 0);
|
leds[l] = CRGB ( COLOR3A, COLOR3B, COLOR3C);
|
||||||
}
|
}
|
||||||
if (lights[l] <= 0)
|
if (lights[l] <= 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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,15 @@
|
||||||
|
#ifndef _SIMWINDDATA_H
|
||||||
|
#define _SIMWINDDATA_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t velocity;
|
||||||
|
float fanpower;
|
||||||
|
}
|
||||||
|
SimWindData;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
#include <Adafruit_MotorShield.h>
|
#include <Adafruit_MotorShield.h>
|
||||||
#include "simdata.h"
|
#include "simwind.h"
|
||||||
|
|
||||||
#define BYTE_SIZE sizeof(SimData)
|
#define BYTE_SIZE sizeof(SimWindData)
|
||||||
#define KPHTOMPH .621317
|
#define KPHTOMPH .621317
|
||||||
|
#define FANPOWER .6
|
||||||
|
|
||||||
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
||||||
|
|
||||||
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
|
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
|
||||||
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(3);
|
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(3);
|
||||||
|
|
||||||
SimData sd;
|
SimWindData sd;
|
||||||
int velocity = 0;
|
int velocity = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
@ -19,10 +19,6 @@ void setup() {
|
||||||
Serial.println("Could not find Motor Shield. Check wiring.");
|
Serial.println("Could not find Motor Shield. Check wiring.");
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
sd.rpms = 0;
|
|
||||||
sd.maxrpm = 6500;
|
|
||||||
sd.altitude = 10;
|
|
||||||
sd.pulses = 40000;
|
|
||||||
sd.velocity = 10;
|
sd.velocity = 10;
|
||||||
|
|
||||||
myMotor1->setSpeed(0);
|
myMotor1->setSpeed(0);
|
||||||
|
|
@ -46,6 +42,6 @@ void loop() {
|
||||||
{
|
{
|
||||||
v = 255;
|
v = 255;
|
||||||
}
|
}
|
||||||
myMotor1->setSpeed(v);
|
myMotor1->setSpeed(v*FANPOWER);
|
||||||
myMotor2->setSpeed(v);
|
myMotor2->setSpeed(v*FANPOWER);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,15 @@ set(devices_source_files
|
||||||
serialdevice.c
|
serialdevice.c
|
||||||
tachdevice.h
|
tachdevice.h
|
||||||
tachdevice.c
|
tachdevice.c
|
||||||
|
usbhapticdevice.h
|
||||||
|
usbhapticdevice.c
|
||||||
|
sound.h
|
||||||
|
sound.c
|
||||||
usb/revburner.h
|
usb/revburner.h
|
||||||
usb/revburner.c
|
usb/revburner.c
|
||||||
sound/usb_generic_shaker.h
|
sound/usb_generic_shaker.h
|
||||||
sound/usb_generic_shaker.c
|
sound/usb_generic_shaker.c
|
||||||
|
sound/usb_generic_shaker_pulse.c
|
||||||
serial/arduino.h
|
serial/arduino.h
|
||||||
serial/arduino.c
|
serial/arduino.c
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,42 @@
|
||||||
#include "arduino.h"
|
#include "arduino.h"
|
||||||
#include "../../slog/slog.h"
|
#include "../../slog/slog.h"
|
||||||
|
|
||||||
#define arduino_timeout 2000
|
#define arduino_timeout 5000
|
||||||
|
|
||||||
int arduino_update(SerialDevice* serialdevice, SimData* simdata)
|
int arduino_update(SerialDevice* serialdevice, void* data, size_t size)
|
||||||
{
|
{
|
||||||
int result = 1;
|
int result = 1;
|
||||||
if (serialdevice->port)
|
if (serialdevice->port)
|
||||||
{
|
{
|
||||||
result = check(sp_blocking_write(serialdevice->port, simdata, sizeof(SimData), arduino_timeout));
|
slogt("copying %i bytes to arduino device", size);
|
||||||
|
result = check(sp_blocking_write(serialdevice->port, data, size, arduino_timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//int arduino_shiftlights_update(SerialDevice* serialdevice, SimData* simdata)
|
||||||
|
//{
|
||||||
|
// int result = 1;
|
||||||
|
// if (serialdevice->port)
|
||||||
|
// {
|
||||||
|
// result = check(sp_blocking_write(serialdevice->port, simdata, sizeof(SimData), arduino_timeout));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int arduino_simwind_update(SerialDevice* serialdevice, SimData* simdata)
|
||||||
|
//{
|
||||||
|
// int result = 1;
|
||||||
|
// if (serialdevice->port)
|
||||||
|
// {
|
||||||
|
// result = check(sp_blocking_write(serialdevice->port, simdata, sizeof(SimData), arduino_timeout));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
//}
|
||||||
|
|
||||||
int arduino_init(SerialDevice* serialdevice, const char* portdev)
|
int arduino_init(SerialDevice* serialdevice, const char* portdev)
|
||||||
{
|
{
|
||||||
slogi("initializing arduino serial device...");
|
slogi("initializing arduino serial device...");
|
||||||
|
|
@ -80,3 +103,4 @@ int check(enum sp_return result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
#include "../simdevice.h"
|
#include "../simdevice.h"
|
||||||
#include "../serialdevice.h"
|
#include "../serialdevice.h"
|
||||||
|
|
||||||
int arduino_update(SerialDevice* serialdevice, SimData* simdata);
|
|
||||||
|
int arduino_update(SerialDevice* serialdevice, void* data, size_t size);
|
||||||
int arduino_init(SerialDevice* serialdevice, const char* portdev);
|
int arduino_init(SerialDevice* serialdevice, const char* portdev);
|
||||||
int arduino_free(SerialDevice* serialdevice);
|
int arduino_free(SerialDevice* serialdevice);
|
||||||
int check(enum sp_return result);
|
int check(enum sp_return result);
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,45 @@ int serialdev_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
||||||
arduino_update(serialdevice, simdata);
|
|
||||||
|
|
||||||
|
arduino_update(serialdevice, simdata, sizeof(SimData));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arduino_shiftlights_update(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
int result = 1;
|
||||||
|
|
||||||
|
|
||||||
|
serialdevice->u.shiftlightsdata.maxrpm = simdata->maxrpm;
|
||||||
|
serialdevice->u.shiftlightsdata.rpm = simdata->rpms;
|
||||||
|
slogt("Updating arduino device rpms to %i", serialdevice->u.shiftlightsdata.rpm);
|
||||||
|
// we can add configs to set all the colors
|
||||||
|
// i can move the size to the initialization since it should not change
|
||||||
|
size_t size = sizeof(ShiftLightsData);
|
||||||
|
|
||||||
|
arduino_update(serialdevice, &serialdevice->u.shiftlightsdata, size);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int arduino_simwind_update(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
int result = 1;
|
||||||
|
|
||||||
|
serialdevice->u.simwinddata.velocity = simdata->velocity;
|
||||||
|
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 = 0.6;
|
||||||
|
size_t size = sizeof(SimWindData);
|
||||||
|
|
||||||
|
arduino_update(serialdevice, &serialdevice->u.simwinddata, size);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int serialdev_free(SimDevice* this)
|
int serialdev_free(SimDevice* this)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
@ -43,6 +78,8 @@ int serialdev_init(SerialDevice* serialdevice, const char* portdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const vtable serial_simdevice_vtable = { &serialdev_update, &serialdev_free };
|
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_simwind_vtable = { &arduino_simwind_update, &serialdev_free };
|
||||||
|
|
||||||
SerialDevice* new_serial_device(DeviceSettings* ds) {
|
SerialDevice* new_serial_device(DeviceSettings* ds) {
|
||||||
|
|
||||||
|
|
@ -53,6 +90,20 @@ SerialDevice* new_serial_device(DeviceSettings* ds) {
|
||||||
this->m.derived = this;
|
this->m.derived = this;
|
||||||
this->m.vtable = &serial_simdevice_vtable;
|
this->m.vtable = &serial_simdevice_vtable;
|
||||||
|
|
||||||
|
slogt("Attempting to configure arduino device with subtype: %i", ds->dev_subtype);
|
||||||
|
switch (ds->dev_subtype) {
|
||||||
|
case (SIMDEVTYPE_SHIFTLIGHTS):
|
||||||
|
this->devicetype = ARDUINODEV__SHIFTLIGHTS;
|
||||||
|
this->m.vtable = &arduino_shiftlights_vtable;
|
||||||
|
slogi("Initializing arduino device for shiftlights.");
|
||||||
|
break;
|
||||||
|
case (SIMDEVTYPE_SIMWIND):
|
||||||
|
this->devicetype = ARDUINODEV__SIMWIND;
|
||||||
|
this->m.vtable = &arduino_simwind_vtable;
|
||||||
|
slogi("Initializing arduino devices for sim wind.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int error = serialdev_init(this, ds->serialdevsettings.portdev);
|
int error = serialdev_init(this, ds->serialdevsettings.portdev);
|
||||||
|
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,11 @@
|
||||||
|
|
||||||
#include <libserialport.h>
|
#include <libserialport.h>
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ARDUINODEV__SHIFTLIGHTS = 0,
|
||||||
|
ARDUINODEV__SIMWIND = 1,
|
||||||
|
}
|
||||||
|
SerialDeviceType;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
||||||
simdevices[j] = sim->m;
|
simdevices[j] = sim->m;
|
||||||
simdevices[j].initialized = true;
|
simdevices[j].initialized = true;
|
||||||
simdevices[j].type = SIMDEV_USB;
|
simdevices[j].type = SIMDEV_USB;
|
||||||
|
simdevices[j].tyre = ds[j].tyre;
|
||||||
devices++;
|
devices++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -78,6 +79,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
||||||
simdevices[j] = sim->m;
|
simdevices[j] = sim->m;
|
||||||
simdevices[j].initialized = true;
|
simdevices[j].initialized = true;
|
||||||
simdevices[j].type = SIMDEV_SOUND;
|
simdevices[j].type = SIMDEV_SOUND;
|
||||||
|
simdevices[j].tyre = ds[j].tyre;
|
||||||
devices++;
|
devices++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
|
||||||
|
#include "../../arduino/simwind/simwind.h"
|
||||||
|
#include "../../arduino/shiftlights/shiftlights.h"
|
||||||
|
|
||||||
typedef struct SimDevice SimDevice;
|
typedef struct SimDevice SimDevice;
|
||||||
|
|
||||||
struct SimDevice
|
struct SimDevice
|
||||||
|
|
@ -20,7 +23,7 @@ struct SimDevice
|
||||||
int id;
|
int id;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
DeviceType type;
|
DeviceType type;
|
||||||
|
MonocoqueTyreIdentifier tyre;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -42,10 +45,17 @@ typedef struct
|
||||||
int id;
|
int id;
|
||||||
SerialType type;
|
SerialType type;
|
||||||
struct sp_port* port;
|
struct sp_port* port;
|
||||||
|
SerialDeviceType devicetype;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
SimWindData simwinddata;
|
||||||
|
ShiftLightsData shiftlightsdata;
|
||||||
|
} u;
|
||||||
}
|
}
|
||||||
SerialDevice;
|
SerialDevice;
|
||||||
|
|
||||||
int serialdev_update(SimDevice* this, SimData* simdata);
|
int arduino_shiftlights_update(SimDevice* this, SimData* simdata);
|
||||||
|
int arduino_simwind_update(SimDevice* this, SimData* simdata);
|
||||||
int serialdev_free(SimDevice* this);
|
int serialdev_free(SimDevice* this);
|
||||||
|
|
||||||
SerialDevice* new_serial_device(DeviceSettings* ds);
|
SerialDevice* new_serial_device(DeviceSettings* ds);
|
||||||
|
|
@ -54,7 +64,8 @@ SerialDevice* new_serial_device(DeviceSettings* ds);
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
USBDEV_UNKNOWN = 0,
|
USBDEV_UNKNOWN = 0,
|
||||||
USBDEV_TACHOMETER = 1
|
USBDEV_TACHOMETER = 1,
|
||||||
|
USBDEV_GENERICHAPTIC = 2
|
||||||
}
|
}
|
||||||
USBType;
|
USBType;
|
||||||
|
|
||||||
|
|
@ -66,6 +77,7 @@ typedef struct
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
TachDevice tachdevice;
|
TachDevice tachdevice;
|
||||||
|
USBGenericHapticDevice hapticdevice;
|
||||||
} u;
|
} u;
|
||||||
}
|
}
|
||||||
USBDevice;
|
USBDevice;
|
||||||
|
|
@ -83,14 +95,19 @@ typedef struct
|
||||||
int id;
|
int id;
|
||||||
SoundType type;
|
SoundType type;
|
||||||
VibrationEffectType effecttype;
|
VibrationEffectType effecttype;
|
||||||
PATestData sounddata;
|
SoundData sounddata;
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
pa_stream *stream;
|
||||||
|
#else
|
||||||
PaStreamParameters outputParameters;
|
PaStreamParameters outputParameters;
|
||||||
PaStream* stream;
|
PaStream* stream;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
SoundDevice;
|
SoundDevice;
|
||||||
|
|
||||||
int sounddev_engine_update(SimDevice* this, SimData* simdata);
|
int sounddev_engine_update(SimDevice* this, SimData* simdata);
|
||||||
int sounddev_gearshift_update(SimDevice* this, SimData* simdata);
|
int sounddev_gearshift_update(SimDevice* this, SimData* simdata);
|
||||||
|
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata);
|
||||||
int sounddev_free(SimDevice* this);
|
int sounddev_free(SimDevice* this);
|
||||||
|
|
||||||
SoundDevice* new_sound_device(DeviceSettings* ds);
|
SoundDevice* new_sound_device(DeviceSettings* ds);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
#include "sound.h"
|
||||||
|
|
||||||
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
|
||||||
|
pa_threaded_mainloop* mainloop;
|
||||||
|
pa_context* context;
|
||||||
|
|
||||||
|
void context_state_cb(pa_context* context, void* mainloop) {
|
||||||
|
pa_threaded_mainloop_signal(mainloop, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int setupsound()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pa_mainloop_api *mainloop_api;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Lock the mainloop so that it does not run and crash before the context is ready
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
slogi("successfully connected pulseaudio...");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int freesound()
|
||||||
|
{
|
||||||
|
if (context)
|
||||||
|
pa_context_unref(context);
|
||||||
|
|
||||||
|
if (mainloop) {
|
||||||
|
pa_signal_done();
|
||||||
|
pa_threaded_mainloop_free(mainloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int setupsound()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
slogi("connecting portaudio...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int freesound()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef _SOUND_H
|
||||||
|
#define _SOUND_H
|
||||||
|
|
||||||
|
#include <pulse/pulseaudio.h>
|
||||||
|
|
||||||
|
extern pa_threaded_mainloop* mainloop;
|
||||||
|
extern pa_context* context;
|
||||||
|
|
||||||
|
|
||||||
|
int setupsound();
|
||||||
|
int freesound();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#ifndef USE_PULSEAUDIO
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
@ -10,6 +12,9 @@
|
||||||
|
|
||||||
#define SAMPLE_RATE (48000)
|
#define SAMPLE_RATE (48000)
|
||||||
|
|
||||||
|
#define DURATION 4.0
|
||||||
|
#define AMPLITUDE .5
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI (3.14159265)
|
#define M_PI (3.14159265)
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -22,39 +27,27 @@ int patestCallbackEngineRPM(const void* inputBuffer,
|
||||||
PaStreamCallbackFlags statusFlags,
|
PaStreamCallbackFlags statusFlags,
|
||||||
void* userData)
|
void* userData)
|
||||||
{
|
{
|
||||||
PATestData* data = (PATestData*)userData;
|
SoundData* data = (SoundData*)userData;
|
||||||
float* out = (float*)outputBuffer;
|
float* out = (float*)outputBuffer;
|
||||||
memset(out, 0, framesPerBuffer * 2 * sizeof(float));
|
memset(out, 0, framesPerBuffer * 2 * sizeof(float));
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
n = data->n;
|
//n = data->n;
|
||||||
(void) inputBuffer; /* Prevent unused argument warning. */
|
(void) inputBuffer; /* Prevent unused argument warning. */
|
||||||
|
|
||||||
for( i=0; i<framesPerBuffer; i++,n++ )
|
for( i=0; i<framesPerBuffer; i++,n++ )
|
||||||
{
|
{
|
||||||
float v = 0;
|
static double t = 0.0;
|
||||||
v = data->amp * sin (2 * M_PI * ((float) n) / (float) SAMPLE_RATE);
|
double sample = AMPLITUDE * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * t);
|
||||||
|
|
||||||
if (n>=data->table_size)
|
t += 1.0 / SAMPLE_RATE;
|
||||||
{
|
if (t >= DURATION) {
|
||||||
n=0;
|
t = 0.0;
|
||||||
|
}
|
||||||
|
*out++ = sample;
|
||||||
|
*out++ = sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (data->gear_sound_data > 0)
|
|
||||||
{
|
|
||||||
*out++ = 0;
|
|
||||||
*out++ = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*out++ = v;
|
|
||||||
*out++ = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data->gear_sound_data = 0;
|
|
||||||
data->n=n;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,39 +59,33 @@ int patestCallbackGearShift(const void* inputBuffer,
|
||||||
PaStreamCallbackFlags statusFlags,
|
PaStreamCallbackFlags statusFlags,
|
||||||
void* userData)
|
void* userData)
|
||||||
{
|
{
|
||||||
PATestData* data = (PATestData*)userData;
|
SoundData* data = (SoundData*)userData;
|
||||||
float* out = (float*)outputBuffer;
|
float* out = (float*)outputBuffer;
|
||||||
memset(out, 0, framesPerBuffer * 2 * sizeof(float));
|
memset(out, 0, framesPerBuffer * 2 * sizeof(float));
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
n = data->n;
|
//n = data->n;
|
||||||
(void) inputBuffer; /* Prevent unused argument warning. */
|
(void) inputBuffer; /* Prevent unused argument warning. */
|
||||||
|
|
||||||
for( i=0; i<framesPerBuffer; i++,n++ )
|
for( i=0; i<framesPerBuffer; i++,n++ )
|
||||||
{
|
{
|
||||||
float v = 0;
|
static double t = 0.0;
|
||||||
v = data->amp * sin (2 * M_PI * ((float) n) / (float) SAMPLE_RATE);
|
double sample = 0;
|
||||||
|
if (data->frequency>0)
|
||||||
if (n>=data->table_size)
|
|
||||||
{
|
{
|
||||||
n=0;
|
sample = AMPLITUDE * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * data->curr_duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data->gear_sound_data > 0)
|
|
||||||
{
|
|
||||||
*out++ = v;
|
|
||||||
*out++ = v;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*out++ = 0;
|
|
||||||
*out++ = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data->gear_sound_data = 0;
|
|
||||||
|
|
||||||
data->n=n;
|
data->curr_duration += 1.0 / SAMPLE_RATE;
|
||||||
return 0;
|
if (data->curr_duration >= data->duration) {
|
||||||
|
data->curr_duration = 0.0;
|
||||||
|
data->curr_frequency = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out++ = sample;
|
||||||
|
*out++ = sample;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_generic_shaker_free(SoundDevice* sounddevice)
|
int usb_generic_shaker_free(SoundDevice* sounddevice)
|
||||||
|
|
@ -169,3 +156,5 @@ error:
|
||||||
Pa_Terminate();
|
Pa_Terminate();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
#ifndef _USB_GENERIC_SHAKER_H
|
#ifndef _USB_GENERIC_SHAKER_H
|
||||||
#define _USB_GENERIC_SHAKER_H
|
#define _USB_GENERIC_SHAKER_H
|
||||||
|
|
||||||
//#include "../sounddevice.h"
|
|
||||||
#include "../simdevice.h"
|
#include "../simdevice.h"
|
||||||
|
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop, pa_context* context, const char* devname, int volume, int pan, const char* streamname);
|
||||||
|
#else
|
||||||
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
||||||
|
#endif
|
||||||
int usb_generic_shaker_free(SoundDevice* sounddevice);
|
int usb_generic_shaker_free(SoundDevice* sounddevice);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
#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 (48000)
|
||||||
|
#define AMPLITUDE .5
|
||||||
|
#define DURATION 4.0
|
||||||
|
|
||||||
|
#ifndef M_PI
|
||||||
|
#define M_PI (3.14159265)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void gear_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||||
|
|
||||||
|
SoundData* data = (SoundData*)userdata;
|
||||||
|
size_t num_samples = length / sizeof(int16_t);
|
||||||
|
int16_t buffer[num_samples];
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void engine_sound_stream(pa_stream *s, size_t length, void *userdata) {
|
||||||
|
|
||||||
|
SoundData* data = (SoundData*)userdata;
|
||||||
|
size_t num_samples = length / sizeof(int16_t);
|
||||||
|
int16_t buffer[num_samples];
|
||||||
|
|
||||||
|
for (size_t i = 0; i < num_samples; i++) {
|
||||||
|
static double t = 0.0;
|
||||||
|
double sample = AMPLITUDE * 32767.0 * sin(2.0 * M_PI * data->curr_frequency * t);
|
||||||
|
|
||||||
|
|
||||||
|
buffer[i] = (int16_t)sample;
|
||||||
|
|
||||||
|
t += 1.0 / SAMPLE_RATE;
|
||||||
|
if (t >= DURATION) {
|
||||||
|
t = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pa_stream_write(s, buffer, length, NULL, 0LL, PA_SEEK_RELATIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stream_success_cb(pa_stream *stream, int success, void *userdata) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stream_state_cb(pa_stream *s, void *mainloop) {
|
||||||
|
pa_threaded_mainloop_signal(mainloop, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_generic_shaker_free(SoundDevice* sounddevice)
|
||||||
|
{
|
||||||
|
int err = 0;
|
||||||
|
//err = Pa_CloseStream( sounddevice->stream );
|
||||||
|
//if( err != paNoError )
|
||||||
|
//{
|
||||||
|
// err = Pa_Terminate();
|
||||||
|
//}
|
||||||
|
if (sounddevice->stream)
|
||||||
|
{
|
||||||
|
pa_stream_unref(sounddevice->stream);
|
||||||
|
pa_xfree(sounddevice->stream);
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* mainloop, pa_context* context, const char* devname, int volume, int pan, const char* streamname)
|
||||||
|
{
|
||||||
|
pa_stream *stream;
|
||||||
|
|
||||||
|
// Create a playback stream
|
||||||
|
pa_sample_spec sample_specifications;
|
||||||
|
sample_specifications.format = FORMAT;
|
||||||
|
sample_specifications.rate = SAMPLE_RATE;
|
||||||
|
sample_specifications.channels = 2;
|
||||||
|
|
||||||
|
|
||||||
|
pa_channel_map channel_map;
|
||||||
|
pa_channel_map_init_stereo(&channel_map);
|
||||||
|
pa_channel_map_parse(&channel_map, "front-left,front-right");
|
||||||
|
|
||||||
|
|
||||||
|
stream = pa_stream_new(context, streamname, &sample_specifications, &channel_map);
|
||||||
|
pa_stream_set_state_callback(stream, stream_state_cb, mainloop);
|
||||||
|
|
||||||
|
|
||||||
|
if (sounddevice->effecttype == EFFECT_GEARSHIFT)
|
||||||
|
{
|
||||||
|
pa_stream_set_write_callback(stream, gear_sound_stream, &sounddevice->sounddata);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pa_stream_set_write_callback(stream, engine_sound_stream, &sounddevice->sounddata);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.prebuf = (uint32_t) -1;
|
||||||
|
buffer_attr.minreq = (uint32_t) -1;
|
||||||
|
|
||||||
|
pa_cvolume cv;
|
||||||
|
uint16_t pvolume = ceil(((double) volume/100.0d)*65535);
|
||||||
|
// Settings copied as per the chromium browser source
|
||||||
|
|
||||||
|
pa_stream_flags_t stream_flags;
|
||||||
|
stream_flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_NOT_MONOTONIC | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED;
|
||||||
|
|
||||||
|
// Connect stream to the default audio output sink
|
||||||
|
pa_cvolume_set(&cv, sample_specifications.channels, pvolume);
|
||||||
|
|
||||||
|
pa_cvolume_set_balance(&cv, &channel_map, pan);
|
||||||
|
|
||||||
|
assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
|
||||||
|
|
||||||
|
// Wait for the stream to be ready
|
||||||
|
for(;;) {
|
||||||
|
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
||||||
|
assert(PA_STREAM_IS_GOOD(stream_state));
|
||||||
|
if (stream_state == PA_STREAM_READY) break;
|
||||||
|
pa_threaded_mainloop_wait(mainloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//pa_threaded_mainloop_unlock(mainloop);
|
||||||
|
|
||||||
|
// Uncork the stream so it will start playing
|
||||||
|
pa_stream_cork(stream, 0, stream_success_cb, mainloop);
|
||||||
|
|
||||||
|
sounddevice->stream = stream;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "sound.h"
|
||||||
#include "simdevice.h"
|
#include "simdevice.h"
|
||||||
#include "sounddevice.h"
|
#include "sounddevice.h"
|
||||||
#include "sound/usb_generic_shaker.h"
|
#include "sound/usb_generic_shaker.h"
|
||||||
|
|
@ -12,13 +13,18 @@
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
|
|
||||||
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear != 0)
|
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
|
||||||
{
|
{
|
||||||
sounddevice->sounddata.gear_sound_data = 3.14;
|
//sounddevice->sounddata.gear_sound_data = 3.14;
|
||||||
|
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||||
|
sounddevice->sounddata.curr_duration = 0;
|
||||||
}
|
}
|
||||||
sounddevice->sounddata.last_gear = simdata->gear;
|
sounddevice->sounddata.last_gear = simdata->gear;
|
||||||
|
|
||||||
|
slogt("set gear frequency to %i", sounddevice->sounddata.frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we could make a vtable for these different effects too
|
// we could make a vtable for these different effects too
|
||||||
|
|
@ -26,9 +32,59 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SoundDevice* sounddevice = (void *) this->derived;
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
gear_sound_set(sounddevice, simdata);
|
sounddevice->sounddata.curr_frequency = simdata->rpms/60;
|
||||||
|
//sounddevice->sounddata.table_size = 48000/(sounddevice->sounddata.frequency);
|
||||||
|
|
||||||
sounddevice->sounddata.table_size = 44100/(simdata->rpms/60);
|
slogt("set engine frequency to %i", sounddevice->sounddata.frequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
|
double play = 0;
|
||||||
|
if (this->tyre == FRONTLEFT || this->tyre == FRONTS || this->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[0];
|
||||||
|
}
|
||||||
|
if (this->tyre == FRONTRIGHT || this->tyre == FRONTS || this->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[1];
|
||||||
|
}
|
||||||
|
if (this->tyre == REARLEFT || this->tyre == REARS || this->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[2];
|
||||||
|
}
|
||||||
|
if (this->tyre == REARRIGHT || this->tyre == REARS || this->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[3];
|
||||||
|
}
|
||||||
|
if (play > 0)
|
||||||
|
{
|
||||||
|
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency * play;
|
||||||
|
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sounddevice->sounddata.curr_frequency = 0;
|
||||||
|
sounddevice->sounddata.curr_duration = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
|
if (simdata->abs > 0)
|
||||||
|
{
|
||||||
|
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
|
||||||
|
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sounddevice->sounddata.curr_frequency = 0;
|
||||||
|
sounddevice->sounddata.curr_duration = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
|
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
|
||||||
|
|
@ -49,32 +105,67 @@ int sounddev_free(SimDevice* this)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sounddev_init(SoundDevice* sounddevice)
|
int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, double duration)
|
||||||
{
|
{
|
||||||
slogi("initializing standalone sound device...");
|
slogi("initializing standalone sound device...");
|
||||||
|
|
||||||
sounddevice->sounddata.pitch = 1;
|
|
||||||
sounddevice->sounddata.pitch = 261.626;
|
|
||||||
sounddevice->sounddata.amp = 32;
|
|
||||||
sounddevice->sounddata.left_phase = sounddevice->sounddata.right_phase = 0;
|
|
||||||
sounddevice->sounddata.table_size = 44100/(100/60);
|
|
||||||
sounddevice->sounddata.last_gear = 0;
|
|
||||||
|
|
||||||
|
slogi("volume is: %i", volume);
|
||||||
|
slogi("frequency is: %i", frequency);
|
||||||
|
slogi("pan is: %i", pan);
|
||||||
|
slogi("duration is: %f", duration);
|
||||||
|
|
||||||
|
|
||||||
|
sounddevice->sounddata.frequency = frequency;
|
||||||
|
//sounddevice->sounddata.pitch = 1;
|
||||||
|
//sounddevice->sounddata.pitch = 261.626;
|
||||||
|
//sounddevice->sounddata.amp = 32;
|
||||||
|
//sounddevice->sounddata.left_phase = sounddevice->sounddata.right_phase = 0;
|
||||||
|
//sounddevice->sounddata.table_size = 48000/(100/60);
|
||||||
|
sounddevice->sounddata.curr_frequency = 100/60;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char* streamname= "Engine";
|
||||||
switch (sounddevice->effecttype) {
|
switch (sounddevice->effecttype) {
|
||||||
case (SOUNDEFFECT_GEARSHIFT):
|
case (EFFECT_GEARSHIFT):
|
||||||
|
|
||||||
sounddevice->sounddata.pitch = 500;
|
sounddevice->sounddata.last_gear = 0;
|
||||||
sounddevice->sounddata.amp = 128;
|
//sounddevice->sounddata.pitch = 500;
|
||||||
sounddevice->sounddata.left_phase = sounddevice->sounddata.right_phase = 0;
|
//sounddevice->sounddata.amp = 128;
|
||||||
sounddevice->sounddata.table_size = 44100/(1);
|
//sounddevice->sounddata.left_phase = sounddevice->sounddata.right_phase = 0;
|
||||||
|
//sounddevice->sounddata.table_size = 48000/(1);
|
||||||
|
sounddevice->sounddata.duration = duration;
|
||||||
|
sounddevice->sounddata.curr_duration = duration;
|
||||||
|
streamname = "Gear";
|
||||||
|
break;
|
||||||
|
case (EFFECT_TYRESLIP):
|
||||||
|
sounddevice->sounddata.duration = duration;
|
||||||
|
sounddevice->sounddata.curr_duration = duration;
|
||||||
|
streamname = "TyreSlip";
|
||||||
|
break;
|
||||||
|
case (EFFECT_ABSBRAKES):
|
||||||
|
sounddevice->sounddata.duration = duration;
|
||||||
|
sounddevice->sounddata.curr_duration = duration;
|
||||||
|
streamname = "ABS";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
|
||||||
|
|
||||||
|
//pa_threaded_mainloop* mainloop;
|
||||||
|
//pa_context* context;
|
||||||
|
usb_generic_shaker_init(sounddevice, mainloop, context, devname, volume, pan, streamname);
|
||||||
|
#else
|
||||||
usb_generic_shaker_init(sounddevice);
|
usb_generic_shaker_init(sounddevice);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static const vtable engine_sound_simdevice_vtable = { &sounddev_engine_update, &sounddev_free };
|
static const vtable engine_sound_simdevice_vtable = { &sounddev_engine_update, &sounddev_free };
|
||||||
static const vtable gear_sound_simdevice_vtable = { &sounddev_gearshift_update, &sounddev_free };
|
static const vtable gear_sound_simdevice_vtable = { &sounddev_gearshift_update, &sounddev_free };
|
||||||
|
static const vtable tyreslip_sound_simdevice_vtable = { &sounddev_tyreslip_update, &sounddev_free };
|
||||||
|
static const vtable absbrakes_sound_simdevice_vtable = { &sounddev_absbrakes_update, &sounddev_free };
|
||||||
|
|
||||||
SoundDevice* new_sound_device(DeviceSettings* ds) {
|
SoundDevice* new_sound_device(DeviceSettings* ds) {
|
||||||
|
|
||||||
|
|
@ -84,21 +175,33 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
|
||||||
this->m.free = &simdevfree;
|
this->m.free = &simdevfree;
|
||||||
this->m.derived = this;
|
this->m.derived = this;
|
||||||
|
|
||||||
slogt("Attempting to configure sound device with subtype: %i", ds->dev_subtype);
|
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type);
|
||||||
switch (ds->dev_subtype) {
|
switch (ds->effect_type) {
|
||||||
case (SIMDEVTYPE_ENGINESOUND):
|
case (EFFECT_ENGINERPM):
|
||||||
this->effecttype = SOUNDEFFECT_ENGINERPM;
|
this->effecttype = EFFECT_ENGINERPM;
|
||||||
this->m.vtable = &engine_sound_simdevice_vtable;
|
this->m.vtable = &engine_sound_simdevice_vtable;
|
||||||
slogi("Initializing sound device for engine vibrations.");
|
slogi("Initializing sound device for engine vibrations.");
|
||||||
break;
|
break;
|
||||||
case (SIMDEVTYPE_GEARSOUND):
|
case (EFFECT_GEARSHIFT):
|
||||||
this->effecttype = SOUNDEFFECT_GEARSHIFT;
|
this->effecttype = EFFECT_GEARSHIFT;
|
||||||
this->m.vtable = &gear_sound_simdevice_vtable;
|
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||||
slogi("Initializing sound device for gear shift vibrations.");
|
slogi("Initializing sound device for gear shift vibrations.");
|
||||||
break;
|
break;
|
||||||
|
case (EFFECT_TYRESLIP):
|
||||||
|
this->effecttype = EFFECT_TYRESLIP;
|
||||||
|
this->m.vtable = &tyreslip_sound_simdevice_vtable;
|
||||||
|
slogi("Initializing sound device for tyre slip vibrations.");
|
||||||
|
break;
|
||||||
|
case (EFFECT_ABSBRAKES):
|
||||||
|
this->effecttype = EFFECT_ABSBRAKES;
|
||||||
|
this->m.vtable = &absbrakes_sound_simdevice_vtable;
|
||||||
|
slogi("Initializing sound device for abs vibrations.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int error = sounddev_init(this);
|
slogt("Attempting to use device %s", ds->sounddevsettings.dev);
|
||||||
|
|
||||||
|
int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.duration);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
#ifndef _SOUNDDEVICE_H
|
#ifndef _SOUNDDEVICE_H
|
||||||
#define _SOUNDDEVICE_H
|
#define _SOUNDDEVICE_H
|
||||||
|
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
#include <pulse/pulseaudio.h>
|
||||||
|
#else
|
||||||
#include "portaudio.h"
|
#include "portaudio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|
@ -10,26 +14,16 @@ typedef enum
|
||||||
}
|
}
|
||||||
SoundType;
|
SoundType;
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
SOUNDEFFECT_ENGINERPM = 0,
|
|
||||||
SOUNDEFFECT_GEARSHIFT = 1
|
|
||||||
}
|
|
||||||
VibrationEffectType;
|
|
||||||
|
|
||||||
#define MAX_TABLE_SIZE (6000)
|
#define MAX_TABLE_SIZE (6000)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float sine[MAX_TABLE_SIZE];
|
|
||||||
float pitch;
|
|
||||||
int last_gear;
|
int last_gear;
|
||||||
int left_phase;
|
int volume;
|
||||||
int right_phase;
|
int frequency;
|
||||||
int n;
|
double duration;
|
||||||
int table_size;
|
int curr_frequency;
|
||||||
int amp;
|
double curr_duration;
|
||||||
int gear_sound_data;
|
|
||||||
}
|
}
|
||||||
PATestData;
|
SoundData;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
||||||
case USBDEV_TACHOMETER :
|
case USBDEV_TACHOMETER :
|
||||||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
||||||
break;
|
break;
|
||||||
|
case USBDEV_GENERICHAPTIC :
|
||||||
|
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -28,12 +31,16 @@ int usbdev_free(SimDevice* this)
|
||||||
{
|
{
|
||||||
USBDevice* usbdevice = (void *) this->derived;
|
USBDevice* usbdevice = (void *) this->derived;
|
||||||
|
|
||||||
|
slogt("Usb device free");
|
||||||
switch ( usbdevice->type )
|
switch ( usbdevice->type )
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
case USBDEV_TACHOMETER :
|
case USBDEV_TACHOMETER :
|
||||||
tachdev_free(&usbdevice->u.tachdevice);
|
tachdev_free(&usbdevice->u.tachdevice);
|
||||||
break;
|
break;
|
||||||
|
case USBDEV_GENERICHAPTIC :
|
||||||
|
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(usbdevice);
|
free(usbdevice);
|
||||||
|
|
@ -46,13 +53,16 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||||
slogi("initializing usb device...");
|
slogi("initializing usb device...");
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
usbdevice->type = USBDEV_TACHOMETER;
|
//usbdevice->type = USBDEV_TACHOMETER;
|
||||||
switch ( usbdevice->type )
|
switch ( usbdevice->type )
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
case USBDEV_TACHOMETER :
|
case USBDEV_TACHOMETER :
|
||||||
error = tachdev_init(&usbdevice->u.tachdevice, ds);
|
error = tachdev_init(&usbdevice->u.tachdevice, ds);
|
||||||
break;
|
break;
|
||||||
|
case USBDEV_GENERICHAPTIC :
|
||||||
|
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
@ -69,6 +79,12 @@ USBDevice* new_usb_device(DeviceSettings* ds) {
|
||||||
this->m.derived = this;
|
this->m.derived = this;
|
||||||
this->m.vtable = &usb_simdevice_vtable;
|
this->m.vtable = &usb_simdevice_vtable;
|
||||||
|
|
||||||
|
this->type = USBDEV_TACHOMETER;
|
||||||
|
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
|
||||||
|
{
|
||||||
|
this->type = USBDEV_GENERICHAPTIC;
|
||||||
|
}
|
||||||
|
|
||||||
int error = usbdev_init(this, ds);
|
int error = usbdev_init(this, ds);
|
||||||
|
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,6 @@
|
||||||
#define _USBDEVICE_H
|
#define _USBDEVICE_H
|
||||||
|
|
||||||
#include "tachdevice.h"
|
#include "tachdevice.h"
|
||||||
|
#include "usbhapticdevice.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "usbhapticdevice.h"
|
||||||
|
#include "../../helper/confighelper.h"
|
||||||
|
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
#include "../../slog/slog.h"
|
||||||
|
|
||||||
|
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
|
||||||
|
{
|
||||||
|
double play = 0;
|
||||||
|
switch (usbhapticdevice->effecttype)
|
||||||
|
{
|
||||||
|
case (EFFECT_TYRESLIP):
|
||||||
|
|
||||||
|
if (usbhapticdevice->effecttype == EFFECT_TYRESLIP)
|
||||||
|
{
|
||||||
|
if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[0];
|
||||||
|
}
|
||||||
|
if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[1];
|
||||||
|
}
|
||||||
|
if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[2];
|
||||||
|
}
|
||||||
|
if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
|
||||||
|
{
|
||||||
|
play += simdata->wheelslip[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case (EFFECT_ABSBRAKES):
|
||||||
|
play += simdata->abs;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (play != usbhapticdevice->state)
|
||||||
|
{
|
||||||
|
if(play > 0)
|
||||||
|
{
|
||||||
|
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1);
|
||||||
|
fflush(usbhapticdevice->handle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value0);
|
||||||
|
fflush(usbhapticdevice->handle);
|
||||||
|
|
||||||
|
}
|
||||||
|
usbhapticdevice->state = play;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
|
||||||
|
{
|
||||||
|
slogt("closing usb haptic device");
|
||||||
|
fflush(usbhapticdevice->handle);
|
||||||
|
fclose(usbhapticdevice->handle);
|
||||||
|
free(usbhapticdevice->dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* ds)
|
||||||
|
{
|
||||||
|
int error = 0;
|
||||||
|
usbhapticdevice->state = 0;
|
||||||
|
usbhapticdevice->dev = strdup(ds->usbdevsettings.dev);
|
||||||
|
usbhapticdevice->value0 = ds->usbdevsettings.value0;
|
||||||
|
usbhapticdevice->value1 = ds->usbdevsettings.value1;
|
||||||
|
usbhapticdevice->state = usbhapticdevice->value0;
|
||||||
|
usbhapticdevice->tyre = ds->tyre;
|
||||||
|
usbhapticdevice->effecttype = ds->effect_type;
|
||||||
|
|
||||||
|
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
|
||||||
|
if(usbhapticdevice->handle == 0)
|
||||||
|
{
|
||||||
|
error = MONOCOQUE_ERROR_INVALID_DEV;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
slogt("Initializing standalone usb haptic device");
|
||||||
|
if(ds->effect_type == EFFECT_TYRESLIP)
|
||||||
|
{
|
||||||
|
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
|
||||||
|
}
|
||||||
|
if(ds->effect_type == EFFECT_WHEELLOCK)
|
||||||
|
{
|
||||||
|
usbhapticdevice->effecttype = EFFECT_WHEELLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef _USBHAPTICDEVICE_H
|
||||||
|
#define _USBHAPTICDEVICE_H
|
||||||
|
|
||||||
|
#include <hidapi/hidapi.h>
|
||||||
|
#include "../helper/confighelper.h"
|
||||||
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
HAPTIC_UNKNOWN = 0,
|
||||||
|
HAPTIC_GENERIC = 1
|
||||||
|
}
|
||||||
|
HapticType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
HapticType type;
|
||||||
|
double state;
|
||||||
|
int value0;
|
||||||
|
int value1;
|
||||||
|
VibrationEffectType effecttype;
|
||||||
|
MonocoqueTyreIdentifier tyre;
|
||||||
|
FILE* handle;
|
||||||
|
char* dev;
|
||||||
|
}
|
||||||
|
USBGenericHapticDevice;
|
||||||
|
|
||||||
|
|
||||||
|
int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata);
|
||||||
|
int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds);
|
||||||
|
int usbhapticdev_free(USBGenericHapticDevice* hapticdevice);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "gameloop.h"
|
#include "gameloop.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
|
|
@ -17,6 +18,19 @@
|
||||||
|
|
||||||
#define DEFAULT_UPDATE_RATE 240.0
|
#define DEFAULT_UPDATE_RATE 240.0
|
||||||
#define SIM_CHECK_RATE 1.0
|
#define SIM_CHECK_RATE 1.0
|
||||||
|
bool go = false;
|
||||||
|
bool go2 = false;
|
||||||
|
struct sigaction act;
|
||||||
|
|
||||||
|
void sighandler(int signum, siginfo_t* info, void* ptr)
|
||||||
|
{
|
||||||
|
sloge("caught signal");
|
||||||
|
go = false;
|
||||||
|
go2 = false;
|
||||||
|
//gfx_clear(pixels, pixels_len);
|
||||||
|
//gfx_swapbuffers();
|
||||||
|
//gfx_close();
|
||||||
|
}
|
||||||
|
|
||||||
int showstats(SimData* simdata)
|
int showstats(SimData* simdata)
|
||||||
{
|
{
|
||||||
|
|
@ -170,34 +184,13 @@ int showstats(SimData* simdata)
|
||||||
|
|
||||||
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
||||||
{
|
{
|
||||||
|
|
||||||
slogi("preparing game loop with %i devices...", numdevices);
|
|
||||||
|
|
||||||
|
|
||||||
slogi("sending initial data to devices");
|
|
||||||
simdata->velocity = 16;
|
|
||||||
simdata->rpms = 100;
|
|
||||||
for (int x = 0; x < numdevices; x++)
|
|
||||||
{
|
|
||||||
devices[x].update(&devices[x], simdata);
|
|
||||||
}
|
|
||||||
sleep(3);
|
|
||||||
|
|
||||||
struct termios newsettings, canonicalmode;
|
|
||||||
tcgetattr(0, &canonicalmode);
|
|
||||||
newsettings = canonicalmode;
|
|
||||||
newsettings.c_lflag &= (~ICANON & ~ECHO);
|
|
||||||
newsettings.c_cc[VMIN] = 1;
|
|
||||||
newsettings.c_cc[VTIME] = 0;
|
|
||||||
tcsetattr(0, TCSANOW, &newsettings);
|
|
||||||
char ch;
|
|
||||||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||||
|
|
||||||
double update_rate = DEFAULT_UPDATE_RATE;
|
double update_rate = DEFAULT_UPDATE_RATE;
|
||||||
|
char ch;
|
||||||
int t=0;
|
int t=0;
|
||||||
int s=0;
|
int s=0;
|
||||||
int go = true;
|
go2 = true;
|
||||||
while (go == true)
|
while (go2 == true && simdata->simstatus > 1)
|
||||||
{
|
{
|
||||||
simdatamap(simdata, simmap, p->sim);
|
simdatamap(simdata, simmap, p->sim);
|
||||||
showstats(simdata);
|
showstats(simdata);
|
||||||
|
|
@ -210,20 +203,17 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||||
{
|
{
|
||||||
scanf("%c", &ch);
|
scanf("%c", &ch);
|
||||||
if(ch == 'q')
|
if(ch == 'q')
|
||||||
{
|
{
|
||||||
go = false;
|
go2 = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stdout, "\n");
|
|
||||||
fflush(stdout);
|
|
||||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
|
||||||
|
|
||||||
simdata->velocity = 0;
|
simdata->velocity = 0;
|
||||||
simdata->rpms = 100;
|
simdata->rpms = 100;
|
||||||
|
|
@ -232,12 +222,19 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int looper(SimDevice* devices, int numdevices, Parameters* p)
|
int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
{
|
{
|
||||||
|
memset(&act, 0, sizeof(act));
|
||||||
|
act.sa_sigaction = sighandler;
|
||||||
|
act.sa_flags = SA_SIGINFO;
|
||||||
|
sigaction(SIGTERM, &act, NULL);
|
||||||
|
sigaction(SIGINT, &act, NULL);
|
||||||
|
sigaction(SIGTSTP, &act, NULL);
|
||||||
|
|
||||||
SimData* simdata = malloc(sizeof(SimData));
|
SimData* simdata = malloc(sizeof(SimData));
|
||||||
SimMap* simmap = malloc(sizeof(SimMap));
|
SimMap* simmap = malloc(sizeof(SimMap));
|
||||||
|
|
@ -253,23 +250,28 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||||
|
|
||||||
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||||
|
|
||||||
p->simon = false;
|
p->simon = false;
|
||||||
double update_rate = SIM_CHECK_RATE;
|
double update_rate = SIM_CHECK_RATE;
|
||||||
int go = true;
|
go = true;
|
||||||
while (go == true)
|
while (go == true)
|
||||||
{
|
{
|
||||||
|
p->simon = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (p->simon == false)
|
|
||||||
{
|
|
||||||
getSim(simdata, simmap, &p->simon, &p->sim);
|
getSim(simdata, simmap, &p->simon, &p->sim);
|
||||||
}
|
|
||||||
|
|
||||||
if (p->simon == true)
|
if (p->simon == true && simdata->simstatus > 1)
|
||||||
{
|
{
|
||||||
|
slogi("preparing game loop with %i devices...", numdevices);
|
||||||
|
|
||||||
|
|
||||||
|
slogi("sending initial data to devices");
|
||||||
|
simdata->velocity = 16;
|
||||||
|
simdata->rpms = 100;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
clilooper(devices, numdevices, p, simdata, simmap);
|
clilooper(devices, numdevices, p, simdata, simmap);
|
||||||
}
|
}
|
||||||
if (p->simon == true)
|
if (p->simon == true)
|
||||||
|
|
@ -280,6 +282,8 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll(&mypoll, 1, 1000.0/update_rate) )
|
if (poll(&mypoll, 1, 1000.0/update_rate) )
|
||||||
|
{
|
||||||
|
if (go != false )
|
||||||
{
|
{
|
||||||
scanf("%c", &ch);
|
scanf("%c", &ch);
|
||||||
if(ch == 'q')
|
if(ch == 'q')
|
||||||
|
|
@ -288,6 +292,7 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
@ -318,6 +323,11 @@ int tester(SimDevice* devices, int numdevices)
|
||||||
simdata->velocity = 16;
|
simdata->velocity = 16;
|
||||||
simdata->rpms = 100;
|
simdata->rpms = 100;
|
||||||
simdata->maxrpm = 8000;
|
simdata->maxrpm = 8000;
|
||||||
|
simdata->abs = 0;
|
||||||
|
simdata->wheelslip[0] = 0;
|
||||||
|
simdata->wheelslip[1] = 0;
|
||||||
|
simdata->wheelslip[2] = 0;
|
||||||
|
simdata->wheelslip[3] = 0;
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
fprintf(stdout, "Setting rpms to 1000\n");
|
fprintf(stdout, "Setting rpms to 1000\n");
|
||||||
|
|
@ -328,8 +338,32 @@ int tester(SimDevice* devices, int numdevices)
|
||||||
}
|
}
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting ABS to 1\n");
|
||||||
|
simdata->abs = 1;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
simdata->abs = 0;
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting Wheelslip to 1\n");
|
||||||
|
simdata->wheelslip[0] = 1;
|
||||||
|
simdata->wheelslip[1] = 1;
|
||||||
|
simdata->wheelslip[2] = 1;
|
||||||
|
simdata->wheelslip[3] = 1;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
simdata->wheelslip[0] = 0;
|
||||||
|
simdata->wheelslip[1] = 0;
|
||||||
|
simdata->wheelslip[2] = 0;
|
||||||
|
simdata->wheelslip[3] = 0;
|
||||||
|
|
||||||
fprintf(stdout, "Shifting into first gear\n");
|
fprintf(stdout, "Shifting into first gear\n");
|
||||||
simdata->gear = 1;
|
simdata->gear = 2;
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
|
|
@ -349,7 +383,7 @@ int tester(SimDevice* devices, int numdevices)
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
fprintf(stdout, "Shifting into second gear\n");
|
fprintf(stdout, "Shifting into second gear\n");
|
||||||
simdata->gear = 2;
|
simdata->gear = 3;
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
|
|
@ -369,7 +403,7 @@ int tester(SimDevice* devices, int numdevices)
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
fprintf(stdout, "Shifting into third gear\n");
|
fprintf(stdout, "Shifting into third gear\n");
|
||||||
simdata->gear = 3;
|
simdata->gear = 4;
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
|
|
@ -397,7 +431,7 @@ int tester(SimDevice* devices, int numdevices)
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
fprintf(stdout, "Shifting into fourth gear\n");
|
fprintf(stdout, "Shifting into fourth gear\n");
|
||||||
simdata->gear = 4;
|
simdata->gear = 5;
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
devices[x].update(&devices[x], simdata);
|
devices[x].update(&devices[x], simdata);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@
|
||||||
#include "confighelper.h"
|
#include "confighelper.h"
|
||||||
|
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
#include "parameters.h"
|
||||||
|
|
||||||
|
#include <pulse/pulseaudio.h>
|
||||||
|
|
||||||
int strcicmp(char const *a, char const *b)
|
int strcicmp(char const *a, char const *b)
|
||||||
{
|
{
|
||||||
|
|
@ -50,6 +52,31 @@ int strtogame(const char* game, MonocoqueSettings* ms)
|
||||||
return MONOCOQUE_ERROR_NONE;
|
return MONOCOQUE_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strtoeffecttype(const char* effect, DeviceSettings* ds)
|
||||||
|
{
|
||||||
|
ds->is_valid = false;
|
||||||
|
|
||||||
|
if (strcicmp(effect, "Engine") == 0)
|
||||||
|
{
|
||||||
|
ds->effect_type = EFFECT_ENGINERPM;
|
||||||
|
}
|
||||||
|
if (strcicmp(effect, "Gear") == 0)
|
||||||
|
{
|
||||||
|
ds->effect_type = EFFECT_GEARSHIFT;
|
||||||
|
}
|
||||||
|
if (strcicmp(effect, "ABS") == 0)
|
||||||
|
{
|
||||||
|
ds->effect_type = EFFECT_ABSBRAKES;
|
||||||
|
}
|
||||||
|
if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0))
|
||||||
|
{
|
||||||
|
ds->effect_type = EFFECT_TYRESLIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
ds->is_valid = true;
|
||||||
|
return MONOCOQUE_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||||
{
|
{
|
||||||
ds->is_valid = false;
|
ds->is_valid = false;
|
||||||
|
|
@ -62,6 +89,11 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||||
ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
|
ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (strcicmp(device_subtype, "UsbHaptic") == 0 || strcicmp(device_subtype, "Haptic") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_USBHAPTIC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SIMDEV_SERIAL:
|
case SIMDEV_SERIAL:
|
||||||
if (strcicmp(device_subtype, "ShiftLights") == 0)
|
if (strcicmp(device_subtype, "ShiftLights") == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -74,16 +106,8 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SIMDEV_SOUND:
|
case SIMDEV_SOUND:
|
||||||
if (strcicmp(device_subtype, "Engine") == 0)
|
ds->is_valid = true;
|
||||||
{
|
|
||||||
ds->dev_subtype = SIMDEVTYPE_ENGINESOUND;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (strcicmp(device_subtype, "Gear") == 0)
|
|
||||||
{
|
|
||||||
ds->dev_subtype = SIMDEVTYPE_GEARSOUND;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
ds->is_valid = false;
|
ds->is_valid = false;
|
||||||
slogw("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype);
|
slogw("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype);
|
||||||
|
|
@ -216,6 +240,40 @@ int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (strcicmp(temp, "FRONTS") == 0)
|
||||||
|
{
|
||||||
|
ds->tyre = FRONTS;
|
||||||
|
}
|
||||||
|
if (strcicmp(temp, "REARS") == 0)
|
||||||
|
{
|
||||||
|
ds->tyre = REARS;
|
||||||
|
}
|
||||||
|
if (strcicmp(temp, "FRONTLEFT") == 0)
|
||||||
|
{
|
||||||
|
ds->tyre = FRONTLEFT;
|
||||||
|
}
|
||||||
|
if (strcicmp(temp, "FRONTRIGHT") == 0)
|
||||||
|
{
|
||||||
|
ds->tyre = FRONTRIGHT;
|
||||||
|
}
|
||||||
|
if (strcicmp(temp, "REARLEFT") == 0)
|
||||||
|
{
|
||||||
|
ds->tyre = REARLEFT;
|
||||||
|
}
|
||||||
|
if (strcicmp(temp, "REARRIGHT") == 0)
|
||||||
|
{
|
||||||
|
ds->tyre = REARRIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int loadconfig(const char* config_file, DeviceSettings* ds)
|
int loadconfig(const char* config_file, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||||
|
|
@ -228,10 +286,11 @@ int loadconfig(const char* config_file, DeviceSettings* ds)
|
||||||
int devsetup(const char* device_type, const char* device_subtype, const char* config_file, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings)
|
int devsetup(const char* device_type, const char* device_subtype, const char* config_file, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings)
|
||||||
{
|
{
|
||||||
int error = MONOCOQUE_ERROR_NONE;
|
int error = MONOCOQUE_ERROR_NONE;
|
||||||
slogi("Called device setup with %s %s %s", device_type, device_subtype, config_file);
|
//slogt("Called device setup with %s %s %s", device_type, device_subtype, config_file);
|
||||||
ds->dev_type = SIMDEV_UNKNOWN;
|
ds->dev_type = SIMDEV_UNKNOWN;
|
||||||
|
|
||||||
error = strtodev(device_type, device_subtype, ds);
|
error = strtodev(device_type, device_subtype, ds);
|
||||||
|
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
if (error != MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
|
|
@ -246,6 +305,8 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||||
{
|
{
|
||||||
if (device_settings != NULL)
|
if (device_settings != NULL)
|
||||||
|
|
@ -264,6 +325,75 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
ds->tachsettings.use_pulses = false;
|
ds->tachsettings.use_pulses = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
|
||||||
|
{
|
||||||
|
if (device_settings != NULL)
|
||||||
|
{
|
||||||
|
ds->usbdevsettings.value0 = 0;
|
||||||
|
ds->usbdevsettings.value1 = 1;
|
||||||
|
|
||||||
|
const char* temp;
|
||||||
|
int found = config_setting_lookup_string(device_settings, "devpath", &temp);
|
||||||
|
if (found == 0)
|
||||||
|
{
|
||||||
|
ds->usbdevsettings.dev = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ds->usbdevsettings.dev = strdup(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
config_setting_lookup_int(device_settings, "value0", &ds->usbdevsettings.value0);
|
||||||
|
config_setting_lookup_int(device_settings, "value1", &ds->usbdevsettings.value1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND) {
|
||||||
|
const char* effect;
|
||||||
|
config_setting_lookup_string(device_settings, "effect", &effect);
|
||||||
|
strtoeffecttype(effect, ds);
|
||||||
|
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_WHEELLOCK)
|
||||||
|
{
|
||||||
|
gettyre(device_settings, ds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds->dev_type == SIMDEV_SOUND)
|
||||||
|
{
|
||||||
|
slogi("reading configured sound device settings");
|
||||||
|
ds->sounddevsettings.frequency = -1;
|
||||||
|
ds->sounddevsettings.volume = -1;
|
||||||
|
ds->sounddevsettings.lowbound_frequency = -1;
|
||||||
|
ds->sounddevsettings.upperbound_frequency = -1;
|
||||||
|
ds->sounddevsettings.pan = 0;
|
||||||
|
ds->sounddevsettings.duration = 2.0;
|
||||||
|
if (ds->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, "frequency", &ds->sounddevsettings.frequency);
|
||||||
|
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
|
||||||
|
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||||
|
|
||||||
|
const char* temp;
|
||||||
|
int found = 0;
|
||||||
|
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
||||||
|
if (found == 0)
|
||||||
|
{
|
||||||
|
ds->sounddevsettings.dev = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ds->sounddevsettings.dev = strdup(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
||||||
{
|
{
|
||||||
if (device_settings != NULL)
|
if (device_settings != NULL)
|
||||||
|
|
@ -286,7 +416,22 @@ int settingsfree(DeviceSettings ds)
|
||||||
{
|
{
|
||||||
free(ds.serialdevsettings.portdev);
|
free(ds.serialdevsettings.portdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (ds.dev_type == SIMDEV_SOUND)
|
||||||
|
{
|
||||||
|
if (ds.sounddevsettings.dev != NULL)
|
||||||
|
{
|
||||||
|
free(ds.sounddevsettings.dev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ds.dev_type == SIMDEV_USB)
|
||||||
|
{
|
||||||
|
if (ds.usbdevsettings.dev != NULL )
|
||||||
|
{
|
||||||
|
free(ds.usbdevsettings.dev);
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef _CONFIGHELPER_H
|
#ifndef _CONFIGHELPER_H
|
||||||
#define _CONFIGHELPER_H
|
#define _CONFIGHELPER_H
|
||||||
|
|
||||||
|
#include <pulse/channelmap.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
@ -21,10 +22,9 @@ typedef enum
|
||||||
{
|
{
|
||||||
SIMDEVTYPE_UNKNOWN = 0,
|
SIMDEVTYPE_UNKNOWN = 0,
|
||||||
SIMDEVTYPE_TACHOMETER = 1,
|
SIMDEVTYPE_TACHOMETER = 1,
|
||||||
SIMDEVTYPE_SHIFTLIGHTS = 2,
|
SIMDEVTYPE_USBHAPTIC = 2,
|
||||||
SIMDEVTYPE_SIMWIND = 3,
|
SIMDEVTYPE_SHIFTLIGHTS = 3,
|
||||||
SIMDEVTYPE_ENGINESOUND = 4,
|
SIMDEVTYPE_SIMWIND = 4
|
||||||
SIMDEVTYPE_GEARSOUND = 5
|
|
||||||
}
|
}
|
||||||
DeviceSubType;
|
DeviceSubType;
|
||||||
|
|
||||||
|
|
@ -40,6 +40,16 @@ typedef enum
|
||||||
}
|
}
|
||||||
SimulatorUpdate;
|
SimulatorUpdate;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
EFFECT_ENGINERPM = 0,
|
||||||
|
EFFECT_GEARSHIFT = 1,
|
||||||
|
EFFECT_ABSBRAKES = 2,
|
||||||
|
EFFECT_TYRESLIP = 3,
|
||||||
|
EFFECT_WHEELLOCK = 4
|
||||||
|
}
|
||||||
|
VibrationEffectType;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
MONOCOQUE_ERROR_NONE = 0,
|
MONOCOQUE_ERROR_NONE = 0,
|
||||||
|
|
@ -51,6 +61,18 @@ typedef enum
|
||||||
}
|
}
|
||||||
MonocoqueError;
|
MonocoqueError;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FRONTLEFT = 0,
|
||||||
|
FRONTRIGHT = 1,
|
||||||
|
REARLEFT = 2,
|
||||||
|
REARRIGHT = 3,
|
||||||
|
FRONTS = 4,
|
||||||
|
REARS = 5,
|
||||||
|
ALLFOUR = 6
|
||||||
|
}
|
||||||
|
MonocoqueTyreIdentifier;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ProgramAction program_action;
|
ProgramAction program_action;
|
||||||
|
|
@ -74,13 +96,38 @@ typedef struct
|
||||||
}
|
}
|
||||||
SerialDeviceSettings;
|
SerialDeviceSettings;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int frequency;
|
||||||
|
int volume;
|
||||||
|
int lowbound_frequency;
|
||||||
|
int upperbound_frequency;
|
||||||
|
int pan;
|
||||||
|
double duration;
|
||||||
|
char* dev;
|
||||||
|
}
|
||||||
|
SoundDeviceSettings;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int value0;
|
||||||
|
int value1;
|
||||||
|
char* dev;
|
||||||
|
}
|
||||||
|
USBDeviceSettings;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
DeviceType dev_type;
|
DeviceType dev_type;
|
||||||
DeviceSubType dev_subtype;
|
DeviceSubType dev_subtype;
|
||||||
|
VibrationEffectType effect_type;
|
||||||
|
// union?
|
||||||
TachometerSettings tachsettings;
|
TachometerSettings tachsettings;
|
||||||
SerialDeviceSettings serialdevsettings;
|
SerialDeviceSettings serialdevsettings;
|
||||||
|
SoundDeviceSettings sounddevsettings;
|
||||||
|
USBDeviceSettings usbdevsettings;
|
||||||
|
MonocoqueTyreIdentifier tyre;
|
||||||
}
|
}
|
||||||
DeviceSettings;
|
DeviceSettings;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
else if (nerrors3==0)
|
else if (nerrors3==0)
|
||||||
{
|
{
|
||||||
p->program_action = A_TEST;
|
p->program_action = A_TEST;
|
||||||
|
p->verbosity_count = arg_verbosity3->count;
|
||||||
exitcode = E_SUCCESS_AND_DO;
|
exitcode = E_SUCCESS_AND_DO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,14 @@
|
||||||
#include "gameloop/gameloop.h"
|
#include "gameloop/gameloop.h"
|
||||||
#include "gameloop/tachconfig.h"
|
#include "gameloop/tachconfig.h"
|
||||||
#include "devices/simdevice.h"
|
#include "devices/simdevice.h"
|
||||||
|
#include "devices/sound.h"
|
||||||
#include "helper/parameters.h"
|
#include "helper/parameters.h"
|
||||||
#include "helper/dirhelper.h"
|
#include "helper/dirhelper.h"
|
||||||
#include "helper/confighelper.h"
|
#include "helper/confighelper.h"
|
||||||
#include "simulatorapi/simapi/simapi/simdata.h"
|
#include "simulatorapi/simapi/simapi/simdata.h"
|
||||||
#include "slog/slog.h"
|
#include "slog/slog.h"
|
||||||
|
|
||||||
|
|
||||||
int create_dir(char* dir)
|
int create_dir(char* dir)
|
||||||
{
|
{
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
|
|
@ -149,9 +151,9 @@ int main(int argc, char** argv)
|
||||||
DeviceSettings ds[configureddevices];
|
DeviceSettings ds[configureddevices];
|
||||||
slogi("found %i devices in configuration", configureddevices);
|
slogi("found %i devices in configuration", configureddevices);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
error = MONOCOQUE_ERROR_NONE;
|
||||||
while (i<configureddevices)
|
while (i<configureddevices)
|
||||||
{
|
{
|
||||||
error = MONOCOQUE_ERROR_NONE;
|
|
||||||
DeviceSettings settings;
|
DeviceSettings settings;
|
||||||
|
|
||||||
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
|
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
|
||||||
|
|
@ -162,6 +164,9 @@ int main(int argc, char** argv)
|
||||||
config_setting_lookup_string(config_device, "type", &device_subtype);
|
config_setting_lookup_string(config_device, "type", &device_subtype);
|
||||||
config_setting_lookup_string(config_device, "config", &device_config_file);
|
config_setting_lookup_string(config_device, "config", &device_config_file);
|
||||||
|
|
||||||
|
//slogt("device type: %s", device_type);
|
||||||
|
//slogt("device sub type: %s", device_subtype);
|
||||||
|
//slogt("device config file: %s", device_config_file);
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
error = devsetup(device_type, device_subtype, device_config_file, ms, &settings, config_device);
|
error = devsetup(device_type, device_subtype, device_config_file, ms, &settings, config_device);
|
||||||
|
|
@ -179,18 +184,22 @@ int main(int argc, char** argv)
|
||||||
i = 0;
|
i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
error = MONOCOQUE_ERROR_NONE;
|
error = MONOCOQUE_ERROR_NONE;
|
||||||
|
|
||||||
|
setupsound();
|
||||||
SimDevice* devices = malloc(numdevices * sizeof(SimDevice));
|
SimDevice* devices = malloc(numdevices * sizeof(SimDevice));
|
||||||
int initdevices = devinit(devices, configureddevices, ds);
|
int initdevices = devinit(devices, configureddevices, ds);
|
||||||
|
|
||||||
if (p->program_action == A_PLAY)
|
if (p->program_action == A_PLAY)
|
||||||
{
|
{
|
||||||
//slogi("running monocoque in gameloop mode..");
|
slogi("running monocoque in gameloop mode..");
|
||||||
//error = strtogame(p->sim_string, ms);
|
//error = strtogame(p->sim_string, ms);
|
||||||
//if (error != MONOCOQUE_ERROR_NONE)
|
//if (error != MONOCOQUE_ERROR_NONE)
|
||||||
//{
|
//{
|
||||||
// goto cleanup_final;
|
// goto cleanup_final;
|
||||||
//}
|
//}
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
pa_threaded_mainloop_unlock(mainloop);
|
||||||
|
#endif
|
||||||
|
|
||||||
error = looper(devices, initdevices, p);
|
error = looper(devices, initdevices, p);
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
|
|
@ -205,6 +214,11 @@ int main(int argc, char** argv)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
slogi("running monocoque in test mode...");
|
slogi("running monocoque in test mode...");
|
||||||
|
|
||||||
|
#ifdef USE_PULSEAUDIO
|
||||||
|
pa_threaded_mainloop_unlock(mainloop);
|
||||||
|
#endif
|
||||||
|
|
||||||
error = tester(devices, initdevices);
|
error = tester(devices, initdevices);
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit ee41c498ee24c410bc551cf09ea68a9fbde0cee7
|
Subproject commit 231e64e1190686dad77fcaf2e9e5e9bc8d831274
|
||||||
Loading…
Reference in New Issue