mirror of
https://github.com/skogaby/OpeNITHM.git
synced 2026-10-09 15:19:52 +03:00
* Add a new class, AutoTouchboard, which is responsible for calibrating itself on a per-key basis using a user single-touch as the basis for calibration * Overhaul the main sketch to redo how input is handled (eliminate the keyboard callback concept). Don't double-read the air sensors * Process every incoming frame of light updates and fix sign error that kept the controller one update behind in addition to dropping updates
97 lines
2.0 KiB
C++
97 lines
2.0 KiB
C++
#include "SerialLeds.h"
|
|
|
|
SerialLeds::SerialLeds()
|
|
{ }
|
|
|
|
bool SerialLeds::process(byte in)
|
|
{
|
|
bool readyToProcess = false;
|
|
switch (currentState)
|
|
{
|
|
case headerSearch:
|
|
// Search for header
|
|
if (in == 0xAA)
|
|
{
|
|
dataBuffer[0] = in;
|
|
currentState = headerConfirm;
|
|
}
|
|
break;
|
|
case headerConfirm:
|
|
// Confirm header
|
|
if (in == 0xAA)
|
|
{
|
|
dataBuffer[1] = in;
|
|
currentState = dataRead;
|
|
currentReadNum = 2;
|
|
}
|
|
else
|
|
{
|
|
currentState = headerSearch;
|
|
}
|
|
break;
|
|
case dataRead:
|
|
{
|
|
dataBuffer[currentReadNum] = in;
|
|
currentReadNum++;
|
|
if (currentReadNum == 100)
|
|
{
|
|
if (memcmp(dataBuffer, lastBuffer, 100) != 0)
|
|
readyToProcess = true;
|
|
memcpy(lastBuffer, dataBuffer, 100);
|
|
currentState = headerSearch;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
return readyToProcess;
|
|
}
|
|
|
|
bool SerialLeds::processBulk(uint8_t *buf, size_t length)
|
|
{
|
|
bool readyToProcess = false;
|
|
currentState = headerSearch;
|
|
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
switch (currentState)
|
|
{
|
|
case headerSearch:
|
|
if (buf[i] == 0xAA)
|
|
{
|
|
currentState = headerConfirm;
|
|
dataBuffer[0] = buf[i];
|
|
}
|
|
break;
|
|
case headerConfirm:
|
|
if (buf[i] == 0xAA)
|
|
{
|
|
currentState = dataRead;
|
|
dataBuffer[1] = buf[i];
|
|
}
|
|
else
|
|
{
|
|
currentState = headerSearch;
|
|
}
|
|
break;
|
|
case dataRead:
|
|
memcpy(dataBuffer + 2, buf + i, 98);
|
|
if (memcmp(dataBuffer, lastBuffer, 100) != 0)
|
|
{
|
|
memcpy(ledData.raw, dataBuffer + 2, 96);
|
|
readyToProcess = true;
|
|
}
|
|
memcpy(lastBuffer, dataBuffer, 100);
|
|
currentState = headerSearch;
|
|
return readyToProcess;
|
|
}
|
|
}
|
|
return readyToProcess;
|
|
}
|
|
|
|
// Left to Right
|
|
RGBLed SerialLeds::getKey(uint8_t key)
|
|
{
|
|
return ledData.rgb[30 - (key * 2)];
|
|
}
|