Compare commits
2
Commits
45f2ef7fef
...
simlights
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1945a0e892 | ||
|
|
20935c33a2 |
+4
-4
@@ -96,10 +96,10 @@ add_subdirectory(src/monocoque/slog)
|
|||||||
#target_link_libraries(hidtest hidapi-hidraw)
|
#target_link_libraries(hidtest hidapi-hidraw)
|
||||||
#add_test(hidtest hidtest)
|
#add_test(hidtest hidtest)
|
||||||
#
|
#
|
||||||
#add_executable(simlighttest tests/simlighttest.c)
|
add_executable(simlighttest tests/simlighttest.c)
|
||||||
#target_include_directories(simlighttest PUBLIC)
|
target_include_directories(simlighttest PUBLIC)
|
||||||
#target_link_libraries(simlighttest serialport)
|
target_link_libraries(simlighttest serialport)
|
||||||
#add_test(simlighttest simlighttest)
|
add_test(simlighttest simlighttest)
|
||||||
|
|
||||||
|
|
||||||
# used for enabling additional compiler options if supported
|
# used for enabling additional compiler options if supported
|
||||||
|
|||||||
@@ -70,6 +70,91 @@ int arduino_shiftlights_update(SimDevice* this, SimData* simdata)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int arduino_simled_update(SimDevice* this, SimData* simdata)
|
||||||
|
{
|
||||||
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
|
int result = 1;
|
||||||
|
|
||||||
|
int total_leds = serialdevice->numleds;
|
||||||
|
size_t bufsize = (total_leds * 3) + 14;
|
||||||
|
char bytes[bufsize];
|
||||||
|
int endled = serialdevice->endled;
|
||||||
|
int startled = serialdevice->startled;
|
||||||
|
if(endled == 0)
|
||||||
|
{
|
||||||
|
endled = total_leds;
|
||||||
|
}
|
||||||
|
int num_avail_leds = endled - startled + 1;
|
||||||
|
int rpm = simdata->rpms;
|
||||||
|
int maxrpm = simdata->maxrpm;
|
||||||
|
int litleds = 0;
|
||||||
|
if(rpm > 0 && maxrpm > 0)
|
||||||
|
{
|
||||||
|
int rpmmargin = ceil(.05*maxrpm);
|
||||||
|
int rpminterval = (maxrpm-rpmmargin) / (num_avail_leds);
|
||||||
|
|
||||||
|
|
||||||
|
for (int l = 1; l <= (num_avail_leds); l++)
|
||||||
|
{
|
||||||
|
if(rpm >= (rpminterval * l))
|
||||||
|
{
|
||||||
|
litleds = l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(int j = 0; j < bufsize; j++)
|
||||||
|
{
|
||||||
|
bytes[j] = 0x00;
|
||||||
|
}
|
||||||
|
bytes[0] = 0xff;
|
||||||
|
bytes[1] = 0xff;
|
||||||
|
bytes[2] = 0xff;
|
||||||
|
bytes[3] = 0xff;
|
||||||
|
bytes[4] = 0xff;
|
||||||
|
bytes[5] = 0xff;
|
||||||
|
bytes[6] = 0x73;
|
||||||
|
bytes[7] = 0x6c;
|
||||||
|
bytes[8] = 0x65;
|
||||||
|
bytes[9] = 0x64;
|
||||||
|
bytes[10] = 0x73;
|
||||||
|
bytes[bufsize-1] = 0xfd;
|
||||||
|
bytes[bufsize-2] = 0xfe;
|
||||||
|
bytes[bufsize-3] = 0xff;
|
||||||
|
|
||||||
|
for(int i = 0; i < litleds; i++)
|
||||||
|
{
|
||||||
|
if(i < ((num_avail_leds) / 2))
|
||||||
|
{
|
||||||
|
//green
|
||||||
|
bytes[11 + ((i + startled - 1) * 3) + 1] = 0xff;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(i < num_avail_leds - 1)
|
||||||
|
{
|
||||||
|
//yellow
|
||||||
|
bytes[11 + ((i + startled - 1) * 3) + 0] = 0xff;
|
||||||
|
bytes[11 + ((i + startled - 1) * 3) + 1] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i == num_avail_leds - 1)
|
||||||
|
{
|
||||||
|
//red
|
||||||
|
bytes[11 + ((i + startled - 1) * 3) + 0] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slogt("Updating arduino device lights to %i", litleds);
|
||||||
|
// we can add configs to set all the colors
|
||||||
|
size_t size = sizeof(bytes);
|
||||||
|
|
||||||
|
arduino_update(serialdevice, &bytes, size);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int arduino_simwind_update(SimDevice* this, SimData* simdata)
|
int arduino_simwind_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SerialDevice* serialdevice = (void *) this->derived;
|
SerialDevice* serialdevice = (void *) this->derived;
|
||||||
@@ -201,6 +286,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_update, &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 };
|
||||||
@@ -223,6 +309,14 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
|||||||
this->m.vtable = &arduino_shiftlights_vtable;
|
this->m.vtable = &arduino_shiftlights_vtable;
|
||||||
slogi("Initializing arduino device for shiftlights.");
|
slogi("Initializing arduino device for shiftlights.");
|
||||||
break;
|
break;
|
||||||
|
case (SIMDEVTYPE_SIMLED):
|
||||||
|
this->devicetype = ARDUINODEV__SIMLED;
|
||||||
|
this->numleds = ds->serialdevsettings.numleds;
|
||||||
|
this->startled = ds->serialdevsettings.startled;
|
||||||
|
this->endled = ds->serialdevsettings.endled;
|
||||||
|
this->m.vtable = &arduino_simled_vtable;
|
||||||
|
slogi("Initializing arduino device for simled.");
|
||||||
|
break;
|
||||||
case (SIMDEVTYPE_SIMWIND):
|
case (SIMDEVTYPE_SIMWIND):
|
||||||
this->devicetype = ARDUINODEV__SIMWIND;
|
this->devicetype = ARDUINODEV__SIMWIND;
|
||||||
this->m.vtable = &arduino_simwind_vtable;
|
this->m.vtable = &arduino_simwind_vtable;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ typedef enum
|
|||||||
ARDUINODEV__SIMWIND = 1,
|
ARDUINODEV__SIMWIND = 1,
|
||||||
ARDUINODEV__HAPTIC = 2,
|
ARDUINODEV__HAPTIC = 2,
|
||||||
SERIALDEV__MOZAR5 = 3,
|
SERIALDEV__MOZAR5 = 3,
|
||||||
|
ARDUINODEV__SIMLED = 4
|
||||||
}
|
}
|
||||||
SerialDeviceType;
|
SerialDeviceType;
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ typedef struct
|
|||||||
// move these two they only apply to the haptic device
|
// move these two they only apply to the haptic device
|
||||||
int motorsposition;
|
int motorsposition;
|
||||||
int numlights;
|
int numlights;
|
||||||
|
int numleds;
|
||||||
|
int startled;
|
||||||
|
int endled;
|
||||||
int baudrate;
|
int baudrate;
|
||||||
double ampfactor;
|
double ampfactor;
|
||||||
double state;
|
double state;
|
||||||
|
|||||||
@@ -145,6 +145,11 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
|||||||
ds->dev_subtype = SIMDEVTYPE_SHIFTLIGHTS;
|
ds->dev_subtype = SIMDEVTYPE_SHIFTLIGHTS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (strcicmp(device_subtype, "Simleds") == 0)
|
||||||
|
{
|
||||||
|
ds->dev_subtype = SIMDEVTYPE_SIMLED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (strcicmp(device_subtype, "SimWind") == 0)
|
if (strcicmp(device_subtype, "SimWind") == 0)
|
||||||
{
|
{
|
||||||
ds->dev_subtype = SIMDEVTYPE_SIMWIND;
|
ds->dev_subtype = SIMDEVTYPE_SIMWIND;
|
||||||
@@ -748,6 +753,18 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||||||
config_setting_lookup_int(device_settings, "numlights", &numlights);
|
config_setting_lookup_int(device_settings, "numlights", &numlights);
|
||||||
ds->serialdevsettings.numlights = numlights;
|
ds->serialdevsettings.numlights = numlights;
|
||||||
|
|
||||||
|
int numleds = 6;
|
||||||
|
config_setting_lookup_int(device_settings, "numleds", &numleds);
|
||||||
|
ds->serialdevsettings.numleds = numleds;
|
||||||
|
|
||||||
|
int startled = 1;
|
||||||
|
config_setting_lookup_int(device_settings, "startled", &startled);
|
||||||
|
ds->serialdevsettings.startled = startled;
|
||||||
|
|
||||||
|
int endled = 1;
|
||||||
|
config_setting_lookup_int(device_settings, "endled", &endled);
|
||||||
|
ds->serialdevsettings.endled = endled;
|
||||||
|
|
||||||
int baud = 9600;
|
int baud = 9600;
|
||||||
config_setting_lookup_int(device_settings, "baud", &baud);
|
config_setting_lookup_int(device_settings, "baud", &baud);
|
||||||
ds->serialdevsettings.baud = baud;
|
ds->serialdevsettings.baud = baud;
|
||||||
@@ -827,7 +844,7 @@ int uiloadconfig(const char* config_file_str, int confignum, int configureddevic
|
|||||||
int settingsfree(DeviceSettings ds)
|
int settingsfree(DeviceSettings ds)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (ds.dev_subtype == SIMDEVTYPE_SIMWIND || ds.dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
if (ds.dev_subtype == SIMDEVTYPE_SIMWIND || ds.dev_subtype == SIMDEVTYPE_SHIFTLIGHTS || ds.dev_subtype == SIMDEVTYPE_SIMLED)
|
||||||
{
|
{
|
||||||
if (ds.serialdevsettings.portdev != NULL)
|
if (ds.serialdevsettings.portdev != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ typedef enum
|
|||||||
SIMDEVTYPE_SIMWIND = 4,
|
SIMDEVTYPE_SIMWIND = 4,
|
||||||
SIMDEVTYPE_SERIALHAPTIC = 5,
|
SIMDEVTYPE_SERIALHAPTIC = 5,
|
||||||
SIMDEVTYPE_USBWHEEL = 6,
|
SIMDEVTYPE_USBWHEEL = 6,
|
||||||
SIMDEVTYPE_SERIALWHEEL = 7
|
SIMDEVTYPE_SERIALWHEEL = 7,
|
||||||
|
SIMDEVTYPE_SIMLED = 8
|
||||||
}
|
}
|
||||||
DeviceSubType;
|
DeviceSubType;
|
||||||
|
|
||||||
@@ -155,6 +156,9 @@ typedef struct
|
|||||||
char* portdev;
|
char* portdev;
|
||||||
MotorPosition motorsposition;
|
MotorPosition motorsposition;
|
||||||
int numlights;
|
int numlights;
|
||||||
|
int numleds;
|
||||||
|
int startled;
|
||||||
|
int endled;
|
||||||
float ampfactor;
|
float ampfactor;
|
||||||
int baud;
|
int baud;
|
||||||
}
|
}
|
||||||
|
|||||||
+79
-18
@@ -10,7 +10,7 @@ int check(enum sp_return result);
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
char* port_name = "/dev/ttyACM0";
|
char* port_name = "/dev/simdev0";
|
||||||
|
|
||||||
/* The ports we will use. */
|
/* The ports we will use. */
|
||||||
struct sp_port* port;
|
struct sp_port* port;
|
||||||
@@ -32,39 +32,100 @@ int main()
|
|||||||
ShiftLightsData sd;
|
ShiftLightsData sd;
|
||||||
|
|
||||||
|
|
||||||
int result;
|
|
||||||
unsigned int timeout = 2000;
|
size_t bufsize1 = 11;
|
||||||
size_t size = sizeof(ShiftLightsData);
|
size_t recv_bufsize1 = 5;
|
||||||
for( sd.litleds = 0; sd.litleds < 7; sd.litleds++)
|
char recv_buf1[recv_bufsize1];
|
||||||
|
char bytes1[bufsize1];
|
||||||
|
|
||||||
|
for(int j = 0; j < bufsize1; j++)
|
||||||
{
|
{
|
||||||
|
bytes1[j] = 0x00;
|
||||||
|
}
|
||||||
|
bytes1[0] = 0xff;
|
||||||
|
bytes1[1] = 0xff;
|
||||||
|
bytes1[2] = 0xff;
|
||||||
|
bytes1[3] = 0xff;
|
||||||
|
bytes1[4] = 0xff;
|
||||||
|
bytes1[5] = 0xff;
|
||||||
|
bytes1[6] = 0x6c;
|
||||||
|
bytes1[7] = 0x65;
|
||||||
|
bytes1[8] = 0x64;
|
||||||
|
bytes1[9] = 0x73;
|
||||||
|
bytes1[10] = 0x63;
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
|
unsigned int timeout = 2000;
|
||||||
|
result = check(sp_blocking_write(port, &bytes1, bufsize1, timeout));
|
||||||
|
result = check(sp_blocking_read(port, &recv_buf1, recv_bufsize1, timeout));
|
||||||
|
|
||||||
|
char numstr[4];
|
||||||
|
for(int j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
numstr[j] = '\0';
|
||||||
|
}
|
||||||
|
for(int j = 0; j < recv_bufsize1; j++)
|
||||||
|
{
|
||||||
|
if(recv_buf1[j] != 0 && recv_buf1[j] != 0x0d && recv_buf1[j] != 0x0a)
|
||||||
|
{
|
||||||
|
numstr[j] = recv_buf1[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int numlights = atoi(numstr);
|
||||||
|
printf("numlights is %i\n", numlights);
|
||||||
|
//printf("%x\n", recv_buf[0]);
|
||||||
|
//printf("%x\n", recv_buf[1]);
|
||||||
|
//printf("%x\n", recv_buf[2]);
|
||||||
|
//printf("%x\n", recv_buf[3]);
|
||||||
|
//printf("%x\n", recv_buf[4]);
|
||||||
|
|
||||||
|
size_t bufsize = (numlights * 3) + 14;
|
||||||
|
char bytes[bufsize];
|
||||||
|
for(int j = 0; j < bufsize; j++)
|
||||||
|
{
|
||||||
|
bytes[j] = 0x00;
|
||||||
|
}
|
||||||
|
bytes[0] = 0xff;
|
||||||
|
bytes[1] = 0xff;
|
||||||
|
bytes[2] = 0xff;
|
||||||
|
bytes[3] = 0xff;
|
||||||
|
bytes[4] = 0xff;
|
||||||
|
bytes[5] = 0xff;
|
||||||
|
bytes[6] = 0x73;
|
||||||
|
bytes[7] = 0x6c;
|
||||||
|
bytes[8] = 0x65;
|
||||||
|
bytes[9] = 0x64;
|
||||||
|
bytes[10] = 0x73;
|
||||||
|
bytes[bufsize-1] = 0xfd;
|
||||||
|
bytes[bufsize-2] = 0xfe;
|
||||||
|
bytes[bufsize-3] = 0xff;
|
||||||
|
|
||||||
|
|
||||||
|
for( int i = 0; i < numlights; i++)
|
||||||
|
{
|
||||||
/* On success, sp_blocking_write() and sp_blocking_read()
|
bytes[(i * 3) + 11 + 1] = 0xff;
|
||||||
* return the number of bytes sent/received before the
|
|
||||||
* timeout expired. We'll store that result here. */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Send data. */
|
/* Send data. */
|
||||||
result = check(sp_blocking_write(port, &sd, size, timeout));
|
result = check(sp_blocking_write(port, &bytes, bufsize, timeout));
|
||||||
|
|
||||||
/* Check whether we sent all of the data. */
|
/* Check whether we sent all of the data. */
|
||||||
if (result == size)
|
if (result == bufsize)
|
||||||
{
|
{
|
||||||
printf("Sent %d bytes successfully, %i lit leds.\n", size, sd.litleds);
|
printf("Sent %d bytes successfully, %i lit leds.\n", bufsize, numlights);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Timed out, %d/%d bytes sent.\n", result, size);
|
printf("Timed out, %d/%d bytes sent.\n", result, bufsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
}
|
}
|
||||||
sd.litleds = 0;
|
for( int i = 0; i < numlights; i++)
|
||||||
result = check(sp_blocking_write(port, &sd, size, timeout));
|
{
|
||||||
|
bytes[(i * 3) + 11 + 1] = 0x00;
|
||||||
|
}
|
||||||
|
result = check(sp_blocking_write(port, &bytes, bufsize, timeout));
|
||||||
|
|
||||||
check(sp_close(port));
|
check(sp_close(port));
|
||||||
sp_free_port(port);
|
sp_free_port(port);
|
||||||
|
|||||||
Reference in New Issue
Block a user