Add beginnings of custom arduino devices.
This commit is contained in:
parent
433e2423e8
commit
e380f3a9d4
|
|
@ -134,7 +134,7 @@ int arduino_init(SerialDevice* serialdevice, const char* portdev)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int arduino_customled_init(SerialDevice* serialdevice, const char* portdev, const char* luafile)
|
int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const char* luafile, bool uselights)
|
||||||
{
|
{
|
||||||
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
|
||||||
|
|
||||||
|
|
@ -142,11 +142,14 @@ int arduino_customled_init(SerialDevice* serialdevice, const char* portdev, cons
|
||||||
int numlights = 0;
|
int numlights = 0;
|
||||||
|
|
||||||
monocoque_serial_device serialdev = monocoque_serial_devices[serialdevice->id];
|
monocoque_serial_device serialdev = monocoque_serial_devices[serialdevice->id];
|
||||||
int error = GetNumberOfLeds(serialdevice, &numlights);
|
int error = 0;
|
||||||
|
if(uselights == true)
|
||||||
|
{
|
||||||
|
error = GetNumberOfLeds(serialdevice, &numlights);
|
||||||
slogi("numlights is %i\n", numlights);
|
slogi("numlights is %i\n", numlights);
|
||||||
// close, error and free if numlights is 0
|
// close, error and free if numlights is 0
|
||||||
serialdevice->numleds = numlights;
|
serialdevice->numleds = numlights;
|
||||||
|
}
|
||||||
|
|
||||||
if(luafile == NULL)
|
if(luafile == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -394,3 +397,32 @@ int arduino_customled_free(SerialDevice* serialdevice, bool lua)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arduino_custom_update(SerialDevice* serialdevice, SimData* simdata)
|
||||||
|
{
|
||||||
|
|
||||||
|
size_t bufsize = 14;
|
||||||
|
char bytes[bufsize];
|
||||||
|
lua_State* L = serialdevice->m.L;
|
||||||
|
|
||||||
|
lua_pushstring(L, "buff");
|
||||||
|
lua_settable(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
|
simdata_to_lua(L, simdata);
|
||||||
|
lua_setglobal(L, "simdata");
|
||||||
|
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t size = sizeof(bytes);
|
||||||
|
int result = arduino_update(serialdevice, &bytes, size);
|
||||||
|
|
||||||
|
slogt("custom led wrote %i bytes", result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,9 @@
|
||||||
|
|
||||||
int arduino_simled_update(SerialDevice* serialdevice, 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_custom_init(SerialDevice* serialdevice, const char* portdev, const char* luafile, bool useleds);
|
||||||
int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata);
|
int arduino_customled_update(SerialDevice* serialdevice, SimData* simdata);
|
||||||
|
int arduino_custom_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,15 @@ int serialdev_update(SimDevice* this, SimData* simdata)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arduino_custom_updater(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
||||||
|
arduino_custom_update(serialdevice, simdata);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int arduino_customled_updater(SimDevice* this, SimData* simdata)
|
int arduino_customled_updater(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
|
@ -219,14 +228,22 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
||||||
break;
|
break;
|
||||||
case ARDUINODEV__SIMLED__CUSTOM:
|
case ARDUINODEV__SIMLED__CUSTOM:
|
||||||
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, serialdevice->m.device_specific_config_file);
|
error = arduino_custom_init(serialdevice, ds->serialdevsettings.portdev, serialdevice->m.device_specific_config_file, true);
|
||||||
|
if(error < 0)
|
||||||
|
{
|
||||||
|
free(serialdevice->m.device_specific_config_file);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ARDUINODEV__CUSTOM:
|
||||||
|
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||||
|
error = arduino_custom_init(serialdevice, ds->serialdevsettings.portdev, serialdevice->m.device_specific_config_file, false);
|
||||||
if(error < 0)
|
if(error < 0)
|
||||||
{
|
{
|
||||||
free(serialdevice->m.device_specific_config_file);
|
free(serialdevice->m.device_specific_config_file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ARDUINODEV__SIMLED:
|
case ARDUINODEV__SIMLED:
|
||||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, NULL);
|
error = arduino_custom_init(serialdevice, ds->serialdevsettings.portdev, NULL, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error = arduino_init(serialdevice, ds->serialdevsettings.portdev);
|
error = arduino_init(serialdevice, ds->serialdevsettings.portdev);
|
||||||
|
|
@ -240,6 +257,7 @@ 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_updater, &serialdev_free };
|
static const vtable arduino_simled_vtable = { &arduino_simled_updater, &serialdev_free };
|
||||||
|
static const vtable arduino_custom_vtable = { &arduino_custom_updater, &serialdev_free };
|
||||||
static const vtable arduino_simled_custom_vtable = { &arduino_customled_updater, &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 };
|
||||||
|
|
@ -288,6 +306,11 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||||
this->m.vtable = &arduino_simwind_vtable;
|
this->m.vtable = &arduino_simwind_vtable;
|
||||||
slogi("Initializing arduino devices for sim wind.");
|
slogi("Initializing arduino devices for sim wind.");
|
||||||
break;
|
break;
|
||||||
|
case (SIMDEVTYPE_ARDUINOCUSTOM):
|
||||||
|
this->devicetype = ARDUINODEV__CUSTOM;
|
||||||
|
this->m.vtable = &arduino_simwind_vtable;
|
||||||
|
slogi("Initializing custom arduino device.");
|
||||||
|
break;
|
||||||
case (SIMDEVTYPE_SERIALHAPTIC):
|
case (SIMDEVTYPE_SERIALHAPTIC):
|
||||||
this->devicetype = ARDUINODEV__HAPTIC;
|
this->devicetype = ARDUINODEV__HAPTIC;
|
||||||
this->m.vtable = &arduino_simhaptic_vtable;
|
this->m.vtable = &arduino_simhaptic_vtable;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ typedef enum
|
||||||
ARDUINODEV__HAPTIC = 2,
|
ARDUINODEV__HAPTIC = 2,
|
||||||
SERIALDEV__MOZAR5 = 3,
|
SERIALDEV__MOZAR5 = 3,
|
||||||
ARDUINODEV__SIMLED = 4,
|
ARDUINODEV__SIMLED = 4,
|
||||||
ARDUINODEV__SIMLED__CUSTOM = 5
|
ARDUINODEV__SIMLED__CUSTOM = 5,
|
||||||
|
ARDUINODEV__CUSTOM = 6
|
||||||
}
|
}
|
||||||
SerialDeviceType;
|
SerialDeviceType;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,11 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||||
ds->dev_subtype = SIMDEVTYPE_SIMLED;
|
ds->dev_subtype = SIMDEVTYPE_SIMLED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (strcicmp(device_subtype, "ArduinoCustom") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_ARDUINOCUSTOM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (strcicmp(device_subtype, "SimWind") == 0)
|
if (strcicmp(device_subtype, "SimWind") == 0)
|
||||||
{
|
{
|
||||||
ds->dev_subtype = SIMDEVTYPE_SIMWIND;
|
ds->dev_subtype = SIMDEVTYPE_SIMWIND;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ typedef enum
|
||||||
SIMDEVTYPE_SERIALHAPTIC = 5,
|
SIMDEVTYPE_SERIALHAPTIC = 5,
|
||||||
SIMDEVTYPE_USBWHEEL = 6,
|
SIMDEVTYPE_USBWHEEL = 6,
|
||||||
SIMDEVTYPE_SERIALWHEEL = 7,
|
SIMDEVTYPE_SERIALWHEEL = 7,
|
||||||
SIMDEVTYPE_SIMLED = 8
|
SIMDEVTYPE_SIMLED = 8,
|
||||||
|
SIMDEVTYPE_ARDUINOCUSTOM = 9
|
||||||
}
|
}
|
||||||
DeviceSubType;
|
DeviceSubType;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue