All commands are working
This commit is contained in:
parent
8a8e6f547b
commit
900c938a97
@ -29,6 +29,8 @@ int SerialCmd_checkCmdArrayForPrefix (void);
|
||||
|
||||
uint32_t SerialCmd_parseColor(unsigned int startOffset);
|
||||
|
||||
int SerialCmd_parseNumber(unsigned int startOffset);
|
||||
|
||||
char SerialCmd_type(void);
|
||||
void SerialCmd_help(void);
|
||||
|
||||
|
@ -21,6 +21,19 @@
|
||||
|
||||
static char myCmd[CMD_MAX];
|
||||
|
||||
/******************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
static unsigned int readLowNipple(int i, unsigned int startOffset);
|
||||
|
||||
static unsigned int readHighNipple(int i, unsigned int startOffset);
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* EXTERNAL FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* number of read bytes
|
||||
@ -108,26 +121,26 @@ char SerialCmd_type(void)
|
||||
* @brief Color
|
||||
* Extract color of the following six bytes
|
||||
* @param startOffset
|
||||
* @return uint32_t
|
||||
* @return uint32_t Color as red, green and blue, @see Color
|
||||
*/
|
||||
uint32_t SerialCmd_parseColor(unsigned int startOffset)
|
||||
{
|
||||
unsigned int colorParts[3]; /* 0: red, 1: green, 2: blue */
|
||||
|
||||
if (startOffset > (CMD_MAX - sizeof(colorParts)))
|
||||
if (startOffset > (CMD_MAX - (sizeof(colorParts) * 2)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i=0; i < (2*3); i+= 2)
|
||||
{
|
||||
colorParts[i/2] = (myCmd[i+startOffset] <= '9') ? ((myCmd[i+startOffset]-'0') << 4) : (((myCmd[i+startOffset]-'A')+10) << 4);
|
||||
colorParts[i / 2] = readHighNipple(i, startOffset);
|
||||
if (colorParts[i/2] < 0)
|
||||
{
|
||||
Serial.print("calcErr:");
|
||||
Serial.println(colorParts[i/2]);
|
||||
}
|
||||
colorParts[i/2] += ( (myCmd[i+startOffset+1] <= '9') ? (myCmd[i+startOffset+1]-'0') : (((myCmd[i+startOffset+1]-'A')+10)) );
|
||||
colorParts[i / 2] += readLowNipple(i, startOffset);
|
||||
}
|
||||
int r = colorParts[0]; /* fill red */
|
||||
int g = colorParts[1]; /* fill green */
|
||||
@ -136,6 +149,38 @@ uint32_t SerialCmd_parseColor(unsigned int startOffset)
|
||||
return Color(r, g, b);
|
||||
}
|
||||
|
||||
static unsigned int readLowNipple(int i, unsigned int startOffset)
|
||||
{
|
||||
return ((myCmd[i + startOffset + 1] <= '9') ? (myCmd[i + startOffset + 1] - '0') : (((myCmd[i + startOffset + 1] - 'A') + 10)));
|
||||
}
|
||||
|
||||
static unsigned int readHighNipple(int i, unsigned int startOffset)
|
||||
{
|
||||
return (myCmd[i + startOffset] <= '9') ? ((myCmd[i + startOffset] - '0') << 4) : (((myCmd[i + startOffset] - 'A') + 10) << 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Parse the following two bytes as hex values
|
||||
* @param startOffset
|
||||
* @return int number (0-255) or negative values on failure
|
||||
*/
|
||||
int SerialCmd_parseNumber(unsigned int startOffset)
|
||||
{
|
||||
|
||||
if (startOffset > (CMD_MAX - 2))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int value=0;
|
||||
value = readHighNipple(0, startOffset);
|
||||
value += readLowNipple(0, startOffset);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
void SerialCmd_help(void)
|
||||
{
|
||||
Serial.println(SERIALCMD_COMMAND_HELP);
|
||||
|
13
src/main.cpp
13
src/main.cpp
@ -39,6 +39,7 @@
|
||||
|
||||
/******************* Settings for command mode ***************/
|
||||
#define COMMAND_BRIGHTNESS 200
|
||||
#define PERCENT_MAX 100
|
||||
|
||||
/******************************************************************************
|
||||
* LOCAL VARIABLES
|
||||
@ -215,11 +216,23 @@ void loop()
|
||||
case SERIALCMD_COMMAND_AUTOMATIC[0]:
|
||||
mAutomaticTargetRPM = RPM_CONTROL_DEACTIVATED;
|
||||
break;
|
||||
case SERIALCMD_COMMAND_FAN[0]:
|
||||
mAutomaticTargetRPM = SerialCmd_parseNumber(SERIALCMD_PARAMETER_OFFSET);
|
||||
if (mAutomaticTargetRPM > PERCENT_MAX)
|
||||
{
|
||||
mAutomaticTargetRPM = PERCENT_MAX;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
pixels->show();
|
||||
|
||||
if ((mAutomaticTargetRPM > fanSpeedPercent))
|
||||
{
|
||||
fanSpeedPercent = mAutomaticTargetRPM;
|
||||
}
|
||||
|
||||
Serial.print(fanSpeedPercent);
|
||||
Serial.print("%;");
|
||||
setFanSpeedPercent(fanSpeedPercent);
|
||||
|
Loading…
x
Reference in New Issue
Block a user