Initialise arrays on the stack in esp32 servo

This commit is contained in:
Piv
2022-07-31 17:50:03 +09:30
parent 985213311d
commit 26647017c3

View File

@@ -33,27 +33,25 @@ void setupServos(uint8_t size, uint8_t *calibrationValues)
void modifyServo(uint8_t channel, uint8_t newAngle)
{
if(servos.count(channel) > 0){
if (servos.count(channel) > 0)
{
servos[channel]->write(newAngle);
}
}
}
void loop()
{
uint8_t *header = new uint8_t[2];
uint8_t header[2];
Serial.readBytes(header, 2);
if (header[0] == 0)
{
uint8_t *calibration = new uint8_t[2 * header[1]];
uint8_t calibration[2 * header[1]];
Serial.readBytes(calibration, header[1]);
setupServos(header[1], calibration);
delete [] calibration;
}
else
{
modifyServo(header[0], header[1]);
}
delete [] header;
}