Compare commits
No commits in common. "usbhaptic" and "master" have entirely different histories.
33
README.md
33
README.md
|
|
@ -29,7 +29,7 @@ Cross Platform device manager for driving and flight simulators, for use with co
|
|||
- argtable2
|
||||
- libconfig
|
||||
- [slog](https://github.com/kala13x/slog) (static)
|
||||
- [simshmbridge](https://github.com/spacefreak18/simshmbridge) - for sims that need shared memory mapping like AC and Project Cars related.
|
||||
- [wine-linux-shm-adapter](https://github.com/spacefreak18/simshmbridge) - for sims that need shared memory mapping like AC.
|
||||
- [simapi](https://github.com/spacefreak18/simapi)
|
||||
|
||||
## Building
|
||||
|
|
@ -51,37 +51,10 @@ 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
|
||||
|
||||
### Setting up Your Arduino Device
|
||||
|
||||
### Static Analysis
|
||||
```
|
||||
mkdir build; cd build
|
||||
|
|
|
|||
|
|
@ -1,166 +0,0 @@
|
|||
# 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
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#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,24 +1,14 @@
|
|||
#include <FastLED.h>
|
||||
#include "shiftlights.h"
|
||||
#include "simdata.h"
|
||||
|
||||
#define SIMDATA_SIZE sizeof(ShiftLightsData)
|
||||
#define SIMDATA_SIZE sizeof(SimData)
|
||||
|
||||
#define LED_PIN 7
|
||||
#define NUM_LEDS 6
|
||||
#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];
|
||||
ShiftLightsData sd;
|
||||
SimData sd;
|
||||
int maxrpm = 0;
|
||||
int rpm = 0;
|
||||
int numlights = NUM_LEDS;
|
||||
|
|
@ -39,8 +29,11 @@ void setup()
|
|||
}
|
||||
FastLED.clear();
|
||||
|
||||
sd.rpm = 0;
|
||||
sd.rpms = 0;
|
||||
sd.maxrpm = 6500;
|
||||
sd.altitude = 10;
|
||||
sd.pulses = 40000;
|
||||
sd.velocity = 10;
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
|
@ -52,10 +45,12 @@ void loop()
|
|||
{
|
||||
Serial.readBytes(buff, SIMDATA_SIZE);
|
||||
memcpy(&sd, &buff, SIMDATA_SIZE);
|
||||
rpm = sd.rpm;
|
||||
rpm = sd.rpms;
|
||||
maxrpm = sd.maxrpm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
while (l < numlights)
|
||||
{
|
||||
lights[l] = 0;
|
||||
|
|
@ -80,15 +75,15 @@ void loop()
|
|||
|
||||
if (l >= numlights / 2)
|
||||
{
|
||||
leds[l] = CRGB ( COLOR1A, COLOR1B, COLOR1C);
|
||||
leds[l] = CRGB ( 0, 0, 255);
|
||||
}
|
||||
if (l < numlights / 2)
|
||||
{
|
||||
leds[l] = CRGB ( COLOR2A, COLOR2B, COLOR2C);
|
||||
leds[l] = CRGB ( 0, 255, 0);
|
||||
}
|
||||
if (l == numlights - 1)
|
||||
{
|
||||
leds[l] = CRGB ( COLOR3A, COLOR3B, COLOR3C);
|
||||
leds[l] = CRGB ( 255, 0, 0);
|
||||
}
|
||||
if (lights[l] <= 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,166 +0,0 @@
|
|||
# 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
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#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 "simwind.h"
|
||||
#include "simdata.h"
|
||||
|
||||
#define BYTE_SIZE sizeof(SimWindData)
|
||||
#define BYTE_SIZE sizeof(SimData)
|
||||
#define KPHTOMPH .621317
|
||||
#define FANPOWER .6
|
||||
|
||||
|
||||
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
||||
|
||||
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
|
||||
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(3);
|
||||
|
||||
SimWindData sd;
|
||||
SimData sd;
|
||||
int velocity = 0;
|
||||
|
||||
void setup() {
|
||||
|
|
@ -19,6 +19,10 @@ void setup() {
|
|||
Serial.println("Could not find Motor Shield. Check wiring.");
|
||||
while (1);
|
||||
}
|
||||
sd.rpms = 0;
|
||||
sd.maxrpm = 6500;
|
||||
sd.altitude = 10;
|
||||
sd.pulses = 40000;
|
||||
sd.velocity = 10;
|
||||
|
||||
myMotor1->setSpeed(0);
|
||||
|
|
@ -42,6 +46,6 @@ void loop() {
|
|||
{
|
||||
v = 255;
|
||||
}
|
||||
myMotor1->setSpeed(v*FANPOWER);
|
||||
myMotor2->setSpeed(v*FANPOWER);
|
||||
myMotor1->setSpeed(v);
|
||||
myMotor2->setSpeed(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ set(devices_source_files
|
|||
serialdevice.c
|
||||
tachdevice.h
|
||||
tachdevice.c
|
||||
usbhapticdevice.h
|
||||
usbhapticdevice.c
|
||||
sound.h
|
||||
sound.c
|
||||
usb/revburner.h
|
||||
|
|
|
|||
|
|
@ -6,42 +6,19 @@
|
|||
#include "arduino.h"
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
#define arduino_timeout 5000
|
||||
#define arduino_timeout 2000
|
||||
|
||||
int arduino_update(SerialDevice* serialdevice, void* data, size_t size)
|
||||
int arduino_update(SerialDevice* serialdevice, SimData* simdata)
|
||||
{
|
||||
int result = 1;
|
||||
if (serialdevice->port)
|
||||
{
|
||||
slogt("copying %i bytes to arduino device", size);
|
||||
result = check(sp_blocking_write(serialdevice->port, data, size, arduino_timeout));
|
||||
result = check(sp_blocking_write(serialdevice->port, simdata, sizeof(SimData), arduino_timeout));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
slogi("initializing arduino serial device...");
|
||||
|
|
@ -103,4 +80,3 @@ int check(enum sp_return result)
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
#include "../simdevice.h"
|
||||
#include "../serialdevice.h"
|
||||
|
||||
|
||||
int arduino_update(SerialDevice* serialdevice, void* data, size_t size);
|
||||
int arduino_update(SerialDevice* serialdevice, SimData* simdata);
|
||||
int arduino_init(SerialDevice* serialdevice, const char* portdev);
|
||||
int arduino_free(SerialDevice* serialdevice);
|
||||
int check(enum sp_return result);
|
||||
|
|
|
|||
|
|
@ -15,45 +15,10 @@ int serialdev_update(SimDevice* this, SimData* simdata)
|
|||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
|
||||
|
||||
|
||||
arduino_update(serialdevice, simdata, sizeof(SimData));
|
||||
arduino_update(serialdevice, simdata);
|
||||
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)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
|
|
@ -78,8 +43,6 @@ int serialdev_init(SerialDevice* serialdevice, const char* portdev)
|
|||
}
|
||||
|
||||
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) {
|
||||
|
||||
|
|
@ -90,20 +53,6 @@ SerialDevice* new_serial_device(DeviceSettings* ds) {
|
|||
this->m.derived = this;
|
||||
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);
|
||||
|
||||
if (error != 0)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,5 @@
|
|||
|
||||
#include <libserialport.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ARDUINODEV__SHIFTLIGHTS = 0,
|
||||
ARDUINODEV__SIMWIND = 1,
|
||||
}
|
||||
SerialDeviceType;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_USB;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
@ -79,7 +78,6 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SOUND;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@
|
|||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
||||
#include "../../arduino/simwind/simwind.h"
|
||||
#include "../../arduino/shiftlights/shiftlights.h"
|
||||
|
||||
typedef struct SimDevice SimDevice;
|
||||
|
||||
|
|
@ -23,7 +21,7 @@ struct SimDevice
|
|||
int id;
|
||||
bool initialized;
|
||||
DeviceType type;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -45,17 +43,10 @@ typedef struct
|
|||
int id;
|
||||
SerialType type;
|
||||
struct sp_port* port;
|
||||
SerialDeviceType devicetype;
|
||||
union
|
||||
{
|
||||
SimWindData simwinddata;
|
||||
ShiftLightsData shiftlightsdata;
|
||||
} u;
|
||||
}
|
||||
SerialDevice;
|
||||
|
||||
int arduino_shiftlights_update(SimDevice* this, SimData* simdata);
|
||||
int arduino_simwind_update(SimDevice* this, SimData* simdata);
|
||||
int serialdev_update(SimDevice* this, SimData* simdata);
|
||||
int serialdev_free(SimDevice* this);
|
||||
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds);
|
||||
|
|
@ -64,8 +55,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds);
|
|||
typedef enum
|
||||
{
|
||||
USBDEV_UNKNOWN = 0,
|
||||
USBDEV_TACHOMETER = 1,
|
||||
USBDEV_GENERICHAPTIC = 2
|
||||
USBDEV_TACHOMETER = 1
|
||||
}
|
||||
USBType;
|
||||
|
||||
|
|
@ -77,7 +67,6 @@ typedef struct
|
|||
union
|
||||
{
|
||||
TachDevice tachdevice;
|
||||
USBGenericHapticDevice hapticdevice;
|
||||
} u;
|
||||
}
|
||||
USBDevice;
|
||||
|
|
@ -107,7 +96,6 @@ SoundDevice;
|
|||
|
||||
int sounddev_engine_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);
|
||||
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds);
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
|||
pa_stream_set_state_callback(stream, stream_state_cb, mainloop);
|
||||
|
||||
|
||||
if (sounddevice->effecttype == EFFECT_GEARSHIFT)
|
||||
if (sounddevice->effecttype == SOUNDEFFECT_GEARSHIFT)
|
||||
{
|
||||
pa_stream_set_write_callback(stream, gear_sound_stream, &sounddevice->sounddata);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,55 +38,6 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
|||
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)
|
||||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
|
@ -128,7 +79,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
|
||||
const char* streamname= "Engine";
|
||||
switch (sounddevice->effecttype) {
|
||||
case (EFFECT_GEARSHIFT):
|
||||
case (SOUNDEFFECT_GEARSHIFT):
|
||||
|
||||
sounddevice->sounddata.last_gear = 0;
|
||||
//sounddevice->sounddata.pitch = 500;
|
||||
|
|
@ -139,16 +90,6 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
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;
|
||||
}
|
||||
|
||||
#ifdef USE_PULSEAUDIO
|
||||
|
|
@ -164,8 +105,6 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
|
||||
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 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) {
|
||||
|
||||
|
|
@ -175,28 +114,18 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
|
|||
this->m.free = &simdevfree;
|
||||
this->m.derived = this;
|
||||
|
||||
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type);
|
||||
switch (ds->effect_type) {
|
||||
case (EFFECT_ENGINERPM):
|
||||
this->effecttype = EFFECT_ENGINERPM;
|
||||
slogt("Attempting to configure sound device with subtype: %i", ds->dev_subtype);
|
||||
switch (ds->dev_subtype) {
|
||||
case (SIMDEVTYPE_ENGINESOUND):
|
||||
this->effecttype = SOUNDEFFECT_ENGINERPM;
|
||||
this->m.vtable = &engine_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for engine vibrations.");
|
||||
break;
|
||||
case (EFFECT_GEARSHIFT):
|
||||
this->effecttype = EFFECT_GEARSHIFT;
|
||||
case (SIMDEVTYPE_GEARSOUND):
|
||||
this->effecttype = SOUNDEFFECT_GEARSHIFT;
|
||||
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for gear shift vibrations.");
|
||||
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;
|
||||
}
|
||||
|
||||
slogt("Attempting to use device %s", ds->sounddevsettings.dev);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,13 @@ typedef enum
|
|||
}
|
||||
SoundType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SOUNDEFFECT_ENGINERPM = 0,
|
||||
SOUNDEFFECT_GEARSHIFT = 1
|
||||
}
|
||||
VibrationEffectType;
|
||||
|
||||
#define MAX_TABLE_SIZE (6000)
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,9 +19,6 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
|||
case USBDEV_TACHOMETER :
|
||||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -31,16 +28,12 @@ int usbdev_free(SimDevice* this)
|
|||
{
|
||||
USBDevice* usbdevice = (void *) this->derived;
|
||||
|
||||
slogt("Usb device free");
|
||||
switch ( usbdevice->type )
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
tachdev_free(&usbdevice->u.tachdevice);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
free(usbdevice);
|
||||
|
|
@ -53,16 +46,13 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
|||
slogi("initializing usb device...");
|
||||
int error = 0;
|
||||
|
||||
//usbdevice->type = USBDEV_TACHOMETER;
|
||||
usbdevice->type = USBDEV_TACHOMETER;
|
||||
switch ( usbdevice->type )
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
error = tachdev_init(&usbdevice->u.tachdevice, ds);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
|
|
@ -79,12 +69,6 @@ USBDevice* new_usb_device(DeviceSettings* ds) {
|
|||
this->m.derived = this;
|
||||
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);
|
||||
|
||||
if (error != 0)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,5 @@
|
|||
#define _USBDEVICE_H
|
||||
|
||||
#include "tachdevice.h"
|
||||
#include "usbhapticdevice.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
#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;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
#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,7 +6,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <poll.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "gameloop.h"
|
||||
#include "../helper/parameters.h"
|
||||
|
|
@ -18,19 +17,6 @@
|
|||
|
||||
#define DEFAULT_UPDATE_RATE 240.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)
|
||||
{
|
||||
|
|
@ -184,13 +170,27 @@ int showstats(SimData* simdata)
|
|||
|
||||
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 pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||
double update_rate = DEFAULT_UPDATE_RATE;
|
||||
char ch;
|
||||
int t=0;
|
||||
int s=0;
|
||||
go2 = true;
|
||||
while (go2 == true && simdata->simstatus > 1)
|
||||
bool go = true;
|
||||
while (go == true && simdata->simstatus > 1)
|
||||
{
|
||||
simdatamap(simdata, simmap, p->sim);
|
||||
showstats(simdata);
|
||||
|
|
@ -210,7 +210,7 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
|
|||
scanf("%c", &ch);
|
||||
if(ch == 'q')
|
||||
{
|
||||
go2 = false;
|
||||
go = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -229,12 +229,6 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
|
|||
|
||||
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));
|
||||
SimMap* simmap = malloc(sizeof(SimMap));
|
||||
|
|
@ -250,28 +244,23 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||
|
||||
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||
|
||||
p->simon = false;
|
||||
double update_rate = SIM_CHECK_RATE;
|
||||
go = true;
|
||||
int go = true;
|
||||
while (go == true)
|
||||
{
|
||||
p->simon = false;
|
||||
|
||||
|
||||
|
||||
|
||||
if (p->simon == false)
|
||||
{
|
||||
getSim(simdata, simmap, &p->simon, &p->sim);
|
||||
|
||||
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);
|
||||
|
||||
if (p->simon == true)
|
||||
{
|
||||
clilooper(devices, numdevices, p, simdata, simmap);
|
||||
}
|
||||
if (p->simon == true)
|
||||
|
|
@ -281,9 +270,7 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||
sleep(2);
|
||||
}
|
||||
|
||||
if (poll(&mypoll, 1, 1000.0/update_rate) )
|
||||
{
|
||||
if (go != false )
|
||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||
{
|
||||
scanf("%c", &ch);
|
||||
if(ch == 'q')
|
||||
|
|
@ -292,7 +279,6 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
|
|
@ -323,11 +309,6 @@ int tester(SimDevice* devices, int numdevices)
|
|||
simdata->velocity = 16;
|
||||
simdata->rpms = 100;
|
||||
simdata->maxrpm = 8000;
|
||||
simdata->abs = 0;
|
||||
simdata->wheelslip[0] = 0;
|
||||
simdata->wheelslip[1] = 0;
|
||||
simdata->wheelslip[2] = 0;
|
||||
simdata->wheelslip[3] = 0;
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting rpms to 1000\n");
|
||||
|
|
@ -338,30 +319,6 @@ int tester(SimDevice* devices, int numdevices)
|
|||
}
|
||||
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");
|
||||
simdata->gear = 2;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
|
|
|
|||
|
|
@ -52,31 +52,6 @@ int strtogame(const char* game, MonocoqueSettings* ms)
|
|||
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)
|
||||
{
|
||||
ds->is_valid = false;
|
||||
|
|
@ -89,11 +64,6 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
|||
ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
|
||||
break;
|
||||
}
|
||||
if (strcicmp(device_subtype, "UsbHaptic") == 0 || strcicmp(device_subtype, "Haptic") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_USBHAPTIC;
|
||||
break;
|
||||
}
|
||||
case SIMDEV_SERIAL:
|
||||
if (strcicmp(device_subtype, "ShiftLights") == 0)
|
||||
{
|
||||
|
|
@ -106,8 +76,21 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
|||
break;
|
||||
}
|
||||
case SIMDEV_SOUND:
|
||||
ds->is_valid = true;
|
||||
if (strcicmp(device_subtype, "Engine") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_ENGINESOUND;
|
||||
break;
|
||||
}
|
||||
if (strcicmp(device_subtype, "Gear") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_GEARSOUND;
|
||||
break;
|
||||
}
|
||||
if (strcicmp(device_subtype, "ABS") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_ABSBRAKES;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
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);
|
||||
|
|
@ -240,40 +223,6 @@ int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
|||
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)
|
||||
{
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||
|
|
@ -290,7 +239,6 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
ds->dev_type = SIMDEV_UNKNOWN;
|
||||
|
||||
error = strtodev(device_type, device_subtype, ds);
|
||||
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
return error;
|
||||
|
|
@ -305,59 +253,6 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||
{
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
config_setting_lookup_int(device_settings, "granularity", &ds->tachsettings.granularity);
|
||||
if (ds->tachsettings.granularity < 0 || ds->tachsettings.granularity > 4 || ds->tachsettings.granularity == 3)
|
||||
{
|
||||
slogd("No or invalid valid set for tachometer granularity, setting to 1");
|
||||
ds->tachsettings.granularity = 1;
|
||||
}
|
||||
slogi("Tachometer granularity set to %i", ds->tachsettings.granularity);
|
||||
}
|
||||
ds->tachsettings.use_pulses = true;
|
||||
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
|
||||
{
|
||||
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");
|
||||
|
|
@ -367,7 +262,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
ds->sounddevsettings.upperbound_frequency = -1;
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.duration = 2.0;
|
||||
if (ds->effect_type == EFFECT_GEARSHIFT)
|
||||
if (ds->dev_subtype == SIMDEVTYPE_GEARSOUND)
|
||||
{
|
||||
ds->sounddevsettings.duration = .125;
|
||||
}
|
||||
|
|
@ -392,7 +287,26 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||
{
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
config_setting_lookup_int(device_settings, "granularity", &ds->tachsettings.granularity);
|
||||
if (ds->tachsettings.granularity < 0 || ds->tachsettings.granularity > 4 || ds->tachsettings.granularity == 3)
|
||||
{
|
||||
slogd("No or invalid valid set for tachometer granularity, setting to 1");
|
||||
ds->tachsettings.granularity = 1;
|
||||
}
|
||||
slogi("Tachometer granularity set to %i", ds->tachsettings.granularity);
|
||||
}
|
||||
ds->tachsettings.use_pulses = true;
|
||||
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
|
||||
{
|
||||
ds->tachsettings.use_pulses = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
||||
{
|
||||
|
|
@ -425,13 +339,5 @@ int settingsfree(DeviceSettings ds)
|
|||
free(ds.sounddevsettings.dev);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds.dev_type == SIMDEV_USB)
|
||||
{
|
||||
if (ds.usbdevsettings.dev != NULL )
|
||||
{
|
||||
free(ds.usbdevsettings.dev);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef _CONFIGHELPER_H
|
||||
#define _CONFIGHELPER_H
|
||||
|
||||
#include <pulse/channelmap.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
@ -22,9 +21,11 @@ typedef enum
|
|||
{
|
||||
SIMDEVTYPE_UNKNOWN = 0,
|
||||
SIMDEVTYPE_TACHOMETER = 1,
|
||||
SIMDEVTYPE_USBHAPTIC = 2,
|
||||
SIMDEVTYPE_SHIFTLIGHTS = 3,
|
||||
SIMDEVTYPE_SIMWIND = 4
|
||||
SIMDEVTYPE_SHIFTLIGHTS = 2,
|
||||
SIMDEVTYPE_SIMWIND = 3,
|
||||
SIMDEVTYPE_ENGINESOUND = 4,
|
||||
SIMDEVTYPE_GEARSOUND = 5,
|
||||
SIMDEVTYPE_ABSBRAKES = 6
|
||||
}
|
||||
DeviceSubType;
|
||||
|
||||
|
|
@ -40,16 +41,6 @@ typedef enum
|
|||
}
|
||||
SimulatorUpdate;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EFFECT_ENGINERPM = 0,
|
||||
EFFECT_GEARSHIFT = 1,
|
||||
EFFECT_ABSBRAKES = 2,
|
||||
EFFECT_TYRESLIP = 3,
|
||||
EFFECT_WHEELLOCK = 4
|
||||
}
|
||||
VibrationEffectType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MONOCOQUE_ERROR_NONE = 0,
|
||||
|
|
@ -61,18 +52,6 @@ typedef enum
|
|||
}
|
||||
MonocoqueError;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FRONTLEFT = 0,
|
||||
FRONTRIGHT = 1,
|
||||
REARLEFT = 2,
|
||||
REARRIGHT = 3,
|
||||
FRONTS = 4,
|
||||
REARS = 5,
|
||||
ALLFOUR = 6
|
||||
}
|
||||
MonocoqueTyreIdentifier;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ProgramAction program_action;
|
||||
|
|
@ -108,26 +87,14 @@ typedef struct
|
|||
}
|
||||
SoundDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int value0;
|
||||
int value1;
|
||||
char* dev;
|
||||
}
|
||||
USBDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool is_valid;
|
||||
DeviceType dev_type;
|
||||
DeviceSubType dev_subtype;
|
||||
VibrationEffectType effect_type;
|
||||
// union?
|
||||
TachometerSettings tachsettings;
|
||||
SerialDeviceSettings serialdevsettings;
|
||||
SoundDeviceSettings sounddevsettings;
|
||||
USBDeviceSettings usbdevsettings;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
}
|
||||
DeviceSettings;
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 231e64e1190686dad77fcaf2e9e5e9bc8d831274
|
||||
Subproject commit c77e96339caf1eb79479d89ce342161ad83ca70e
|
||||
Loading…
Reference in New Issue