Compare commits
10 Commits
49144f9429
...
8065929618
| Author | SHA1 | Date |
|---|---|---|
|
|
8065929618 | |
|
|
5211753a7e | |
|
|
d2ff88aabb | |
|
|
978c607d66 | |
|
|
0d4a1fae1c | |
|
|
a50b68f3b6 | |
|
|
d8df1890b3 | |
|
|
af7077b07a | |
|
|
61825e4ddf | |
|
|
5eb136312b |
|
|
@ -6,10 +6,16 @@ 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 = "Shaker"
|
type = "Engine"
|
||||||
devid = "98FD:83AC";
|
devid = "98FD:83AC"; },
|
||||||
config = "shaker1.config"; },
|
{ device = "Sound";
|
||||||
|
type = "Gear"
|
||||||
|
devid = "98FD:83AC"; },
|
||||||
{ device = "Serial";
|
{ device = "Serial";
|
||||||
type = "ShiftLights";
|
type = "ShiftLights";
|
||||||
config = "None";
|
config = "None";
|
||||||
devpath = "/dev/ttyACM0"; } );
|
devpath = "/dev/ttyACM0"; } ),
|
||||||
|
{ device = "Serial";
|
||||||
|
type = "SimWind";
|
||||||
|
config = "None";
|
||||||
|
devpath = "/dev/ttyACM1"; } );
|
||||||
|
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
#include <FastLED.h>
|
|
||||||
#include "../../monocoque/simulatorapi/simdata.h"
|
|
||||||
|
|
||||||
#define BYTE_SIZE sizeof(SimData)
|
|
||||||
|
|
||||||
#define LED_PIN 7
|
|
||||||
#define NUM_LEDS 6
|
|
||||||
|
|
||||||
CRGB leds[NUM_LEDS];
|
|
||||||
SimData sd;
|
|
||||||
int maxrpm = 0;
|
|
||||||
int rpm = 0;
|
|
||||||
int numlights = NUM_LEDS;
|
|
||||||
int pin = LED_PIN;
|
|
||||||
int lights[6];
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
Serial.begin(9600);
|
|
||||||
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
|
|
||||||
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
|
|
||||||
FastLED.setBrightness(40);
|
|
||||||
for (int i = 0; i < numlights; i++)
|
|
||||||
{
|
|
||||||
leds[i] = CRGB ( 0, 0, 0);
|
|
||||||
lights[i] = 0;
|
|
||||||
}
|
|
||||||
FastLED.clear();
|
|
||||||
|
|
||||||
sd.rpms = 0;
|
|
||||||
sd.maxrpm = 6500;
|
|
||||||
sd.altitude = 10;
|
|
||||||
sd.pulses = 40000;
|
|
||||||
sd.velocity = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
int l = 0;
|
|
||||||
char buff[BYTE_SIZE];
|
|
||||||
|
|
||||||
if (Serial.available() >= BYTE_SIZE) {
|
|
||||||
Serial.readBytes(buff, BYTE_SIZE);
|
|
||||||
memcpy(&sd, &buff, BYTE_SIZE);
|
|
||||||
rpm = sd.rpms;
|
|
||||||
maxrpm = sd.maxrpm;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while (l < numlights)
|
|
||||||
{
|
|
||||||
lights[l] = 0;
|
|
||||||
l++;
|
|
||||||
}
|
|
||||||
l = -1;
|
|
||||||
int rpmlights = 0;
|
|
||||||
while (rpm > rpmlights)
|
|
||||||
{
|
|
||||||
if (l>=0)
|
|
||||||
{
|
|
||||||
lights[l] = 1;
|
|
||||||
}
|
|
||||||
l++;
|
|
||||||
rpmlights = rpmlights + (((maxrpm-250)/numlights));
|
|
||||||
}
|
|
||||||
|
|
||||||
l = 0;
|
|
||||||
FastLED.clear();
|
|
||||||
while (l < numlights)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (l >= numlights / 2)
|
|
||||||
{
|
|
||||||
leds[l] = CRGB ( 0, 0, 255);
|
|
||||||
}
|
|
||||||
if (l < numlights / 2)
|
|
||||||
{
|
|
||||||
leds[l] = CRGB ( 0, 255, 0);
|
|
||||||
}
|
|
||||||
if (l == numlights - 1)
|
|
||||||
{
|
|
||||||
leds[l] = CRGB ( 255, 0, 0);
|
|
||||||
}
|
|
||||||
if (lights[l] <= 0)
|
|
||||||
{
|
|
||||||
leds[l] = CRGB ( 0, 0, 0);
|
|
||||||
}
|
|
||||||
FastLED.show();
|
|
||||||
l++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include <Adafruit_MotorShield.h>
|
||||||
|
#include "../../monocoque/simulatorapi/simdata.h"
|
||||||
|
|
||||||
|
#define BYTE_SIZE sizeof(SimData)
|
||||||
|
#define KPHTOMPH .621317
|
||||||
|
|
||||||
|
|
||||||
|
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
||||||
|
|
||||||
|
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
|
||||||
|
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(3);
|
||||||
|
|
||||||
|
SimData sd;
|
||||||
|
int velocity = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
if (!AFMS.begin()) {
|
||||||
|
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);
|
||||||
|
myMotor1->run(FORWARD);
|
||||||
|
|
||||||
|
myMotor2->setSpeed(0);
|
||||||
|
myMotor2->run(FORWARD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
char buff[BYTE_SIZE];
|
||||||
|
|
||||||
|
if (Serial.available() >= BYTE_SIZE)
|
||||||
|
{
|
||||||
|
Serial.readBytes(buff, BYTE_SIZE);
|
||||||
|
memcpy(&sd, &buff, BYTE_SIZE);
|
||||||
|
velocity = sd.velocity;
|
||||||
|
}
|
||||||
|
int v = ceil(velocity * KPHTOMPH);
|
||||||
|
if (v >= 255)
|
||||||
|
{
|
||||||
|
v = 255;
|
||||||
|
}
|
||||||
|
myMotor1->setSpeed(v);
|
||||||
|
myMotor2->setSpeed(v);
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "arduino.h"
|
#include "arduino.h"
|
||||||
#include "../slog/slog.h"
|
#include "../../slog/slog.h"
|
||||||
|
|
||||||
#define arduino_timeout 2000
|
#define arduino_timeout 2000
|
||||||
|
|
||||||
|
|
@ -18,11 +19,12 @@ int arduino_update(SerialDevice* serialdevice, SimData* simdata)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int arduino_init(SerialDevice* serialdevice)
|
int arduino_init(SerialDevice* serialdevice, const char* portdev)
|
||||||
{
|
{
|
||||||
slogi("initializing arduino serial device...");
|
slogi("initializing arduino serial device...");
|
||||||
int error = 0;
|
int error = 0;
|
||||||
char* port_name = "/dev/ttyACM0";
|
char* port_name = strdup(portdev);
|
||||||
|
|
||||||
slogd("Looking for port %s.\n", port_name);
|
slogd("Looking for port %s.\n", port_name);
|
||||||
error = check(sp_get_port_by_name(port_name, &serialdevice->port));
|
error = check(sp_get_port_by_name(port_name, &serialdevice->port));
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
|
|
@ -40,6 +42,7 @@ int arduino_init(SerialDevice* serialdevice)
|
||||||
check(sp_set_stopbits(serialdevice->port, 1));
|
check(sp_set_stopbits(serialdevice->port, 1));
|
||||||
check(sp_set_flowcontrol(serialdevice->port, SP_FLOWCONTROL_NONE));
|
check(sp_set_flowcontrol(serialdevice->port, SP_FLOWCONTROL_NONE));
|
||||||
|
|
||||||
|
free(port_name);
|
||||||
slogd("Successfully setup arduino serial device...");
|
slogd("Successfully setup arduino serial device...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
#ifndef _ARDUINO_H
|
#ifndef _ARDUINO_H
|
||||||
#define _ARDUINO_H
|
#define _ARDUINO_H
|
||||||
|
|
||||||
|
#include "../simdevice.h"
|
||||||
#include "../serialdevice.h"
|
#include "../serialdevice.h"
|
||||||
|
|
||||||
int arduino_update(SerialDevice* serialdevice, SimData* simdata);
|
int arduino_update(SerialDevice* serialdevice, SimData* simdata);
|
||||||
int arduino_init(SerialDevice* serialdevice);
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,34 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "simdevice.h"
|
||||||
#include "serialdevice.h"
|
#include "serialdevice.h"
|
||||||
#include "serial/arduino.h"
|
#include "serial/arduino.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
#include "../simulatorapi/simdata.h"
|
#include "../simulatorapi/simdata.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
int serialdev_update(SerialDevice* serialdevice, SimData* simdata)
|
int serialdev_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
||||||
arduino_update(serialdevice, simdata);
|
arduino_update(serialdevice, simdata);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int serialdev_free(SerialDevice* serialdevice)
|
int serialdev_free(SimDevice* this)
|
||||||
{
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
||||||
arduino_free(serialdevice);
|
arduino_free(serialdevice);
|
||||||
|
|
||||||
|
free(serialdevice);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int serialdev_init(SerialDevice* serialdevice)
|
int serialdev_init(SerialDevice* serialdevice, const char* portdev)
|
||||||
{
|
{
|
||||||
slogi("initializing serial device...");
|
slogi("initializing serial device...");
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
@ -29,7 +37,29 @@ int serialdev_init(SerialDevice* serialdevice)
|
||||||
serialdevice->type = SERIALDEV_UNKNOWN;
|
serialdevice->type = SERIALDEV_UNKNOWN;
|
||||||
serialdevice->type = SERIALDEV_ARDUINO;
|
serialdevice->type = SERIALDEV_ARDUINO;
|
||||||
|
|
||||||
error = arduino_init(serialdevice);
|
error = arduino_init(serialdevice, portdev);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const vtable serial_simdevice_vtable = { &serialdev_update, &serialdev_free };
|
||||||
|
|
||||||
|
SerialDevice* new_serial_device(DeviceSettings* ds) {
|
||||||
|
|
||||||
|
SerialDevice* this = (SerialDevice*) malloc(sizeof(SerialDevice));
|
||||||
|
|
||||||
|
this->m.update = &update;
|
||||||
|
this->m.free = &simdevfree;
|
||||||
|
this->m.derived = this;
|
||||||
|
this->m.vtable = &serial_simdevice_vtable;
|
||||||
|
|
||||||
|
int error = serialdev_init(this, ds->serialdevsettings.portdev);
|
||||||
|
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
free(this);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,6 @@
|
||||||
#define _SERIALDEVICE_H
|
#define _SERIALDEVICE_H
|
||||||
|
|
||||||
#include <libserialport.h>
|
#include <libserialport.h>
|
||||||
#include "../helper/parameters.h"
|
|
||||||
#include "../simulatorapi/simdata.h"
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
SERIALDEV_UNKNOWN = 0,
|
|
||||||
SERIALDEV_ARDUINO = 1
|
|
||||||
}
|
|
||||||
SerialType;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
SerialType type;
|
|
||||||
struct sp_port* port;
|
|
||||||
}
|
|
||||||
SerialDevice;
|
|
||||||
|
|
||||||
int serialdev_update(SerialDevice* serialdevice, SimData* simdata);
|
|
||||||
int serialdev_init(SerialDevice* serialdevice);
|
|
||||||
int serialdev_free(SerialDevice* serialdevice);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "simdevice.h"
|
#include "simdevice.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
|
|
@ -6,80 +7,101 @@
|
||||||
#include "../simulatorapi/simdata.h"
|
#include "../simulatorapi/simdata.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
int devupdate(SimDevice* simdevice, SimData* simdata)
|
|
||||||
|
int update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
if (simdevice->initialized==false)
|
((vtable*)this->vtable)->update(this, simdata);
|
||||||
{
|
}
|
||||||
return 0;
|
|
||||||
}
|
int simdevfree(SimDevice* this)
|
||||||
switch ( simdevice->type )
|
{
|
||||||
{
|
((vtable*)this->vtable)->free(this);
|
||||||
case SIMDEV_USB :
|
}
|
||||||
usbdev_update(&simdevice->d.usbdevice, simdata);
|
|
||||||
break;
|
int devupdate(SimDevice* this, SimData* simdata)
|
||||||
case SIMDEV_SOUND :
|
{
|
||||||
sounddev_update(&simdevice->d.sounddevice, simdata);
|
|
||||||
break;
|
|
||||||
case SIMDEV_SERIAL :
|
|
||||||
serialdev_update(&simdevice->d.serialdevice, simdata);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int devfree(SimDevice* simdevice)
|
int devfree(SimDevice* simdevices, int numdevices)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (simdevice->initialized==false)
|
slogi("freeing %i simdevices...", numdevices);
|
||||||
|
int devices = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < numdevices; j++)
|
||||||
{
|
{
|
||||||
slogw("Attempt to free an uninitialized device");
|
SimDevice simdev = simdevices[j];
|
||||||
return MONOCOQUE_ERROR_INVALID_DEV;
|
if (simdev.initialized == true)
|
||||||
}
|
{
|
||||||
switch ( simdevice->type )
|
simdev.free(&simdev);
|
||||||
{
|
}
|
||||||
case SIMDEV_USB :
|
|
||||||
usbdev_free(&simdevice->d.usbdevice);
|
|
||||||
break;
|
|
||||||
case SIMDEV_SOUND :
|
|
||||||
sounddev_free(&simdevice->d.sounddevice);
|
|
||||||
break;
|
|
||||||
case SIMDEV_SERIAL :
|
|
||||||
serialdev_free(&simdevice->d.serialdevice);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(simdevices);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int devinit(SimDevice* simdevice, DeviceSettings* ds)
|
int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
slogi("initializing simdevice...");
|
slogi("initializing simdevices...");
|
||||||
simdevice->initialized = false;
|
int devices = 0;
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
switch ( ds->dev_type )
|
for (int j = 0; j < numdevices; j++)
|
||||||
{
|
{
|
||||||
case SIMDEV_USB :
|
simdevices[j].initialized = false;
|
||||||
simdevice->type = SIMDEV_USB;
|
|
||||||
simdevice->d.usbdevice.type = USBDEV_UNKNOWN;
|
if (ds[j].dev_type == SIMDEV_USB) {
|
||||||
err = usbdev_init(&simdevice->d.usbdevice, ds);
|
USBDevice* sim = new_usb_device(&ds[j]);
|
||||||
break;
|
if (sim != NULL)
|
||||||
case SIMDEV_SOUND :
|
{
|
||||||
simdevice->type = SIMDEV_SOUND;
|
simdevices[j] = sim->m;
|
||||||
err = sounddev_init(&simdevice->d.sounddevice);
|
simdevices[j].initialized = true;
|
||||||
break;
|
simdevices[j].type = SIMDEV_USB;
|
||||||
case SIMDEV_SERIAL :
|
devices++;
|
||||||
simdevice->type = SIMDEV_SERIAL;
|
}
|
||||||
err = serialdev_init(&simdevice->d.serialdevice);
|
else
|
||||||
break;
|
{
|
||||||
default :
|
slogw("Could not initialize USB Device");
|
||||||
sloge("Unknown device type");
|
}
|
||||||
err = MONOCOQUE_ERROR_UNKNOWN_DEV;
|
}
|
||||||
break;
|
|
||||||
|
if (ds[j].dev_type == SIMDEV_SOUND) {
|
||||||
|
|
||||||
|
SoundDevice* sim = new_sound_device(&ds[j]);
|
||||||
|
if (sim != NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
simdevices[j] = sim->m;
|
||||||
|
simdevices[j].initialized = true;
|
||||||
|
simdevices[j].type = SIMDEV_SOUND;
|
||||||
|
devices++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slogw("Could not initialize Sound Device");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds[j].dev_type == SIMDEV_SERIAL) {
|
||||||
|
|
||||||
|
SerialDevice* sim = new_serial_device(&ds[j]);
|
||||||
|
if (sim != NULL)
|
||||||
|
{
|
||||||
|
simdevices[j] = sim->m;
|
||||||
|
simdevices[j].initialized = true;
|
||||||
|
simdevices[j].type = SIMDEV_SERIAL;
|
||||||
|
devices++;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slogw("Could not initialize Serial Device");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err==0)
|
return devices;
|
||||||
{
|
|
||||||
simdevice->initialized = true;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,26 +9,102 @@
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../simulatorapi/simdata.h"
|
#include "../simulatorapi/simdata.h"
|
||||||
|
|
||||||
|
typedef struct SimDevice SimDevice;
|
||||||
|
|
||||||
typedef struct
|
struct SimDevice
|
||||||
{
|
{
|
||||||
|
const void* vtable;
|
||||||
|
int (*update)(SimDevice*, SimData*);
|
||||||
|
int (*free)(SimDevice*);
|
||||||
|
void* derived;
|
||||||
int id;
|
int id;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
DeviceType type;
|
DeviceType type;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int (*update)(SimDevice*, SimData*);
|
||||||
|
int (*free)(SimDevice*);
|
||||||
|
} vtable;
|
||||||
|
|
||||||
|
/********* Serial Devices *****/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
SERIALDEV_UNKNOWN = 0,
|
||||||
|
SERIALDEV_ARDUINO = 1
|
||||||
|
}
|
||||||
|
SerialType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SimDevice m;
|
||||||
|
int id;
|
||||||
|
SerialType type;
|
||||||
|
struct sp_port* port;
|
||||||
|
}
|
||||||
|
SerialDevice;
|
||||||
|
|
||||||
|
int serialdev_update(SimDevice* this, SimData* simdata);
|
||||||
|
int serialdev_free(SimDevice* this);
|
||||||
|
|
||||||
|
SerialDevice* new_serial_device(DeviceSettings* ds);
|
||||||
|
|
||||||
|
/********* USB HID Devices *****/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
USBDEV_UNKNOWN = 0,
|
||||||
|
USBDEV_TACHOMETER = 1
|
||||||
|
}
|
||||||
|
USBType;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SimDevice m;
|
||||||
|
int id;
|
||||||
|
USBType type;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
USBDevice usbdevice;
|
TachDevice tachdevice;
|
||||||
SoundDevice sounddevice;
|
} u;
|
||||||
SerialDevice serialdevice;
|
|
||||||
} d;
|
|
||||||
}
|
}
|
||||||
SimDevice;
|
USBDevice;
|
||||||
|
|
||||||
|
int usbdev_update(SimDevice* this, SimData* simdata);
|
||||||
|
int usbdev_free(SimDevice* this);
|
||||||
|
|
||||||
|
USBDevice* new_usb_device(DeviceSettings* ds);
|
||||||
|
|
||||||
|
|
||||||
|
/********* Sound Devices *****/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SimDevice m;
|
||||||
|
int id;
|
||||||
|
SoundType type;
|
||||||
|
VibrationEffectType effecttype;
|
||||||
|
PATestData sounddata;
|
||||||
|
PaStreamParameters outputParameters;
|
||||||
|
PaStream* stream;
|
||||||
|
}
|
||||||
|
SoundDevice;
|
||||||
|
|
||||||
|
int sounddev_engine_update(SimDevice* this, SimData* simdata);
|
||||||
|
int sounddev_gearshift_update(SimDevice* this, SimData* simdata);
|
||||||
|
int sounddev_free(SimDevice* this);
|
||||||
|
|
||||||
|
SoundDevice* new_sound_device(DeviceSettings* ds);
|
||||||
|
|
||||||
|
/***** Generic Methods *********/
|
||||||
|
|
||||||
|
int update(SimDevice* simdevice, SimData* simdata);
|
||||||
|
|
||||||
int devupdate(SimDevice* simdevice, SimData* simdata);
|
int devupdate(SimDevice* simdevice, SimData* simdata);
|
||||||
|
|
||||||
int devinit(SimDevice* simdevice, DeviceSettings* ds);
|
int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds);
|
||||||
|
|
||||||
int devfree(SimDevice* simdevice);
|
int devfree(SimDevice* simdevices, int numdevices);
|
||||||
|
|
||||||
|
int simdevfree(SimDevice* this);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int patestCallbackEngineRPM(const void* inputBuffer,
|
||||||
int patestCallback(const void* inputBuffer,
|
|
||||||
void* outputBuffer,
|
void* outputBuffer,
|
||||||
unsigned long framesPerBuffer,
|
unsigned long framesPerBuffer,
|
||||||
const PaStreamCallbackTimeInfo* timeInfo,
|
const PaStreamCallbackTimeInfo* timeInfo,
|
||||||
|
|
@ -36,27 +35,16 @@ int patestCallback(const void* inputBuffer,
|
||||||
float v = 0;
|
float v = 0;
|
||||||
v = data->amp * sin (2 * M_PI * ((float) n) / (float) SAMPLE_RATE);
|
v = data->amp * sin (2 * M_PI * ((float) n) / (float) SAMPLE_RATE);
|
||||||
|
|
||||||
if ( data->gear_sound_data > 0 )
|
if (n>=data->table_size)
|
||||||
{
|
{
|
||||||
if (n>=1764)
|
n=0;
|
||||||
{
|
|
||||||
n=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (n>=data->table_size)
|
|
||||||
{
|
|
||||||
n=0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( data->gear_sound_data > 0 )
|
if (data->gear_sound_data > 0)
|
||||||
{
|
{
|
||||||
// right channel only?
|
*out++ = 0;
|
||||||
// i have my butt hooked up to right channel... make this configurable?
|
*out++ = 0;
|
||||||
*out++ = v;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +53,50 @@ int patestCallback(const void* inputBuffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data->gear_sound_data = 0;
|
||||||
|
data->n=n;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int patestCallbackGearShift(const void* inputBuffer,
|
||||||
|
void* outputBuffer,
|
||||||
|
unsigned long framesPerBuffer,
|
||||||
|
const PaStreamCallbackTimeInfo* timeInfo,
|
||||||
|
PaStreamCallbackFlags statusFlags,
|
||||||
|
void* userData)
|
||||||
|
{
|
||||||
|
PATestData* data = (PATestData*)userData;
|
||||||
|
float* out = (float*)outputBuffer;
|
||||||
|
memset(out, 0, framesPerBuffer * 2 * sizeof(float));
|
||||||
|
unsigned int i;
|
||||||
|
unsigned int n;
|
||||||
|
n = data->n;
|
||||||
|
(void) inputBuffer; /* Prevent unused argument warning. */
|
||||||
|
|
||||||
|
for( i=0; i<framesPerBuffer; i++,n++ )
|
||||||
|
{
|
||||||
|
float v = 0;
|
||||||
|
v = data->amp * sin (2 * M_PI * ((float) n) / (float) SAMPLE_RATE);
|
||||||
|
|
||||||
|
if (n>=data->table_size)
|
||||||
|
{
|
||||||
|
n=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data->gear_sound_data > 0)
|
||||||
|
{
|
||||||
|
*out++ = v;
|
||||||
|
*out++ = v;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*out++ = 0;
|
||||||
|
*out++ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data->gear_sound_data = 0;
|
||||||
|
|
||||||
data->n=n;
|
data->n=n;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -97,14 +129,28 @@ int usb_generic_shaker_init(SoundDevice* sounddevice)
|
||||||
sounddevice->outputParameters.suggestedLatency = Pa_GetDeviceInfo( sounddevice->outputParameters.device )->defaultLowOutputLatency;
|
sounddevice->outputParameters.suggestedLatency = Pa_GetDeviceInfo( sounddevice->outputParameters.device )->defaultLowOutputLatency;
|
||||||
sounddevice->outputParameters.hostApiSpecificStreamInfo = NULL;
|
sounddevice->outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||||
|
|
||||||
err = Pa_OpenStream( &sounddevice->stream,
|
if (sounddevice->effecttype == SOUNDEFFECT_GEARSHIFT)
|
||||||
NULL, /* No input. */
|
{
|
||||||
&sounddevice->outputParameters, /* As above. */
|
err = Pa_OpenStream( &sounddevice->stream,
|
||||||
SAMPLE_RATE,
|
NULL, /* No input. */
|
||||||
440, /* Frames per buffer. */
|
&sounddevice->outputParameters, /* As above. */
|
||||||
paClipOff, /* No out of range samples expected. */
|
SAMPLE_RATE,
|
||||||
patestCallback,
|
440, /* Frames per buffer. */
|
||||||
&sounddevice->sounddata );
|
paClipOff, /* No out of range samples expected. */
|
||||||
|
patestCallbackGearShift,
|
||||||
|
&sounddevice->sounddata );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = Pa_OpenStream( &sounddevice->stream,
|
||||||
|
NULL, /* No input. */
|
||||||
|
&sounddevice->outputParameters, /* As above. */
|
||||||
|
SAMPLE_RATE,
|
||||||
|
440, /* Frames per buffer. */
|
||||||
|
paClipOff, /* No out of range samples expected. */
|
||||||
|
patestCallbackEngineRPM,
|
||||||
|
&sounddevice->sounddata );
|
||||||
|
}
|
||||||
if( err != paNoError )
|
if( err != paNoError )
|
||||||
{
|
{
|
||||||
goto error;
|
goto error;
|
||||||
|
|
@ -121,8 +167,5 @@ int usb_generic_shaker_init(SoundDevice* sounddevice)
|
||||||
|
|
||||||
error:
|
error:
|
||||||
Pa_Terminate();
|
Pa_Terminate();
|
||||||
//fprintf( stderr, "An error occured while using the portaudio stream\n" );
|
|
||||||
//fprintf( stderr, "Error number: %d\n", err );
|
|
||||||
//fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#ifndef _USB_GENERIC_SHAKER_H
|
#ifndef _USB_GENERIC_SHAKER_H
|
||||||
#define _USB_GENERIC_SHAKER_H
|
#define _USB_GENERIC_SHAKER_H
|
||||||
|
|
||||||
#include "../sounddevice.h"
|
//#include "../sounddevice.h"
|
||||||
|
#include "../simdevice.h"
|
||||||
|
|
||||||
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
int usb_generic_shaker_init(SoundDevice* sounddevice);
|
||||||
int usb_generic_shaker_free(SoundDevice* sounddevice);
|
int usb_generic_shaker_free(SoundDevice* sounddevice);
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,52 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "simdevice.h"
|
||||||
#include "sounddevice.h"
|
#include "sounddevice.h"
|
||||||
#include "sound/usb_generic_shaker.h"
|
#include "sound/usb_generic_shaker.h"
|
||||||
#include "../simulatorapi/simdata.h"
|
#include "../simulatorapi/simdata.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
int sounddev_update(SoundDevice* sounddevice, SimData* simdata)
|
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
sounddevice->sounddata.table_size = 44100/(simdata->rpms/60);
|
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear != 0)
|
||||||
|
|
||||||
sounddevice->sounddata.gear_sound_data = 0;
|
|
||||||
if (sounddevice->sounddata.last_gear != simdata->gear)
|
|
||||||
{
|
{
|
||||||
sounddevice->sounddata.gear_sound_data = sounddevice->sounddata.amp;
|
sounddevice->sounddata.gear_sound_data = 3.14;
|
||||||
}
|
}
|
||||||
sounddevice->sounddata.last_gear = simdata->gear;
|
sounddevice->sounddata.last_gear = simdata->gear;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sounddev_free(SoundDevice* sounddevice)
|
// we could make a vtable for these different effects too
|
||||||
|
int sounddev_engine_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
return usb_generic_shaker_free(sounddevice);
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
|
gear_sound_set(sounddevice, simdata);
|
||||||
|
|
||||||
|
sounddevice->sounddata.table_size = 44100/(simdata->rpms/60);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
|
gear_sound_set(sounddevice, simdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sounddev_free(SimDevice* this)
|
||||||
|
{
|
||||||
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
|
usb_generic_shaker_free(sounddevice);
|
||||||
|
|
||||||
|
free(sounddevice);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sounddev_init(SoundDevice* sounddevice)
|
int sounddev_init(SoundDevice* sounddevice)
|
||||||
|
|
@ -34,5 +60,51 @@ int sounddev_init(SoundDevice* sounddevice)
|
||||||
sounddevice->sounddata.table_size = 44100/(100/60);
|
sounddevice->sounddata.table_size = 44100/(100/60);
|
||||||
sounddevice->sounddata.last_gear = 0;
|
sounddevice->sounddata.last_gear = 0;
|
||||||
|
|
||||||
|
switch (sounddevice->effecttype) {
|
||||||
|
case (SOUNDEFFECT_GEARSHIFT):
|
||||||
|
|
||||||
|
sounddevice->sounddata.pitch = 500;
|
||||||
|
sounddevice->sounddata.amp = 128;
|
||||||
|
sounddevice->sounddata.left_phase = sounddevice->sounddata.right_phase = 0;
|
||||||
|
sounddevice->sounddata.table_size = 44100/(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
usb_generic_shaker_init(sounddevice);
|
usb_generic_shaker_init(sounddevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const vtable engine_sound_simdevice_vtable = { &sounddev_engine_update, &sounddev_free };
|
||||||
|
static const vtable gear_sound_simdevice_vtable = { &sounddev_gearshift_update, &sounddev_free };
|
||||||
|
|
||||||
|
SoundDevice* new_sound_device(DeviceSettings* ds) {
|
||||||
|
|
||||||
|
SoundDevice* this = (SoundDevice*) malloc(sizeof(SoundDevice));
|
||||||
|
|
||||||
|
this->m.update = &update;
|
||||||
|
this->m.free = &simdevfree;
|
||||||
|
this->m.derived = this;
|
||||||
|
|
||||||
|
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 (SIMDEVTYPE_GEARSOUND):
|
||||||
|
this->effecttype = SOUNDEFFECT_GEARSHIFT;
|
||||||
|
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||||
|
slogi("Initializing sound device for gear shift vibrations.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int error = sounddev_init(this);
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
free(this);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
#include "portaudio.h"
|
#include "portaudio.h"
|
||||||
|
|
||||||
#include "../simulatorapi/simdata.h"
|
|
||||||
#include "../helper/parameters.h"
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
SOUNDDEV_UNKNOWN = 0,
|
SOUNDDEV_UNKNOWN = 0,
|
||||||
|
|
@ -13,6 +10,13 @@ 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
|
||||||
{
|
{
|
||||||
|
|
@ -28,18 +32,4 @@ typedef struct
|
||||||
}
|
}
|
||||||
PATestData;
|
PATestData;
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
SoundType type;
|
|
||||||
PATestData sounddata;
|
|
||||||
PaStreamParameters outputParameters;
|
|
||||||
PaStream* stream;
|
|
||||||
}
|
|
||||||
SoundDevice;
|
|
||||||
|
|
||||||
int sounddev_update(SoundDevice* sounddevice, SimData* simdata);
|
|
||||||
int sounddev_init(SoundDevice* sounddevice);
|
|
||||||
int sounddev_free(SoundDevice* sounddevice);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "usbdevice.h"
|
#include "usbdevice.h"
|
||||||
|
#include "simdevice.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
#include "../simulatorapi/simdata.h"
|
#include "../simulatorapi/simdata.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
int usbdev_update(USBDevice* usbdevice, SimData* simdata)
|
int usbdev_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
|
USBDevice* usbdevice = (void *) this->derived;
|
||||||
|
|
||||||
switch ( usbdevice->type )
|
switch ( usbdevice->type )
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
|
|
@ -20,8 +24,10 @@ int usbdev_update(USBDevice* usbdevice, SimData* simdata)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usbdev_free(USBDevice* usbdevice)
|
int usbdev_free(SimDevice* this)
|
||||||
{
|
{
|
||||||
|
USBDevice* usbdevice = (void *) this->derived;
|
||||||
|
|
||||||
switch ( usbdevice->type )
|
switch ( usbdevice->type )
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
|
|
@ -30,6 +36,8 @@ int usbdev_free(USBDevice* usbdevice)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(usbdevice);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,6 +45,8 @@ 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;
|
||||||
switch ( usbdevice->type )
|
switch ( usbdevice->type )
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
|
|
@ -47,3 +57,24 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const vtable usb_simdevice_vtable = { &usbdev_update, &usbdev_free };
|
||||||
|
|
||||||
|
USBDevice* new_usb_device(DeviceSettings* ds) {
|
||||||
|
|
||||||
|
USBDevice* this = (USBDevice*) malloc(sizeof(USBDevice));
|
||||||
|
|
||||||
|
this->m.update = &update;
|
||||||
|
this->m.free = &simdevfree;
|
||||||
|
this->m.derived = this;
|
||||||
|
this->m.vtable = &usb_simdevice_vtable;
|
||||||
|
|
||||||
|
int error = usbdev_init(this, ds);
|
||||||
|
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
free(this);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,29 +2,5 @@
|
||||||
#define _USBDEVICE_H
|
#define _USBDEVICE_H
|
||||||
|
|
||||||
#include "tachdevice.h"
|
#include "tachdevice.h"
|
||||||
#include "../helper/confighelper.h"
|
|
||||||
#include "../simulatorapi/simdata.h"
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
USBDEV_UNKNOWN = 0,
|
|
||||||
USBDEV_TACHOMETER = 1
|
|
||||||
}
|
|
||||||
USBType;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
USBType type;
|
|
||||||
union
|
|
||||||
{
|
|
||||||
TachDevice tachdevice;
|
|
||||||
} u;
|
|
||||||
}
|
|
||||||
USBDevice;
|
|
||||||
|
|
||||||
int usbdev_update(USBDevice* usbdevice, SimData* simdata);
|
|
||||||
int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds);
|
|
||||||
int usbdev_free(USBDevice* usbdevice);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#include "../simulatorapi/simmapper.h"
|
#include "../simulatorapi/simmapper.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
#define DEFAULT_UPDATE_RATE 120.0
|
#define DEFAULT_UPDATE_RATE 240.0
|
||||||
|
|
||||||
int showstats(SimData* simdata)
|
int showstats(SimData* simdata)
|
||||||
{
|
{
|
||||||
|
|
@ -165,7 +165,7 @@ int showstats(SimData* simdata)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int looper(SimDevice* devices[], int numdevices, Simulator simulator)
|
int looper(SimDevice* devices, int numdevices, Simulator simulator)
|
||||||
{
|
{
|
||||||
|
|
||||||
slogi("preparing game loop with %i devices...", numdevices);
|
slogi("preparing game loop with %i devices...", numdevices);
|
||||||
|
|
@ -179,6 +179,15 @@ int looper(SimDevice* devices[], int numdevices, Simulator simulator)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
struct termios newsettings, canonicalmode;
|
||||||
tcgetattr(0, &canonicalmode);
|
tcgetattr(0, &canonicalmode);
|
||||||
newsettings = canonicalmode;
|
newsettings = canonicalmode;
|
||||||
|
|
@ -191,35 +200,23 @@ int looper(SimDevice* devices[], int numdevices, Simulator simulator)
|
||||||
|
|
||||||
double update_rate = DEFAULT_UPDATE_RATE;
|
double update_rate = DEFAULT_UPDATE_RATE;
|
||||||
int t=0;
|
int t=0;
|
||||||
|
int s=0;
|
||||||
int go = true;
|
int go = true;
|
||||||
while (go == true)
|
while (go == true)
|
||||||
{
|
{
|
||||||
simdatamap(simdata, simmap, simulator);
|
simdatamap(simdata, simmap, simulator);
|
||||||
showstats(simdata);
|
showstats(simdata);
|
||||||
t++;
|
t++;
|
||||||
if(simdata->rpms<250)
|
s++;
|
||||||
|
if(simdata->rpms<100)
|
||||||
{
|
{
|
||||||
simdata->rpms=250;
|
simdata->rpms=100;
|
||||||
}
|
}
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
if (devices[x]->type == SIMDEV_SERIAL)
|
devices[x].update(&devices[x], simdata);
|
||||||
{
|
|
||||||
if(t>=update_rate)
|
|
||||||
{
|
|
||||||
devupdate(devices[x], simdata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
devupdate(devices[x], simdata);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(t>=update_rate)
|
|
||||||
{
|
|
||||||
t=0;
|
|
||||||
}
|
|
||||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||||
{
|
{
|
||||||
scanf("%c", &ch);
|
scanf("%c", &ch);
|
||||||
|
|
@ -233,8 +230,156 @@ int looper(SimDevice* devices[], int numdevices, Simulator simulator)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||||
|
|
||||||
|
simdata->velocity = 0;
|
||||||
|
simdata->rpms = 100;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
|
||||||
free(simdata);
|
free(simdata);
|
||||||
free(simmap);
|
free(simmap);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tester(SimDevice* devices, int numdevices)
|
||||||
|
{
|
||||||
|
|
||||||
|
slogi("preparing test with %i devices...", numdevices);
|
||||||
|
SimData* simdata = malloc(sizeof(SimData));
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
simdata->gear = 0;
|
||||||
|
simdata->velocity = 16;
|
||||||
|
simdata->rpms = 100;
|
||||||
|
simdata->maxrpm = 8000;
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting rpms to 1000\n");
|
||||||
|
simdata->rpms = 1000;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Shifting into first gear\n");
|
||||||
|
simdata->gear = 1;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting speed to 100\n");
|
||||||
|
simdata->velocity = 100;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Shifting into second gear\n");
|
||||||
|
simdata->gear = 2;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting speed to 200\n");
|
||||||
|
simdata->velocity = 200;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Shifting into third gear\n");
|
||||||
|
simdata->gear = 3;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting rpms to 2000\n");
|
||||||
|
simdata->rpms = 2000;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting rpms to 4000\n");
|
||||||
|
simdata->rpms = 4000;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Shifting into fourth gear\n");
|
||||||
|
simdata->gear = 4;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting speed to 300\n");
|
||||||
|
simdata->velocity = 300;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
fprintf(stdout, "Setting rpms to 8000\n");
|
||||||
|
simdata->rpms = 8000;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
simdata->velocity = 0;
|
||||||
|
simdata->rpms = 100;
|
||||||
|
for (int x = 0; x < numdevices; x++)
|
||||||
|
{
|
||||||
|
devices[x].update(&devices[x], simdata);
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||||
|
|
||||||
|
free(simdata);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "../devices/simdevice.h"
|
#include "../devices/simdevice.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
|
|
||||||
int looper (SimDevice* devices[], int numdevices, Simulator simulator);
|
int tester(SimDevice* devices, int numdevices);
|
||||||
|
int looper (SimDevice* devices, int numdevices, Simulator simulator);
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ int config_tachometer(int max_revs, int granularity, const char* save_file, SimD
|
||||||
WriteXmlFromArrays(nodes, rpm_array, values_array, max_revs, save_file);
|
WriteXmlFromArrays(nodes, rpm_array, values_array, max_revs, save_file);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
simdata->pulses = 0;
|
simdata->pulses = 0;
|
||||||
devupdate(simdevice, simdata);
|
simdevice->update(simdevice, simdata);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <libxml/parser.h>
|
#include <libxml/parser.h>
|
||||||
#include <libxml/xmlreader.h>
|
#include <libxml/xmlreader.h>
|
||||||
|
|
@ -11,21 +12,32 @@
|
||||||
|
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
|
|
||||||
|
int strcicmp(char const *a, char const *b)
|
||||||
|
{
|
||||||
|
for (;; a++, b++) {
|
||||||
|
int d = tolower((unsigned char)*a) - tolower((unsigned char)*b);
|
||||||
|
if (d != 0 || !*a)
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int strtogame(const char* game, MonocoqueSettings* ms)
|
int strtogame(const char* game, MonocoqueSettings* ms)
|
||||||
{
|
{
|
||||||
slogd("Checking for %s in list of supported simulators.", game);
|
slogd("Checking for %s in list of supported simulators.", game);
|
||||||
if (strcmp(game, "ac") == 0)
|
if (strcicmp(game, "ac") == 0)
|
||||||
{
|
{
|
||||||
slogd("Setting simulator to Assetto Corsa");
|
slogd("Setting simulator to Assetto Corsa");
|
||||||
ms->sim_name = SIMULATOR_ASSETTO_CORSA;
|
ms->sim_name = SIMULATOR_ASSETTO_CORSA;
|
||||||
}
|
}
|
||||||
else if (strcmp(game, "rf2") == 0)
|
else if (strcicmp(game, "rf2") == 0)
|
||||||
{
|
{
|
||||||
slogd("Setting simulator to RFactor 2");
|
slogd("Setting simulator to RFactor 2");
|
||||||
ms->sim_name = SIMULATOR_RFACTOR2;
|
ms->sim_name = SIMULATOR_RFACTOR2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(game, "test") == 0)
|
if (strcicmp(game, "test") == 0)
|
||||||
{
|
{
|
||||||
slogd("Setting simulator to Test Data");
|
slogd("Setting simulator to Test Data");
|
||||||
ms->sim_name = SIMULATOR_MONOCOQUE_TEST;
|
ms->sim_name = SIMULATOR_MONOCOQUE_TEST;
|
||||||
|
|
@ -38,22 +50,68 @@ int strtogame(const char* game, MonocoqueSettings* ms)
|
||||||
return MONOCOQUE_ERROR_NONE;
|
return MONOCOQUE_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int strtodev(const char* device_type, DeviceSettings* ds)
|
int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||||
{
|
{
|
||||||
ds->is_valid = false;
|
ds->is_valid = false;
|
||||||
if (strcmp(device_type, "USB") == 0)
|
ds->dev_subtype = SIMDEVTYPE_UNKNOWN;
|
||||||
|
|
||||||
|
switch (simdev) {
|
||||||
|
case SIMDEV_USB:
|
||||||
|
if (strcicmp(device_subtype, "Tachometer") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SIMDEV_SERIAL:
|
||||||
|
if (strcicmp(device_subtype, "ShiftLights") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_SHIFTLIGHTS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strcicmp(device_subtype, "SimWind") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_SIMWIND;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SIMDEV_SOUND:
|
||||||
|
if (strcicmp(device_subtype, "Engine") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_ENGINESOUND;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strcicmp(device_subtype, "Gear") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_GEARSOUND;
|
||||||
|
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);
|
||||||
|
return MONOCOQUE_ERROR_INVALID_DEV;
|
||||||
|
}
|
||||||
|
ds->is_valid = true;
|
||||||
|
return MONOCOQUE_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int strtodev(const char* device_type, const char* device_subtype, DeviceSettings* ds)
|
||||||
|
{
|
||||||
|
ds->is_valid = false;
|
||||||
|
if (strcicmp(device_type, "USB") == 0)
|
||||||
{
|
{
|
||||||
ds->dev_type = SIMDEV_USB;
|
ds->dev_type = SIMDEV_USB;
|
||||||
|
strtodevsubtype(device_subtype, ds, SIMDEV_USB);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(device_type, "Sound") == 0)
|
if (strcicmp(device_type, "Sound") == 0)
|
||||||
{
|
{
|
||||||
ds->dev_type = SIMDEV_SOUND;
|
ds->dev_type = SIMDEV_SOUND;
|
||||||
|
strtodevsubtype(device_subtype, ds, SIMDEV_SOUND);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(device_type, "Serial") == 0)
|
if (strcicmp(device_type, "Serial") == 0)
|
||||||
{
|
{
|
||||||
ds->dev_type = SIMDEV_SERIAL;
|
ds->dev_type = SIMDEV_SERIAL;
|
||||||
|
strtodevsubtype(device_subtype, ds, SIMDEV_SERIAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -65,33 +123,6 @@ int strtodev(const char* device_type, DeviceSettings* ds)
|
||||||
return MONOCOQUE_ERROR_NONE;
|
return MONOCOQUE_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int strtodevtype(const char* device_subtype, DeviceSettings* ds)
|
|
||||||
{
|
|
||||||
ds->is_valid = false;
|
|
||||||
if (strcmp(device_subtype, "Tachometer") == 0)
|
|
||||||
{
|
|
||||||
ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (strcmp(device_subtype, "ShiftLights") == 0)
|
|
||||||
{
|
|
||||||
ds->dev_subtype = SIMDEVTYPE_SHIFTLIGHTS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (strcmp(device_subtype, "Shaker") == 0)
|
|
||||||
{
|
|
||||||
ds->dev_subtype = SIMDEVTYPE_SHAKER;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ds->is_valid = false;
|
|
||||||
slogi("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype);
|
|
||||||
return MONOCOQUE_ERROR_INVALID_DEV;
|
|
||||||
}
|
|
||||||
ds->is_valid = true;
|
|
||||||
return MONOCOQUE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -131,7 +162,7 @@ int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
slogt("Xml Element name %s", cursubsubnode->name);
|
slogt("Xml Element name %s", cursubsubnode->name);
|
||||||
}
|
}
|
||||||
if (strcmp(cursubsubnode->name, "SettingsItem") == 0)
|
if (strcicmp(cursubsubnode->name, "SettingsItem") == 0)
|
||||||
{
|
{
|
||||||
arraysize++;
|
arraysize++;
|
||||||
}
|
}
|
||||||
|
|
@ -153,13 +184,13 @@ int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
for (cursubsubsubnode = cursubsubnode->children; cursubsubsubnode; cursubsubsubnode = cursubsubsubnode->next)
|
for (cursubsubsubnode = cursubsubnode->children; cursubsubsubnode; cursubsubsubnode = cursubsubsubnode->next)
|
||||||
{
|
{
|
||||||
if (strcmp(cursubsubsubnode->name, "Value") == 0)
|
if (strcicmp(cursubsubsubnode->name, "Value") == 0)
|
||||||
{
|
{
|
||||||
xmlChar* a = xmlNodeGetContent(cursubsubsubnode);
|
xmlChar* a = xmlNodeGetContent(cursubsubsubnode);
|
||||||
rpms_array[i] = strtol((char*) a, &buf, 10);
|
rpms_array[i] = strtol((char*) a, &buf, 10);
|
||||||
xmlFree(a);
|
xmlFree(a);
|
||||||
}
|
}
|
||||||
if (strcmp(cursubsubsubnode->name, "TimeValue") == 0)
|
if (strcicmp(cursubsubsubnode->name, "TimeValue") == 0)
|
||||||
{
|
{
|
||||||
xmlChar* a = xmlNodeGetContent(cursubsubsubnode);
|
xmlChar* a = xmlNodeGetContent(cursubsubsubnode);
|
||||||
pulses_array[i] = strtol((char*) a, &buf, 10);
|
pulses_array[i] = strtol((char*) a, &buf, 10);
|
||||||
|
|
@ -199,18 +230,14 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
int error = MONOCOQUE_ERROR_NONE;
|
int error = MONOCOQUE_ERROR_NONE;
|
||||||
slogi("Called device setup with %s %s %s", device_type, device_subtype, config_file);
|
slogi("Called device setup with %s %s %s", device_type, device_subtype, config_file);
|
||||||
ds->dev_type = SIMDEV_UNKNOWN;
|
ds->dev_type = SIMDEV_UNKNOWN;
|
||||||
ds->dev_subtype = SIMDEVTYPE_UNKNOWN;
|
|
||||||
error = strtodev(device_type, ds);
|
error = strtodev(device_type, device_subtype, ds);
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
if (error != MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
error = strtodevtype(device_subtype, ds);
|
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
|
||||||
{
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
if (ms->program_action == A_PLAY)
|
|
||||||
{
|
{
|
||||||
error = loadconfig(config_file, ds);
|
error = loadconfig(config_file, ds);
|
||||||
}
|
}
|
||||||
|
|
@ -232,11 +259,34 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
slogi("Tachometer granularity set to %i", ds->tachsettings.granularity);
|
slogi("Tachometer granularity set to %i", ds->tachsettings.granularity);
|
||||||
}
|
}
|
||||||
ds->tachsettings.use_pulses = true;
|
ds->tachsettings.use_pulses = true;
|
||||||
if (ms->program_action == A_PLAY)
|
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
|
||||||
{
|
{
|
||||||
ds->tachsettings.use_pulses = false;
|
ds->tachsettings.use_pulses = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
||||||
|
{
|
||||||
|
if (device_settings != NULL)
|
||||||
|
{
|
||||||
|
const char* temp;
|
||||||
|
config_setting_lookup_string(device_settings, "devpath", &temp);
|
||||||
|
ds->serialdevsettings.portdev = strdup(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int settingsfree(DeviceSettings ds)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (ds.dev_subtype == SIMDEVTYPE_SIMWIND || ds.dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
||||||
|
{
|
||||||
|
if (ds.serialdevsettings.portdev != NULL)
|
||||||
|
{
|
||||||
|
free(ds.serialdevsettings.portdev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,10 @@ typedef enum
|
||||||
{
|
{
|
||||||
SIMDEVTYPE_UNKNOWN = 0,
|
SIMDEVTYPE_UNKNOWN = 0,
|
||||||
SIMDEVTYPE_TACHOMETER = 1,
|
SIMDEVTYPE_TACHOMETER = 1,
|
||||||
SIMDEVTYPE_SHAKER = 2,
|
SIMDEVTYPE_SHIFTLIGHTS = 2,
|
||||||
SIMDEVTYPE_SHIFTLIGHTS = 3
|
SIMDEVTYPE_SIMWIND = 3,
|
||||||
|
SIMDEVTYPE_ENGINESOUND = 4,
|
||||||
|
SIMDEVTYPE_GEARSOUND = 5
|
||||||
}
|
}
|
||||||
DeviceSubType;
|
DeviceSubType;
|
||||||
|
|
||||||
|
|
@ -74,12 +76,19 @@ typedef struct
|
||||||
}
|
}
|
||||||
TachometerSettings;
|
TachometerSettings;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char* portdev;
|
||||||
|
}
|
||||||
|
SerialDeviceSettings;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
DeviceType dev_type;
|
DeviceType dev_type;
|
||||||
DeviceSubType dev_subtype;
|
DeviceSubType dev_subtype;
|
||||||
TachometerSettings tachsettings;
|
TachometerSettings tachsettings;
|
||||||
|
SerialDeviceSettings serialdevsettings;
|
||||||
}
|
}
|
||||||
DeviceSettings;
|
DeviceSettings;
|
||||||
|
|
||||||
|
|
@ -87,4 +96,6 @@ int strtogame(const char* game, MonocoqueSettings* ms);
|
||||||
|
|
||||||
int devsetup(const char* device_type, const char* device_subtype, const char* config_files, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings);
|
int devsetup(const char* device_type, const char* device_subtype, const char* config_files, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings);
|
||||||
|
|
||||||
|
int settingsfree(DeviceSettings ds);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
|
|
||||||
struct arg_lit* arg_verbosity1 = arg_litn("v","verbose", 0, 2, "increase logging verbosity");
|
struct arg_lit* arg_verbosity1 = arg_litn("v","verbose", 0, 2, "increase logging verbosity");
|
||||||
struct arg_lit* arg_verbosity2 = arg_litn("v","verbose", 0, 2, "increase logging verbosity");
|
struct arg_lit* arg_verbosity2 = arg_litn("v","verbose", 0, 2, "increase logging verbosity");
|
||||||
|
struct arg_lit* arg_verbosity3 = arg_litn("v","verbose", 0, 2, "increase logging verbosity");
|
||||||
|
|
||||||
struct arg_rex* cmd1 = arg_rex1(NULL, NULL, "play", NULL, REG_ICASE, NULL);
|
struct arg_rex* cmd1 = arg_rex1(NULL, NULL, "play", NULL, REG_ICASE, NULL);
|
||||||
struct arg_str* arg_sim = arg_strn("s", "sim", "<gamename>", 0, 1, NULL);
|
struct arg_str* arg_sim = arg_strn("s", "sim", "<gamename>", 0, 1, NULL);
|
||||||
|
|
@ -43,6 +44,13 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
void* argtable2[] = {cmd2a,cmd2b,arg_max_revs,arg_granularity,arg_save,arg_verbosity2,help2,vers2,end2};
|
void* argtable2[] = {cmd2a,cmd2b,arg_max_revs,arg_granularity,arg_save,arg_verbosity2,help2,vers2,end2};
|
||||||
int nerrors2;
|
int nerrors2;
|
||||||
|
|
||||||
|
struct arg_rex* cmd3 = arg_rex1(NULL, NULL, "test", NULL, REG_ICASE, NULL);
|
||||||
|
struct arg_lit* help3 = arg_litn(NULL,"help", 0, 1, "print this help and exit");
|
||||||
|
struct arg_lit* vers3 = arg_litn(NULL,"version", 0, 1, "print version information and exit");
|
||||||
|
struct arg_end* end3 = arg_end(20);
|
||||||
|
void* argtable3[] = {cmd3,arg_verbosity3,help3,vers3,end3};
|
||||||
|
int nerrors3;
|
||||||
|
|
||||||
struct arg_lit* help0 = arg_lit0(NULL,"help", "print this help and exit");
|
struct arg_lit* help0 = arg_lit0(NULL,"help", "print this help and exit");
|
||||||
struct arg_lit* version0 = arg_lit0(NULL,"version", "print version information and exit");
|
struct arg_lit* version0 = arg_lit0(NULL,"version", "print version information and exit");
|
||||||
struct arg_end* end0 = arg_end(20);
|
struct arg_end* end0 = arg_end(20);
|
||||||
|
|
@ -70,6 +78,7 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
nerrors0 = arg_parse(argc,argv,argtable0);
|
nerrors0 = arg_parse(argc,argv,argtable0);
|
||||||
nerrors1 = arg_parse(argc,argv,argtable1);
|
nerrors1 = arg_parse(argc,argv,argtable1);
|
||||||
nerrors2 = arg_parse(argc,argv,argtable2);
|
nerrors2 = arg_parse(argc,argv,argtable2);
|
||||||
|
nerrors3 = arg_parse(argc,argv,argtable3);
|
||||||
|
|
||||||
if (nerrors1==0)
|
if (nerrors1==0)
|
||||||
{
|
{
|
||||||
|
|
@ -92,6 +101,11 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
p->verbosity_count = arg_verbosity2->count;
|
p->verbosity_count = arg_verbosity2->count;
|
||||||
exitcode = E_SUCCESS_AND_DO;
|
exitcode = E_SUCCESS_AND_DO;
|
||||||
}
|
}
|
||||||
|
else if (nerrors3==0)
|
||||||
|
{
|
||||||
|
p->program_action = A_TEST;
|
||||||
|
exitcode = E_SUCCESS_AND_DO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (cmd1->count > 0)
|
if (cmd1->count > 0)
|
||||||
|
|
@ -111,12 +125,13 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
{
|
{
|
||||||
if (help->count==0 && vers->count==0)
|
if (help->count==0 && vers->count==0)
|
||||||
{
|
{
|
||||||
printf("%s: missing <play|config> command.\n",progname);
|
printf("%s: missing <play|config|test> command.\n",progname);
|
||||||
printf("Usage 1: %s ", progname);
|
printf("Usage 1: %s ", progname);
|
||||||
arg_print_syntax(stdout,argtable1,"\n");
|
arg_print_syntax(stdout,argtable1,"\n");
|
||||||
printf("Usage 2: %s ", progname);
|
printf("Usage 2: %s ", progname);
|
||||||
arg_print_syntax(stdout,argtable2,"\n");
|
arg_print_syntax(stdout,argtable2,"\n");
|
||||||
|
printf("Usage 3: %s ", progname);
|
||||||
|
arg_print_syntax(stdout,argtable3,"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exitcode = E_SUCCESS_AND_EXIT;
|
exitcode = E_SUCCESS_AND_EXIT;
|
||||||
|
|
@ -131,6 +146,8 @@ ConfigError getParameters(int argc, char** argv, Parameters* p)
|
||||||
arg_print_syntax(stdout,argtable1,"\n");
|
arg_print_syntax(stdout,argtable1,"\n");
|
||||||
printf("Usage 2: %s ", progname);
|
printf("Usage 2: %s ", progname);
|
||||||
arg_print_syntax(stdout,argtable2,"\n");
|
arg_print_syntax(stdout,argtable2,"\n");
|
||||||
|
printf("Usage 3: %s ", progname);
|
||||||
|
arg_print_syntax(stdout,argtable3,"\n");
|
||||||
printf("\nReport bugs on the github github.com/spacefreak18/monocoque.\n");
|
printf("\nReport bugs on the github github.com/spacefreak18/monocoque.\n");
|
||||||
exitcode = E_SUCCESS_AND_EXIT;
|
exitcode = E_SUCCESS_AND_EXIT;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
@ -148,6 +165,7 @@ cleanup:
|
||||||
arg_freetable(argtable0,sizeof(argtable0)/sizeof(argtable0[0]));
|
arg_freetable(argtable0,sizeof(argtable0)/sizeof(argtable0[0]));
|
||||||
arg_freetable(argtable1,sizeof(argtable1)/sizeof(argtable1[0]));
|
arg_freetable(argtable1,sizeof(argtable1)/sizeof(argtable1[0]));
|
||||||
arg_freetable(argtable2,sizeof(argtable2)/sizeof(argtable2[0]));
|
arg_freetable(argtable2,sizeof(argtable2)/sizeof(argtable2[0]));
|
||||||
|
arg_freetable(argtable3,sizeof(argtable3)/sizeof(argtable3[0]));
|
||||||
return exitcode;
|
return exitcode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@ Parameters;
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
A_PLAY = 0,
|
A_PLAY = 0,
|
||||||
A_CONFIG_TACH = 1,
|
A_TEST = 1,
|
||||||
A_CONFIG_SHAKER = 2
|
A_CONFIG_TACH = 2,
|
||||||
|
A_CONFIG_SHAKER = 3
|
||||||
}
|
}
|
||||||
ProgramAction;
|
ProgramAction;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,8 @@ int main(int argc, char** argv)
|
||||||
SimDevice* tachdev = malloc(sizeof(SimDevice));
|
SimDevice* tachdev = malloc(sizeof(SimDevice));
|
||||||
SimData* sdata = malloc(sizeof(SimData));
|
SimData* sdata = malloc(sizeof(SimData));
|
||||||
DeviceSettings* ds = malloc(sizeof(DeviceSettings));
|
DeviceSettings* ds = malloc(sizeof(DeviceSettings));
|
||||||
|
|
||||||
error = devsetup("USB", "Tachometer", "None", ms, ds, NULL);
|
error = devsetup("USB", "Tachometer", "None", ms, ds, NULL);
|
||||||
error = devinit(tachdev, ds);
|
|
||||||
slogi("configuring tachometer with max revs: %i, granularity: %i, saving to %s", p->max_revs, p->granularity, p->save_file);
|
|
||||||
|
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
if (error != MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
|
|
@ -123,33 +122,37 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
error = devinit(tachdev, 1, ds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error != MONOCOQUE_ERROR_NONE)
|
||||||
|
{
|
||||||
|
sloge("Could not proceed with tachometer configuration due to error: %i", error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slogi("configuring tachometer with max revs: %i, granularity: %i, saving to %s", p->max_revs, p->granularity, p->save_file);
|
||||||
config_tachometer(p->max_revs, p->granularity, p->save_file, tachdev, sdata);
|
config_tachometer(p->max_revs, p->granularity, p->save_file, tachdev, sdata);
|
||||||
}
|
}
|
||||||
devfree(tachdev);
|
devfree(tachdev, 1);
|
||||||
free(tachdev);
|
//free(tachdev);
|
||||||
free(sdata);
|
free(sdata);
|
||||||
free(ds);
|
free(ds);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
slogi("running monocoque in gameloop mode..");
|
|
||||||
int error = 0;
|
|
||||||
|
|
||||||
error = strtogame(p->sim_string, ms);
|
int error = 0;
|
||||||
if (error != MONOCOQUE_ERROR_NONE)
|
|
||||||
{
|
|
||||||
goto cleanup_final;
|
|
||||||
}
|
|
||||||
|
|
||||||
int configureddevices = config_setting_length(config_devices);
|
int configureddevices = config_setting_length(config_devices);
|
||||||
int numdevices = 0;
|
int numdevices = 0;
|
||||||
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;
|
||||||
while (i<configureddevices)
|
while (i<configureddevices)
|
||||||
{
|
{
|
||||||
error = MONOCOQUE_ERROR_NONE;
|
error = MONOCOQUE_ERROR_NONE;
|
||||||
DeviceSettings* settings = malloc(sizeof(DeviceSettings));
|
DeviceSettings settings;
|
||||||
ds[i] = settings;
|
ds[i] = 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);
|
||||||
const char* device_type;
|
const char* device_type;
|
||||||
|
|
@ -161,7 +164,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
error = devsetup(device_type, device_subtype, device_config_file, ms, ds[i], config_device);
|
error = devsetup(device_type, device_subtype, device_config_file, ms, &ds[i], config_device);
|
||||||
}
|
}
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
|
|
@ -175,47 +178,52 @@ int main(int argc, char** argv)
|
||||||
i = 0;
|
i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
error = MONOCOQUE_ERROR_NONE;
|
error = MONOCOQUE_ERROR_NONE;
|
||||||
SimDevice* devices[numdevices];
|
SimDevice* devices = malloc(numdevices * sizeof(SimDevice));
|
||||||
while (i<configureddevices)
|
int initdevices = devinit(devices, configureddevices, ds);
|
||||||
{
|
|
||||||
if (ds[i]->is_valid == true)
|
|
||||||
{
|
|
||||||
SimDevice* device = malloc(sizeof(SimDevice));
|
|
||||||
devinit(device, ds[i]);
|
|
||||||
devices[j] = device;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = looper(devices, numdevices, ms->sim_name);
|
if (p->program_action == A_PLAY)
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
|
||||||
{
|
{
|
||||||
slogi("Game loop exited succesfully with error code: %i", error);
|
slogi("running monocoque in gameloop mode..");
|
||||||
|
error = strtogame(p->sim_string, ms);
|
||||||
|
if (error != MONOCOQUE_ERROR_NONE)
|
||||||
|
{
|
||||||
|
goto cleanup_final;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
error = looper(devices, initdevices, ms->sim_name);
|
||||||
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
|
{
|
||||||
|
slogi("Game loop exited succesfully with error code: %i", error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sloge("Game loop exited with error code: %i", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sloge("Game loop exited with error code: %i", error);
|
slogi("running monocoque in test mode...");
|
||||||
}
|
error = tester(devices, initdevices);
|
||||||
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
i = 0;
|
|
||||||
while (i<configureddevices)
|
|
||||||
{
|
|
||||||
if(ds[i]->dev_subtype == SIMDEV_USB)
|
|
||||||
{
|
{
|
||||||
free(ds[i]->tachsettings.pulses_array);
|
slogi("Test exited succesfully with error code: %i", error);
|
||||||
free(ds[i]->tachsettings.rpms_array);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sloge("Test exited with error code: %i", error);
|
||||||
}
|
}
|
||||||
free(ds[i]);
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
devfree(devices, initdevices);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i<numdevices)
|
// improve the api around the config helper
|
||||||
|
// i don't like that i stack allocated but hid a malloc inside
|
||||||
|
for( i = 0; i < configureddevices; i++)
|
||||||
{
|
{
|
||||||
devfree(devices[i]);
|
settingsfree(ds[i]);
|
||||||
free(devices[i]);
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,5 @@
|
||||||
SUBSYSTEMS=="usb",ATTRS{product}=="Rev Burner",GROUP="input",TAG+="uaccess"
|
SUBSYSTEMS=="usb",ATTRS{product}=="Rev Burner",GROUP="input",TAG+="uaccess"
|
||||||
|
|
||||||
|
|
||||||
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0043", ATTRS{serial}=="75033303335351A080F0", SYMLINK+="simdev0", GROUP="input", TAG+="uaccess"
|
||||||
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0043", ATTRS{serial}=="242303138313514131F1", SYMLINK+="simdev1", GROUP="input", TAG+="uaccess"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue