Add ability to use lua on cammus c12
This commit is contained in:
parent
367c6fed34
commit
5dc00eb4ce
|
|
@ -119,15 +119,14 @@ int arduino_customled_init(SerialDevice* serialdevice, const char* portdev, cons
|
||||||
}
|
}
|
||||||
lua_setglobal(L,"myFunc");
|
lua_setglobal(L,"myFunc");
|
||||||
|
|
||||||
serialdevice->L = L;
|
serialdevice->m.L = L;
|
||||||
|
|
||||||
return serialdevice->id;
|
return serialdevice->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int arduino_simled_update(SimDevice* this, SimData* simdata)
|
int arduino_simled_update(SerialDevice* serialdevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
int total_leds = serialdevice->numleds;
|
int total_leds = serialdevice->numleds;
|
||||||
|
|
@ -211,9 +210,8 @@ int arduino_simled_update(SimDevice* this, SimData* simdata)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int arduino_customled_update(SimDevice* this, SimData* simdata)
|
int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
int total_leds = serialdevice->numleds;
|
int total_leds = serialdevice->numleds;
|
||||||
|
|
@ -240,7 +238,7 @@ int arduino_customled_update(SimDevice* this, SimData* simdata)
|
||||||
bytes[bufsize-3] = 0xff;
|
bytes[bufsize-3] = 0xff;
|
||||||
|
|
||||||
|
|
||||||
lua_State* L = serialdevice->L;
|
lua_State* L = serialdevice->m.L;
|
||||||
|
|
||||||
lua_pushstring(L, "buff");
|
lua_pushstring(L, "buff");
|
||||||
lua_pushlightuserdata(L, &bytes);
|
lua_pushlightuserdata(L, &bytes);
|
||||||
|
|
@ -325,7 +323,7 @@ int arduino_customled_free(SerialDevice* serialdevice, bool lua)
|
||||||
|
|
||||||
if(lua == true)
|
if(lua == true)
|
||||||
{
|
{
|
||||||
lua_close(serialdevice->L);
|
lua_close(serialdevice->m.L);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@
|
||||||
#include "../serialdevice.h"
|
#include "../serialdevice.h"
|
||||||
|
|
||||||
|
|
||||||
int arduino_simled_update(SimDevice* this, SimData* simdata);
|
int arduino_simled_update(SerialDevice* serialdevice, SimData* simdata);
|
||||||
int arduino_update(SerialDevice* serialdevice, void* data, size_t size);
|
int arduino_update(SerialDevice* serialdevice, void* data, size_t size);
|
||||||
int arduino_customled_init(SerialDevice* serialdevice, const char* portdev, const char* luafile);
|
int arduino_customled_init(SerialDevice* serialdevice, const char* portdev, const char* luafile);
|
||||||
int arduino_customled_update(SimDevice* this, SimData* simdata);
|
int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata);
|
||||||
int arduino_init(SerialDevice* serialdevice, const char* portdev);
|
int arduino_init(SerialDevice* serialdevice, const char* portdev);
|
||||||
int arduino_free(SerialDevice* serialdevice);
|
int arduino_free(SerialDevice* serialdevice);
|
||||||
int arduino_customled_free(SerialDevice* serialdevice, bool lua);
|
int arduino_customled_free(SerialDevice* serialdevice, bool lua);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,24 @@ int serialdev_update(SimDevice* this, SimData* simdata)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arduino_customled_updater(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
||||||
|
arduino_customled_update(serialdevice, simdata);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int arduino_simled_updater(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
||||||
|
arduino_simled_update(serialdevice, simdata);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int arduino_shiftlights_update(SimDevice* this, SimData* simdata)
|
int arduino_shiftlights_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
@ -199,7 +217,7 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
||||||
error = moza_init(serialdevice, ds->serialdevsettings.portdev);
|
error = moza_init(serialdevice, ds->serialdevsettings.portdev);
|
||||||
break;
|
break;
|
||||||
case ARDUINODEV__SIMLED__CUSTOM:
|
case ARDUINODEV__SIMLED__CUSTOM:
|
||||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, ds->serialdevsettings.config_file);
|
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, ds->specific_config_file);
|
||||||
break;
|
break;
|
||||||
case ARDUINODEV__SIMLED:
|
case ARDUINODEV__SIMLED:
|
||||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, NULL);
|
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, NULL);
|
||||||
|
|
@ -215,8 +233,8 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
||||||
|
|
||||||
static const vtable serial_simdevice_vtable = { &serialdev_update, &serialdev_free };
|
static const vtable serial_simdevice_vtable = { &serialdev_update, &serialdev_free };
|
||||||
static const vtable arduino_shiftlights_vtable = { &arduino_shiftlights_update, &serialdev_free };
|
static const vtable arduino_shiftlights_vtable = { &arduino_shiftlights_update, &serialdev_free };
|
||||||
static const vtable arduino_simled_vtable = { &arduino_simled_update, &serialdev_free };
|
static const vtable arduino_simled_vtable = { &arduino_simled_updater, &serialdev_free };
|
||||||
static const vtable arduino_simled_custom_vtable = { &arduino_customled_update, &serialdev_free };
|
static const vtable arduino_simled_custom_vtable = { &arduino_customled_updater, &serialdev_free };
|
||||||
static const vtable arduino_simwind_vtable = { &arduino_simwind_update, &serialdev_free };
|
static const vtable arduino_simwind_vtable = { &arduino_simwind_update, &serialdev_free };
|
||||||
static const vtable arduino_simhaptic_vtable = { &arduino_simhaptic_update, &serialdev_free };
|
static const vtable arduino_simhaptic_vtable = { &arduino_simhaptic_update, &serialdev_free };
|
||||||
static const vtable serialwheel_vtable = { &serial_wheel_update, &serial_wheel_free };
|
static const vtable serialwheel_vtable = { &serial_wheel_update, &serial_wheel_free };
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,16 @@
|
||||||
#define _SIMDEVICE_H
|
#define _SIMDEVICE_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <hidapi/hidapi.h>
|
||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
#include "usbdevice.h"
|
#include "usbdevice.h"
|
||||||
#include "sounddevice.h"
|
#include "sounddevice.h"
|
||||||
#include "serialdevice.h"
|
#include "serialdevice.h"
|
||||||
|
|
||||||
#include "hapticeffect.h"
|
#include "hapticeffect.h"
|
||||||
|
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
|
||||||
|
|
@ -27,6 +30,7 @@ struct SimDevice
|
||||||
int id;
|
int id;
|
||||||
int fps;
|
int fps;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
lua_State* L;
|
||||||
DeviceType type;
|
DeviceType type;
|
||||||
HapticEffect hapticeffect;
|
HapticEffect hapticeffect;
|
||||||
};
|
};
|
||||||
|
|
@ -51,7 +55,7 @@ typedef struct
|
||||||
int id;
|
int id;
|
||||||
SerialType type;
|
SerialType type;
|
||||||
struct sp_port* port;
|
struct sp_port* port;
|
||||||
lua_State* L;
|
|
||||||
SerialDeviceType devicetype;
|
SerialDeviceType devicetype;
|
||||||
// move these two they only apply to the haptic device
|
// move these two they only apply to the haptic device
|
||||||
int motorsposition;
|
int motorsposition;
|
||||||
|
|
@ -93,6 +97,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
SimDevice m;
|
SimDevice m;
|
||||||
int id;
|
int id;
|
||||||
|
hid_device* handle;
|
||||||
USBType type;
|
USBType type;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
|
@ -145,4 +150,16 @@ int devfree(SimDevice* simdevices, int numdevices);
|
||||||
|
|
||||||
int simdevfree(SimDevice* this);
|
int simdevfree(SimDevice* this);
|
||||||
|
|
||||||
|
|
||||||
|
/****** USB SubTypes ****************/
|
||||||
|
int wheeldev_update(USBDevice* usbdevice, SimData* simdata);
|
||||||
|
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds);
|
||||||
|
int wheeldev_free(USBDevice* usbdevice);
|
||||||
|
|
||||||
|
int tachdev_update(USBDevice* tachdevice, SimData* simdata);
|
||||||
|
int tachdev_init(USBDevice* tachdevice, DeviceSettings* ds);
|
||||||
|
int tachdev_free(USBDevice* tachdevice);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,16 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tachdevice.h"
|
//#include "tachdevice.h"
|
||||||
#include "revburner.h"
|
#include "simdevice.h"
|
||||||
#include "../../helper/confighelper.h"
|
#include "usb/revburner.h"
|
||||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../../slog/slog.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
int tachdev_update(TachDevice* tachdevice, SimData* simdata)
|
int tachdev_update(USBDevice* usbdevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
|
TachDevice* tachdevice = &usbdevice->u.tachdevice;
|
||||||
// current plan is to just use the revburner xml format for other possible tachometer devices
|
// current plan is to just use the revburner xml format for other possible tachometer devices
|
||||||
// with that assumption this same logic is assumed the same for other tachometer devices
|
// with that assumption this same logic is assumed the same for other tachometer devices
|
||||||
// the only difference then being in communication to the physical device
|
// the only difference then being in communication to the physical device
|
||||||
|
|
@ -43,30 +45,33 @@ int tachdev_update(TachDevice* tachdevice, SimData* simdata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slogt("Settings tachometer pulses to %i", pulses);
|
slogt("Settings tachometer pulses to %i", pulses);
|
||||||
revburner_update(tachdevice, pulses);
|
revburner_update(usbdevice, pulses);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tachdev_free(TachDevice* tachdevice)
|
int tachdev_free(USBDevice* usbdevice)
|
||||||
{
|
{
|
||||||
|
TachDevice* tachdevice = &usbdevice->u.tachdevice;
|
||||||
switch ( tachdevice->type )
|
switch ( tachdevice->type )
|
||||||
{
|
{
|
||||||
case TACHDEV_UNKNOWN :
|
case TACHDEV_UNKNOWN :
|
||||||
case TACHDEV_REVBURNER :
|
case TACHDEV_REVBURNER :
|
||||||
revburner_update(tachdevice, 0);
|
revburner_update(usbdevice, 0);
|
||||||
revburner_free(tachdevice);
|
revburner_free(usbdevice);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tachdev_init(TachDevice* tachdevice, DeviceSettings* ds)
|
int tachdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
slogi("initializing tachometer device...");
|
slogi("initializing tachometer device...");
|
||||||
|
|
||||||
|
TachDevice* tachdevice = &usbdevice->u.tachdevice;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
// detection of tach device model
|
// detection of tach device model
|
||||||
tachdevice->type = TACHDEV_UNKNOWN;
|
tachdevice->type = TACHDEV_UNKNOWN;
|
||||||
|
|
@ -74,7 +79,7 @@ int tachdev_init(TachDevice* tachdevice, DeviceSettings* ds)
|
||||||
|
|
||||||
tachdevice->tachsettings = ds->tachsettings;
|
tachdevice->tachsettings = ds->tachsettings;
|
||||||
|
|
||||||
error = revburner_init(tachdevice);
|
error = revburner_init(usbdevice);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _TACHDEVICE_H
|
#ifndef _TACHDEVICE_H
|
||||||
#define _TACHDEVICE_H
|
#define _TACHDEVICE_H
|
||||||
|
|
||||||
#include <hidapi/hidapi.h>
|
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
|
||||||
|
|
@ -19,13 +19,10 @@ typedef struct
|
||||||
int id;
|
int id;
|
||||||
TachType type;
|
TachType type;
|
||||||
bool use_pulses;
|
bool use_pulses;
|
||||||
hid_device* handle;
|
|
||||||
TachometerSettings tachsettings;
|
TachometerSettings tachsettings;
|
||||||
}
|
}
|
||||||
TachDevice;
|
TachDevice;
|
||||||
|
|
||||||
int tachdev_update(TachDevice* tachdevice, SimData* simdata);
|
|
||||||
int tachdev_init(TachDevice* tachdevice, DeviceSettings* ds);
|
|
||||||
int tachdev_free(TachDevice* tachdevice);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
#include <hidapi/hidapi.h>
|
#include <hidapi/hidapi.h>
|
||||||
|
|
||||||
#include "tachdevice.h"
|
#include "../simdevice.h"
|
||||||
#include "../slog/slog.h"
|
#include "../../slog/slog.h"
|
||||||
|
|
||||||
const size_t REVBURNER_BUFSIZE = 8;
|
const size_t REVBURNER_BUFSIZE = 8;
|
||||||
|
|
||||||
|
|
||||||
int revburner_update(TachDevice* tachdevice, int pulses)
|
int revburner_update(USBDevice* tachdevice, int pulses)
|
||||||
{
|
{
|
||||||
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
@ -37,7 +37,7 @@ int revburner_update(TachDevice* tachdevice, int pulses)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int revburner_free(TachDevice* tachdevice)
|
int revburner_free(USBDevice* tachdevice)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ int revburner_free(TachDevice* tachdevice)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int revburner_init(TachDevice* tachdevice)
|
int revburner_init(USBDevice* tachdevice)
|
||||||
{
|
{
|
||||||
slogi("initializing revburner tachometer...");
|
slogi("initializing revburner tachometer...");
|
||||||
//tachdevice->update_tachometer = revburner_device_update;
|
//tachdevice->update_tachometer = revburner_device_update;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
#ifndef _REVBURNER_H
|
#ifndef _REVBURNER_H
|
||||||
#define _REVBURNER_H
|
#define _REVBURNER_H
|
||||||
|
|
||||||
int revburner_update(TachDevice* tachdevice, int pulses);
|
#include "../simdevice.h"
|
||||||
int revburner_init(TachDevice* tachdevice);
|
|
||||||
int revburner_free(TachDevice* tachdevice);
|
int revburner_update(USBDevice* tachdevice, int pulses);
|
||||||
|
int revburner_init(USBDevice* tachdevice);
|
||||||
|
int revburner_free(USBDevice* tachdevice);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,15 @@
|
||||||
#include <hidapi/hidapi.h>
|
#include <hidapi/hidapi.h>
|
||||||
|
|
||||||
#include "cammusc12.h"
|
#include "cammusc12.h"
|
||||||
|
#include "../../serial/arduinoledlua.h"
|
||||||
#include "../../../slog/slog.h"
|
#include "../../../slog/slog.h"
|
||||||
|
|
||||||
const int cammusc12_hidupdate_buf_size = 16;
|
const int cammusc12_hidupdate_buf_size = 16;
|
||||||
|
const int cammusc12_hidledupdate_buf_size = 7;
|
||||||
|
|
||||||
int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity)
|
const int cammusc12_total_leds = 15;
|
||||||
|
|
||||||
|
int cammusc12_update(USBDevice* usbdevice, int maxrpm, int rpm, int gear, int velocity)
|
||||||
{
|
{
|
||||||
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
@ -43,9 +47,9 @@ int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, in
|
||||||
bytes[6] = gear-1;
|
bytes[6] = gear-1;
|
||||||
|
|
||||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x%02x%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], rpm, velocity, gear);
|
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x%02x%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], rpm, velocity, gear);
|
||||||
if (wheeldevice->handle)
|
if (usbdevice->handle)
|
||||||
{
|
{
|
||||||
res = hid_write(wheeldevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
res = hid_write(usbdevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -55,7 +59,7 @@ int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, in
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cammusc12_free(WheelDevice* wheeldevice)
|
int cammusc12_free(USBDevice* wheeldevice)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
|
|
@ -65,7 +69,7 @@ int cammusc12_free(WheelDevice* wheeldevice)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cammusc12_init(WheelDevice* wheeldevice)
|
int cammusc12_init_(USBDevice* wheeldevice)
|
||||||
{
|
{
|
||||||
slogi("initializing cammus c12 wheel...");
|
slogi("initializing cammus c12 wheel...");
|
||||||
|
|
||||||
|
|
@ -84,3 +88,119 @@ int cammusc12_init(WheelDevice* wheeldevice)
|
||||||
slogd("Found Cammus C12 Wheel...");
|
slogd("Found Cammus C12 Wheel...");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cammusc12_init(USBDevice* wheeldevice, const char* luafile)
|
||||||
|
{
|
||||||
|
|
||||||
|
int res = cammusc12_init_(wheeldevice);
|
||||||
|
if(luafile == NULL)
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_State* L = luaL_newstate();
|
||||||
|
luaL_openlibs(L);
|
||||||
|
|
||||||
|
int top=lua_gettop(L);
|
||||||
|
int status = luaL_loadfile(L, luafile);
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
/* If something went wrong, error message is at the top of */
|
||||||
|
/* the stack */
|
||||||
|
sloge("There is an issue with your lua script");
|
||||||
|
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
|
||||||
|
//exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_setglobal(L,"myFunc");
|
||||||
|
|
||||||
|
wheeldevice->m.L = L;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int cammusc12_customled_update(USBDevice* usbdevice, SimData* simdata)
|
||||||
|
{
|
||||||
|
int result = 1;
|
||||||
|
|
||||||
|
|
||||||
|
size_t bufsize = (cammusc12_total_leds * 3);
|
||||||
|
char ledbytes[bufsize];
|
||||||
|
|
||||||
|
|
||||||
|
lua_State* L = usbdevice->m.L;
|
||||||
|
|
||||||
|
lua_pushstring(L, "buff");
|
||||||
|
lua_pushlightuserdata(L, &ledbytes);
|
||||||
|
lua_settable(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
|
simdata_to_lua(L, simdata);
|
||||||
|
lua_setglobal(L, "simdata");
|
||||||
|
|
||||||
|
lua_pushinteger(L, cammusc12_total_leds);
|
||||||
|
lua_setglobal(L, "TotalLeds");
|
||||||
|
|
||||||
|
lua_register(L, "set_led_to_color", set_led_to_color);
|
||||||
|
lua_register(L, "set_led_range_to_color", set_led_range_to_color);
|
||||||
|
lua_register(L, "set_led_to_rgb_color", set_led_to_rgb_color);
|
||||||
|
lua_register(L, "set_led_range_to_rgb_color", set_led_range_to_rgb_color);
|
||||||
|
lua_register(L, "led_clear_all", led_clear_all);
|
||||||
|
|
||||||
|
lua_pushinteger(L, LUALEDCOLOR_RED);
|
||||||
|
lua_setglobal(L, "RED");
|
||||||
|
lua_pushinteger(L, LUALEDCOLOR_GREEN);
|
||||||
|
lua_setglobal(L, "GREEN");
|
||||||
|
lua_pushinteger(L, LUALEDCOLOR_BLUE);
|
||||||
|
lua_setglobal(L, "BLUE");
|
||||||
|
lua_pushinteger(L, LUALEDCOLOR_YELLOW);
|
||||||
|
lua_setglobal(L, "YELLOW");
|
||||||
|
lua_pushinteger(L, LUALEDCOLOR_ORANGE);
|
||||||
|
lua_setglobal(L, "ORANGE");
|
||||||
|
|
||||||
|
lua_getglobal(L,"myFunc");
|
||||||
|
if (lua_pcall(L, 0, 0, 0) != LUA_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error calling Lua script: %s\n", lua_tostring(L, -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
unsigned char bytes[cammusc12_hidledupdate_buf_size];
|
||||||
|
for(int x = 0; x < cammusc12_hidledupdate_buf_size; x++)
|
||||||
|
{
|
||||||
|
bytes[x] = 0x00;
|
||||||
|
}
|
||||||
|
bytes[0] = 0xFA;
|
||||||
|
bytes[1] = 0xFB;
|
||||||
|
bytes[2] = 0x02;
|
||||||
|
|
||||||
|
for(int i = 0; i < cammusc12_total_leds; i++)
|
||||||
|
{
|
||||||
|
for (int x = 3; x < cammusc12_hidledupdate_buf_size; x++)
|
||||||
|
{
|
||||||
|
bytes[x] = 0x00;
|
||||||
|
}
|
||||||
|
uint8_t led = i;
|
||||||
|
uint8_t red = ledbytes[(i * 3) + 0];
|
||||||
|
uint8_t green = ledbytes[(i * 3) + 1];
|
||||||
|
uint8_t blue = ledbytes[(i * 3) + 2];
|
||||||
|
|
||||||
|
bytes[3] = led;
|
||||||
|
bytes[4] = red;
|
||||||
|
bytes[5] = green;
|
||||||
|
bytes[6] = blue;
|
||||||
|
|
||||||
|
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x%02x%02x from red %i green %i blue %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], red, green, blue);
|
||||||
|
if (usbdevice->handle)
|
||||||
|
{
|
||||||
|
res = hid_write(usbdevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slogd("no handle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
#include "../../wheeldevice.h"
|
#include "../../wheeldevice.h"
|
||||||
|
|
||||||
int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
#include "../../simdevice.h"
|
||||||
int cammusc12_init(WheelDevice* wheeldevice);
|
|
||||||
int cammusc12_free(WheelDevice* wheeldevice);
|
int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||||
|
int cammusc12_init(USBDevice* wheeldevice, const char* luafile);
|
||||||
|
int cammusc12_free(USBDevice* wheeldevice);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
const int cammusc5_hidupdate_buf_size = 14;
|
const int cammusc5_hidupdate_buf_size = 14;
|
||||||
const int num_avail_leds = 9;
|
const int num_avail_leds = 9;
|
||||||
|
|
||||||
int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity)
|
int cammusc5_update(USBDevice* usbdevice, int maxrpm, int rpm, int gear, int velocity)
|
||||||
{
|
{
|
||||||
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
@ -56,9 +56,9 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
|
||||||
bytes[4] = gear-1;
|
bytes[4] = gear-1;
|
||||||
|
|
||||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], rpm, velocity, gear);
|
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], rpm, velocity, gear);
|
||||||
if (wheeldevice->handle)
|
if (usbdevice->handle)
|
||||||
{
|
{
|
||||||
res = hid_write(wheeldevice->handle, bytes, cammusc5_hidupdate_buf_size);
|
res = hid_write(usbdevice->handle, bytes, cammusc5_hidupdate_buf_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -68,17 +68,17 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cammusc5_free(WheelDevice* wheeldevice)
|
int cammusc5_free(USBDevice* usbdevice)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
hid_close(wheeldevice->handle);
|
hid_close(usbdevice->handle);
|
||||||
res = hid_exit();
|
res = hid_exit();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cammusc5_init(WheelDevice* wheeldevice)
|
int cammusc5_init(USBDevice* usbdevice)
|
||||||
{
|
{
|
||||||
slogi("initializing cammus c5 wheel...");
|
slogi("initializing cammus c5 wheel...");
|
||||||
|
|
||||||
|
|
@ -86,9 +86,9 @@ int cammusc5_init(WheelDevice* wheeldevice)
|
||||||
|
|
||||||
res = hid_init();
|
res = hid_init();
|
||||||
|
|
||||||
wheeldevice->handle = hid_open(0x3416, 0x1021, NULL);
|
usbdevice->handle = hid_open(0x3416, 0x1021, NULL);
|
||||||
|
|
||||||
if (!wheeldevice->handle)
|
if (!usbdevice->handle)
|
||||||
{
|
{
|
||||||
sloge("Could not find attached Cammus C5 Wheel");
|
sloge("Could not find attached Cammus C5 Wheel");
|
||||||
res = hid_exit();
|
res = hid_exit();
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef _CAMMUSC5_H
|
#ifndef _CAMMUSC5_H
|
||||||
#define _CAMMUSC5_H
|
#define _CAMMUSC5_H
|
||||||
|
|
||||||
#include "../../wheeldevice.h"
|
#include "../../simdevice.h"
|
||||||
|
|
||||||
int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
int cammusc5_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||||
int cammusc5_init(WheelDevice* wheeldevice);
|
int cammusc5_init(USBDevice* wheeldevice);
|
||||||
int cammusc5_free(WheelDevice* wheeldevice);
|
int cammusc5_free(USBDevice* wheeldevice);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
case USBDEV_TACHOMETER :
|
case USBDEV_TACHOMETER :
|
||||||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
tachdev_update(usbdevice, simdata);
|
||||||
break;
|
break;
|
||||||
case USBDEV_WHEEL :
|
case USBDEV_WHEEL :
|
||||||
wheeldev_update(&usbdevice->u.wheeldevice, simdata);
|
wheeldev_update(usbdevice, simdata);
|
||||||
break;
|
break;
|
||||||
case USBDEV_GENERICHAPTIC :
|
case USBDEV_GENERICHAPTIC :
|
||||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||||
|
|
@ -39,10 +39,10 @@ int usbdev_free(SimDevice* this)
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
case USBDEV_TACHOMETER :
|
case USBDEV_TACHOMETER :
|
||||||
tachdev_free(&usbdevice->u.tachdevice);
|
tachdev_free(usbdevice);
|
||||||
break;
|
break;
|
||||||
case USBDEV_WHEEL :
|
case USBDEV_WHEEL :
|
||||||
wheeldev_free(&usbdevice->u.wheeldevice);
|
wheeldev_free(usbdevice);
|
||||||
break;
|
break;
|
||||||
case USBDEV_GENERICHAPTIC :
|
case USBDEV_GENERICHAPTIC :
|
||||||
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
||||||
|
|
@ -64,10 +64,10 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
case USBDEV_UNKNOWN :
|
case USBDEV_UNKNOWN :
|
||||||
case USBDEV_TACHOMETER :
|
case USBDEV_TACHOMETER :
|
||||||
error = tachdev_init(&usbdevice->u.tachdevice, ds);
|
error = tachdev_init(usbdevice, ds);
|
||||||
break;
|
break;
|
||||||
case USBDEV_WHEEL :
|
case USBDEV_WHEEL :
|
||||||
error = wheeldev_init(&usbdevice->u.wheeldevice, ds);
|
error = wheeldev_init(usbdevice, ds);
|
||||||
break;
|
break;
|
||||||
case USBDEV_GENERICHAPTIC :
|
case USBDEV_GENERICHAPTIC :
|
||||||
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
||||||
|
|
|
||||||
|
|
@ -5,21 +5,23 @@
|
||||||
#include "usb/wheels/cammusc5.h"
|
#include "usb/wheels/cammusc5.h"
|
||||||
#include "usb/wheels/cammusc12.h"
|
#include "usb/wheels/cammusc12.h"
|
||||||
#include "serial/moza.h"
|
#include "serial/moza.h"
|
||||||
#include "wheeldevice.h"
|
|
||||||
|
#include "simdevice.h"
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
int wheeldev_update(WheelDevice* wheeldevice, SimData* simdata)
|
int wheeldev_update(USBDevice* usbdevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
|
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||||
switch ( wheeldevice->type )
|
switch ( wheeldevice->type )
|
||||||
{
|
{
|
||||||
case WHEELDEV_UNKNOWN :
|
case WHEELDEV_UNKNOWN :
|
||||||
case WHEELDEV_CAMMUSC5 :
|
case WHEELDEV_CAMMUSC5 :
|
||||||
cammusc5_update(wheeldevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
cammusc5_update(usbdevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||||
break;
|
break;
|
||||||
case WHEELDEV_CAMMUSC12 :
|
case WHEELDEV_CAMMUSC12 :
|
||||||
cammusc12_update(wheeldevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
cammusc12_update(usbdevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -27,46 +29,55 @@ int wheeldev_update(WheelDevice* wheeldevice, SimData* simdata)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wheeldev_free(WheelDevice* wheeldevice)
|
int wheeldev_free(USBDevice* usbdevice)
|
||||||
{
|
{
|
||||||
|
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||||
switch ( wheeldevice->type )
|
switch ( wheeldevice->type )
|
||||||
{
|
{
|
||||||
case WHEELDEV_UNKNOWN :
|
case WHEELDEV_UNKNOWN :
|
||||||
case WHEELDEV_CAMMUSC5 :
|
case WHEELDEV_CAMMUSC5 :
|
||||||
cammusc5_update(wheeldevice, 0, 0, 0, 0);
|
cammusc5_update(usbdevice, 0, 0, 0, 0);
|
||||||
cammusc5_free(wheeldevice);
|
cammusc5_free(usbdevice);
|
||||||
break;
|
break;
|
||||||
case WHEELDEV_CAMMUSC12 :
|
case WHEELDEV_CAMMUSC12 :
|
||||||
cammusc12_update(wheeldevice, 0, 0, 0, 0);
|
cammusc12_update(usbdevice, 0, 0, 0, 0);
|
||||||
cammusc12_free(wheeldevice);
|
cammusc12_free(usbdevice);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wheeldev_init(WheelDevice* wheeldevice, DeviceSettings* ds)
|
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||||
{
|
{
|
||||||
slogi("initializing wheel device...");
|
slogi("initializing wheel device...");
|
||||||
int error = 0;
|
int error = 0;
|
||||||
// detection of wheel model
|
// detection of wheel model
|
||||||
|
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
|
||||||
switch (ds->dev_subsubtype) {
|
switch (ds->dev_subsubtype) {
|
||||||
|
|
||||||
case SIMDEVSUBTYPE_CAMMUSC5:
|
case SIMDEVSUBTYPE_CAMMUSC5:
|
||||||
wheeldevice->type = WHEELDEV_CAMMUSC5;
|
wheeldevice->type = WHEELDEV_CAMMUSC5;
|
||||||
slogi("Attempting to initialize cammus C5");
|
slogi("Attempting to initialize cammus C5");
|
||||||
error = cammusc5_init(wheeldevice);
|
error = cammusc5_init(usbdevice);
|
||||||
break;
|
break;
|
||||||
case SIMDEVSUBTYPE_CAMMUSC12:
|
case SIMDEVSUBTYPE_CAMMUSC12:
|
||||||
wheeldevice->type = WHEELDEV_CAMMUSC12;
|
wheeldevice->type = WHEELDEV_CAMMUSC12;
|
||||||
slogi("Attempting to initialize cammus C12");
|
slogi("Attempting to initialize cammus C12");
|
||||||
error = cammusc12_init(wheeldevice);
|
|
||||||
|
if(ds->has_config == true)
|
||||||
|
{
|
||||||
|
error = cammusc12_init(usbdevice, ds->specific_config_file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = cammusc12_init(usbdevice, NULL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
wheeldevice->type = WHEELDEV_UNKNOWN;
|
wheeldevice->type = WHEELDEV_UNKNOWN;
|
||||||
slogw("Unknown cammus wheel detected, trying C5");
|
slogw("Unknown cammus wheel detected, trying C5");
|
||||||
error = cammusc5_init(wheeldevice);
|
error = cammusc5_init(usbdevice);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef _WHEELDEVICE_H
|
#ifndef _WHEELDEVICE_H
|
||||||
#define _WHEELDEVICE_H
|
#define _WHEELDEVICE_H
|
||||||
|
|
||||||
#include <hidapi/hidapi.h>
|
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
|
||||||
|
|
@ -20,13 +19,9 @@ typedef struct
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
WheelType type;
|
WheelType type;
|
||||||
hid_device* handle;
|
|
||||||
char* port;
|
char* port;
|
||||||
}
|
}
|
||||||
WheelDevice;
|
WheelDevice;
|
||||||
|
|
||||||
int wheeldev_update(WheelDevice* wheeldevice, SimData* simdata);
|
|
||||||
int wheeldev_init(WheelDevice* wheeldevice, DeviceSettings* ds);
|
|
||||||
int wheeldev_free(WheelDevice* wheeldevice);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -801,10 +801,13 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
|
|
||||||
slogt("set port baud rate to %i, ampfactor %f", baud, ampfactor);
|
slogt("set port baud rate to %i, ampfactor %f", baud, ampfactor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ds->has_config = false;
|
ds->has_config = false;
|
||||||
const char* temp2;
|
const char* temp2;
|
||||||
found = config_setting_lookup_string(device_settings, "config", &temp2);
|
int found = config_setting_lookup_string(device_settings, "config", &temp2);
|
||||||
slogt("config is %s found is %i", temp2, found);
|
|
||||||
if(strcicmp(temp2, "none") == 0)
|
if(strcicmp(temp2, "none") == 0)
|
||||||
{
|
{
|
||||||
slogt("config set to none");
|
slogt("config set to none");
|
||||||
|
|
@ -812,11 +815,8 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ds->has_config = true;
|
ds->has_config = true;
|
||||||
ds->serialdevsettings.config_file = strdup(temp2);
|
ds->specific_config_file = strdup(temp2);
|
||||||
slogt("will try to load config file at %s", ds->serialdevsettings.config_file);
|
slogt("will try to load config file at %s", ds->specific_config_file);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ TachometerSettings;
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char* portdev;
|
char* portdev;
|
||||||
char* config_file;
|
|
||||||
MotorPosition motorsposition;
|
MotorPosition motorsposition;
|
||||||
int numlights;
|
int numlights;
|
||||||
int numleds;
|
int numleds;
|
||||||
|
|
@ -204,12 +204,12 @@ typedef struct
|
||||||
MonocoqueTyreIdentifier tyre;
|
MonocoqueTyreIdentifier tyre;
|
||||||
double threshold;
|
double threshold;
|
||||||
bool has_config;
|
bool has_config;
|
||||||
|
char* specific_config_file;
|
||||||
// union?
|
// union?
|
||||||
TachometerSettings tachsettings;
|
TachometerSettings tachsettings;
|
||||||
SerialDeviceSettings serialdevsettings;
|
SerialDeviceSettings serialdevsettings;
|
||||||
SoundDeviceSettings sounddevsettings;
|
SoundDeviceSettings sounddevsettings;
|
||||||
USBDeviceSettings usbdevsettings;
|
USBDeviceSettings usbdevsettings;
|
||||||
|
|
||||||
}
|
}
|
||||||
DeviceSettings;
|
DeviceSettings;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue