Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

shiftbrite app: Fixed the processing of the bytes so that it does ope…

…rations in the correct order. Made some variables "static const" to save a little CPU time.
  • Loading branch information...
commit e30d18e6730d202cbf86fe7555c9a42565728963 1 parent dbfa809
@DavidEGrayson DavidEGrayson authored
Showing with 45 additions and 36 deletions.
  1. +45 −36 apps/shiftbrite/shiftbrite.c
View
81 apps/shiftbrite/shiftbrite.c
@@ -105,53 +105,62 @@ int32 restrictRange(int32 value, int32 min, int32 max)
return value;
}
-void shiftbriteService()
+void shiftbriteProcessByte(char c)
{
static char rgb[12]; // big enough to hold 4 hex digits times three colors
static uint8 i = 0;
- uint8 input_bits = restrictRange(param_input_bits,1,16); // allow up to 16 bits = 4 hex digits
- uint8 hex_chars_per_color = ((input_bits-1) >> 2) + 1; // 1-4 bits = 1; 5-8 bits = 2; etc.
- int8 shift = 10 - input_bits; // amount to shift to create the output
-
- while(radioComRxAvailable())
+ static const uint8 input_bits = restrictRange(param_input_bits,1,16); // allow up to 16 bits = 4 hex digits
+ static const uint8 hex_chars_per_color = ((input_bits-1) >> 2) + 1; // 1-4 bits = 1; 5-8 bits = 2; etc.
+ static const int8 shift = 10 - input_bits; // amount to shift to create the output
+
+ if(c == '\r' || c == '\n')
{
- char c = radioComRxReceiveByte();
- if(radioComTxAvailable() && param_echo_on)
- {
- radioComTxSendByte(c);
- }
- if(c == '\r' || c == '\n')
- {
- i = 0;
- LED_YELLOW(1);
- toggleLatch();
- break;
- }
- rgb[i] = c;
- i++;
+ i = 0;
+ LED_YELLOW(1);
+ toggleLatch();
}
-
- if(i == hex_chars_per_color*3)
+ else
{
- i = 0;
+
+ rgb[i] = c;
+ i++;
- if(shift > 0)
+ if(i == hex_chars_per_color*3)
{
- sendRGB(
- hex(rgb, hex_chars_per_color) << shift,
- hex(rgb+hex_chars_per_color, hex_chars_per_color) << shift,
- hex(rgb+hex_chars_per_color*2,hex_chars_per_color) << shift
- );
+
+ i = 0;
+
+ if(shift > 0)
+ {
+ sendRGB(
+ hex(rgb, hex_chars_per_color) << shift,
+ hex(rgb+hex_chars_per_color, hex_chars_per_color) << shift,
+ hex(rgb+hex_chars_per_color*2,hex_chars_per_color) << shift
+ );
+ }
+ else
+ {
+ sendRGB(
+ hex(rgb, hex_chars_per_color) >> -shift,
+ hex(rgb+hex_chars_per_color, hex_chars_per_color) >> -shift,
+ hex(rgb+hex_chars_per_color*2,hex_chars_per_color) >> -shift
+ );
+ }
}
- else
+ }
+}
+
+void shiftbriteService()
+{
+ while(radioComRxAvailable())
+ {
+ char c = radioComRxReceiveByte();
+ if(radioComTxAvailable() && param_echo_on)
{
- sendRGB(
- hex(rgb, hex_chars_per_color) >> -shift,
- hex(rgb+hex_chars_per_color, hex_chars_per_color) >> -shift,
- hex(rgb+hex_chars_per_color*2,hex_chars_per_color) >> -shift
- );
+ radioComTxSendByte(c);
}
- }
+ shiftbriteProcessByte(c);
+ }
}
void shiftbriteInit()
Please sign in to comment.
Something went wrong with that request. Please try again.