Serial8 (#11)
* Using 8 bits per int for serial devices * Refactor simwind code slightly to improve performance
This commit is contained in:
parent
2446fc9af2
commit
545168c3ab
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t litleds;
|
||||
uint8_t litleds;
|
||||
//unsigned char color_1_red;
|
||||
//unsigned char color_1_green;
|
||||
//unsigned char color_1_blue;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t motor1;
|
||||
uint32_t effect1;
|
||||
uint32_t motor2;
|
||||
uint32_t effect2;
|
||||
uint32_t motor3;
|
||||
uint32_t effect3;
|
||||
uint32_t motor4;
|
||||
uint32_t effect4;
|
||||
uint8_t motor1;
|
||||
uint8_t effect1;
|
||||
uint8_t motor2;
|
||||
uint8_t effect2;
|
||||
uint8_t motor3;
|
||||
uint8_t effect3;
|
||||
uint8_t motor4;
|
||||
uint8_t effect4;
|
||||
}
|
||||
SimHapticData;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t velocity;
|
||||
float fanpower;
|
||||
uint8_t velocity;
|
||||
uint8_t fanpower;
|
||||
}
|
||||
SimWindData;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ SimWindData sd;
|
|||
int velocity = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.begin(9600);
|
||||
if (!AFMS.begin()) {
|
||||
Serial.println("Could not find Motor Shield. Check wiring.");
|
||||
while (1);
|
||||
|
|
@ -37,11 +37,7 @@ void loop() {
|
|||
memcpy(&sd, &buff, BYTE_SIZE);
|
||||
velocity = sd.velocity;
|
||||
}
|
||||
int v = ceil(velocity * KPHTOMPH);
|
||||
if (v >= 255)
|
||||
{
|
||||
v = 255;
|
||||
}
|
||||
myMotor1->setSpeed(v*FANPOWER);
|
||||
myMotor2->setSpeed(v*FANPOWER);
|
||||
|
||||
myMotor1->setSpeed(velocity*FANPOWER);
|
||||
myMotor2->setSpeed(velocity*FANPOWER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
#define KPHTOMPH .621317
|
||||
|
||||
int serialdev_update(SimDevice* this, SimData* simdata)
|
||||
{
|
||||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
|
|
@ -63,10 +65,12 @@ int arduino_simwind_update(SimDevice* this, SimData* simdata)
|
|||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
int result = 1;
|
||||
|
||||
serialdevice->u.simwinddata.velocity = simdata->velocity;
|
||||
// sending over as mph, when you consider 255mph to be a reasonable upper limit
|
||||
serialdevice->u.simwinddata.velocity = ceil(simdata->velocity*KPHTOMPH);
|
||||
|
||||
slogt("Updating arduino device speed to %i", serialdevice->u.simwinddata.velocity);
|
||||
// this can be added to the config, all config dependent can be added to init
|
||||
serialdevice->u.simwinddata.fanpower = 0.6;
|
||||
serialdevice->u.simwinddata.fanpower = (int)0.6 * 255;
|
||||
size_t size = sizeof(SimWindData);
|
||||
|
||||
arduino_update(serialdevice, &serialdevice->u.simwinddata, size);
|
||||
|
|
|
|||
Loading…
Reference in New Issue