Files
skogaby_OpeNITHM/Firmware/OpeNITHM/SerialProcessor.cpp
T

77 lines
1.7 KiB
C++

#include "SerialProcessor.h"
SerialProcessor::SerialProcessor()
{ }
void SerialProcessor::processConfigCommand(uint8_t* buf)
{
// figure out which command we're running
switch (buf[2])
{
// print the controller info
case CMD_PRINT_INFO:
byte bytes[100];
// whether the air sensor is analog or not
#ifdef IR_SENSOR_ANALOG
bytes[0] = 0x11;
#else
bytes[0] = 0x00;
#endif
// slider on color
bytes[1] = led_on.r;
bytes[2] = led_on.g;
bytes[3] = led_on.b;
// slider off color
bytes[4] = led_off.r;
bytes[5] = led_off.g;
bytes[6] = led_off.b;
// slider sensitivity
bytes[7] = touchboard->getSensitivity();
// air sensitivity
bytes[8] = sensor->getAnalogSensitivity();
Serial.write(bytes, 100);
break;
case CMD_CHANGE_ON_COLOR:
led_on.r = buf[3];
led_on.g = buf[4];
led_on.b = buf[5];
serialLeds->saveLights();
break;
case CMD_CHANGE_OFF_COLOR:
led_off.r = buf[3];
led_off.g = buf[4];
led_off.b = buf[5];
serialLeds->saveLights();
break;
case CMD_CALIBRATE_SLIDER:
touchboard->setSensitivity(buf[3]);
touchboard->calibrateKeys(true);
break;
case CMD_CALIBRATE_AIR_SENSORS:
sensor->setAnalogSensitivity(buf[3]);
sensor->recalibrate();
break;
default:
break;
}
}
void SerialProcessor::processBulk(uint8_t *buf)
{
if (buf[0] == LED_FLAG && buf[1] == LED_FLAG)
{
serialLeds->processBulk(buf);
useSerialLeds = true;
serialLightsCounter = 0;
}
else if (buf[0] == CONFIG_FLAG && buf[1] == CONFIG_FLAG)
{
processConfigCommand(buf);
}
}