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);
|
uint32_t SerialCmd_parseColor(unsigned int startOffset);
|
||||||
|
|
||||||
|
int SerialCmd_parseNumber(unsigned int startOffset);
|
||||||
|
|
||||||
char SerialCmd_type(void);
|
char SerialCmd_type(void);
|
||||||
void SerialCmd_help(void);
|
void SerialCmd_help(void);
|
||||||
|
|
||||||
|
@ -21,6 +21,19 @@
|
|||||||
|
|
||||||
static char myCmd[CMD_MAX];
|
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
|
* @brief
|
||||||
* number of read bytes
|
* number of read bytes
|
||||||
@ -108,26 +121,26 @@ char SerialCmd_type(void)
|
|||||||
* @brief Color
|
* @brief Color
|
||||||
* Extract color of the following six bytes
|
* Extract color of the following six bytes
|
||||||
* @param startOffset
|
* @param startOffset
|
||||||
* @return uint32_t
|
* @return uint32_t Color as red, green and blue, @see Color
|
||||||
*/
|
*/
|
||||||
uint32_t SerialCmd_parseColor(unsigned int startOffset)
|
uint32_t SerialCmd_parseColor(unsigned int startOffset)
|
||||||
{
|
{
|
||||||
unsigned int colorParts[3]; /* 0: red, 1: green, 2: blue */
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i < (2*3); i+= 2)
|
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)
|
if (colorParts[i/2] < 0)
|
||||||
{
|
{
|
||||||
Serial.print("calcErr:");
|
Serial.print("calcErr:");
|
||||||
Serial.println(colorParts[i/2]);
|
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 r = colorParts[0]; /* fill red */
|
||||||
int g = colorParts[1]; /* fill green */
|
int g = colorParts[1]; /* fill green */
|
||||||
@ -136,6 +149,38 @@ uint32_t SerialCmd_parseColor(unsigned int startOffset)
|
|||||||
return Color(r, g, b);
|
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)
|
void SerialCmd_help(void)
|
||||||
{
|
{
|
||||||
Serial.println(SERIALCMD_COMMAND_HELP);
|
Serial.println(SERIALCMD_COMMAND_HELP);
|
||||||
|
13
src/main.cpp
13
src/main.cpp
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
/******************* Settings for command mode ***************/
|
/******************* Settings for command mode ***************/
|
||||||
#define COMMAND_BRIGHTNESS 200
|
#define COMMAND_BRIGHTNESS 200
|
||||||
|
#define PERCENT_MAX 100
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* LOCAL VARIABLES
|
* LOCAL VARIABLES
|
||||||
@ -215,11 +216,23 @@ void loop()
|
|||||||
case SERIALCMD_COMMAND_AUTOMATIC[0]:
|
case SERIALCMD_COMMAND_AUTOMATIC[0]:
|
||||||
mAutomaticTargetRPM = RPM_CONTROL_DEACTIVATED;
|
mAutomaticTargetRPM = RPM_CONTROL_DEACTIVATED;
|
||||||
break;
|
break;
|
||||||
|
case SERIALCMD_COMMAND_FAN[0]:
|
||||||
|
mAutomaticTargetRPM = SerialCmd_parseNumber(SERIALCMD_PARAMETER_OFFSET);
|
||||||
|
if (mAutomaticTargetRPM > PERCENT_MAX)
|
||||||
|
{
|
||||||
|
mAutomaticTargetRPM = PERCENT_MAX;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pixels->show();
|
pixels->show();
|
||||||
|
|
||||||
|
if ((mAutomaticTargetRPM > fanSpeedPercent))
|
||||||
|
{
|
||||||
|
fanSpeedPercent = mAutomaticTargetRPM;
|
||||||
|
}
|
||||||
|
|
||||||
Serial.print(fanSpeedPercent);
|
Serial.print(fanSpeedPercent);
|
||||||
Serial.print("%;");
|
Serial.print("%;");
|
||||||
setFanSpeedPercent(fanSpeedPercent);
|
setFanSpeedPercent(fanSpeedPercent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user