Update borg.h
This commit is contained in:
		
							parent
							
								
									206c4d58ac
								
							
						
					
					
						commit
						0d2b1b7a79
					
				@ -5,13 +5,14 @@
 | 
				
			|||||||
#include <FastLED.h>
 | 
					#include <FastLED.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct LEDSelect {
 | 
					struct LEDSelect {
 | 
				
			||||||
	byte side;
 | 
					  byte side;
 | 
				
			||||||
	byte column;
 | 
					  byte column;
 | 
				
			||||||
	byte row;
 | 
					  byte row;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Decodes side, column, row into n LED
 | 
					// Decodes side, column, row into n LED
 | 
				
			||||||
int decodeLED(LEDSelect selection);
 | 
					int decodeLED(LEDSelect selection);
 | 
				
			||||||
 | 
					void encodeLED(int n, LEDSelect* Result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
** Set Color
 | 
					** Set Color
 | 
				
			||||||
@ -19,103 +20,121 @@ int decodeLED(LEDSelect selection);
 | 
				
			|||||||
** The last two propertries can be 255, meaning no information
 | 
					** The last two propertries can be 255, meaning no information
 | 
				
			||||||
** the property that is 255 will be inclusively filled with the CRGB color
 | 
					** the property that is 255 will be inclusively filled with the CRGB color
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
bool setColor(LEDSelect selection, CRGB* leds);
 | 
					bool setColor(LEDSelect selection, CRGB color, CRGB* leds);
 | 
				
			||||||
// Sets every color that isn't black
 | 
					// Sets every color that isn't black
 | 
				
			||||||
bool updateColors(LEDSelect selection, CRGB* leds);
 | 
					bool updateColors(LEDSelect selection, CRGB* leds);
 | 
				
			||||||
// Mirrors one side to every other side
 | 
					// Mirrors one side to every other side
 | 
				
			||||||
bool mirror(byte side, CRGB* leds);
 | 
					bool mirror(byte side, CRGB* leds);
 | 
				
			||||||
 | 
					//Prints large X in a given color
 | 
				
			||||||
 | 
					void printError(CRGB color, CRGB* leds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int decodeLED(LEDSelect selection) {
 | 
					int decodeLED(LEDSelect selection) {
 | 
				
			||||||
	return 9 * selection.side + 3 * selection.row + selection.column;
 | 
					  return 9 * selection.side + 3 * selection.row + selection.column;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void encodeLED(int n, LEDSelect* Result) {
 | 
				
			||||||
 | 
					  Result->side = n / 9;
 | 
				
			||||||
 | 
					  Result->column = n % 9 / 3;
 | 
				
			||||||
 | 
					  Result->row = n % 9 % 3;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool setColor(LEDSelect selection, CRGB color, CRGB* leds) {
 | 
					bool setColor(LEDSelect selection, CRGB color, CRGB* leds) {
 | 
				
			||||||
	if (selection.side == 255) {
 | 
					  if (selection.side == 255) {
 | 
				
			||||||
		return false;
 | 
					    return false;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	if (selection.column == 255 && selection.row == 255) {
 | 
					  if (selection.column == 255 && selection.row == 255) {
 | 
				
			||||||
		for (byte n = 0; n < 9; n++) {
 | 
					    for (byte n = 0; n < 9; n++) {
 | 
				
			||||||
			leds[selection.side * 9 + n] = color;
 | 
					      leds[selection.side * 9 + n] = color;
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else if (selection.column == 255 && selection.row != 255) {
 | 
					  else if (selection.column == 255 && selection.row != 255) {
 | 
				
			||||||
		for (byte n = 0; n < 3; n++) {
 | 
					    for (byte n = 0; n < 3; n++) {
 | 
				
			||||||
			leds[decodeLED({ selection.side, n, selection.row })] = color;
 | 
					      leds[decodeLED({ selection.side, n, selection.row })] = color;
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else if (selection.column != 255 && selection.row == 255) {
 | 
					  else if (selection.column != 255 && selection.row == 255) {
 | 
				
			||||||
		for (byte n = 0; n < 3; n++) {
 | 
					    for (byte n = 0; n < 3; n++) {
 | 
				
			||||||
			leds[decodeLED({ selection.side, selection.column, n })] = color;
 | 
					      leds[decodeLED({ selection.side, selection.column, n })] = color;
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else if (selection.column != 255 && selection.row != 255) {
 | 
					  else if (selection.column != 255 && selection.row != 255) {
 | 
				
			||||||
		leds[decodeLED(selection)] = color;
 | 
					    leds[decodeLED(selection)] = color;
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else {
 | 
					  else {
 | 
				
			||||||
		return false;
 | 
					    return false;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool updateColors(LEDSelect selection, CRGB color, CRGB* leds) {
 | 
					bool updateColors(LEDSelect selection, CRGB color, CRGB* leds) {
 | 
				
			||||||
	if (selection.side == 255) {
 | 
					  if (selection.side == 255) {
 | 
				
			||||||
		return false;
 | 
					    return false;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
	if (selection.column == 255 && selection.row == 255) {
 | 
					  if (selection.column == 255 && selection.row == 255) {
 | 
				
			||||||
		for (int n = 0; n < 9; n++) {
 | 
					    for (int n = 0; n < 9; n++) {
 | 
				
			||||||
			CRGB* led = &leds[selection.side * 9 + n];
 | 
					      CRGB* led = &leds[selection.side * 9 + n];
 | 
				
			||||||
			if (*led != (CRGB) 0x000000) {
 | 
					      if (*led != (CRGB) 0x000000) {
 | 
				
			||||||
				*led = color;
 | 
					        *led = color;
 | 
				
			||||||
			}
 | 
					      }
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else if (selection.column == 255 && selection.row != 255) {
 | 
					  else if (selection.column == 255 && selection.row != 255) {
 | 
				
			||||||
		for (int n = 0; n < 3; n++) {
 | 
					    for (int n = 0; n < 3; n++) {
 | 
				
			||||||
			CRGB* led = &leds[decodeLED({ selection.side, n, selection.row })];
 | 
					      CRGB* led = &leds[decodeLED({ selection.side, n, selection.row })];
 | 
				
			||||||
			if (*led != (CRGB)0x000000) {
 | 
					      if (*led != (CRGB)0x000000) {
 | 
				
			||||||
				*led = color;
 | 
					        *led = color;
 | 
				
			||||||
			}
 | 
					      }
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else if (selection.column != 255 && selection.row == 255) {
 | 
					  else if (selection.column != 255 && selection.row == 255) {
 | 
				
			||||||
		for (int n = 0; n < 3; n++) {
 | 
					    for (int n = 0; n < 3; n++) {
 | 
				
			||||||
			CRGB* led = &leds[decodeLED({ selection.side, selection.column, n })];
 | 
					      CRGB* led = &leds[decodeLED({ selection.side, selection.column, n })];
 | 
				
			||||||
			if (*led != (CRGB) 0x000000) {
 | 
					      if (*led != (CRGB) 0x000000) {
 | 
				
			||||||
				*led = color;
 | 
					        *led = color;
 | 
				
			||||||
			}
 | 
					      }
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else if (selection.column != 255 && selection.row != 255) {
 | 
					  else if (selection.column != 255 && selection.row != 255) {
 | 
				
			||||||
		CRGB* led = &leds[decodeLED(selection)];
 | 
					    CRGB* led = &leds[decodeLED(selection)];
 | 
				
			||||||
		if (*led != (CRGB) 0x000000) {
 | 
					    if (*led != (CRGB) 0x000000) {
 | 
				
			||||||
			*led = color;
 | 
					      *led = color;
 | 
				
			||||||
		}
 | 
					    }
 | 
				
			||||||
		return true;
 | 
					    return true;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
	else {
 | 
					  else {
 | 
				
			||||||
		return false;
 | 
					    return false;
 | 
				
			||||||
	}
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool mirror(byte side, CRGB* leds) {
 | 
					bool mirror(byte side, CRGB* leds) {
 | 
				
			||||||
	/*TODO: figure out memory structure, 
 | 
					  /*TODO: figure out memory structure, 
 | 
				
			||||||
		copy the nine leds to the the different memory parts,
 | 
					    copy the nine leds to the the different memory parts, so it the text is displayed on all sides.
 | 
				
			||||||
		should probably use some form of modulo
 | 
					    should probably use some form of modulo
 | 
				
			||||||
	*/
 | 
					  */
 | 
				
			||||||
 | 
					  for(int i = 0; i < sizeof(leds) / sizeof(CRGB); i+=9) {
 | 
				
			||||||
 | 
					    memcpy(&leds[i], &leds[decodeLED({side, 0, 0})], sizeof(CRGB) * 9);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void printError(CRGB color, CRGB* leds) {
 | 
				
			||||||
 | 
					  setColor({0, 255, 255}, (CRGB) color, leds);
 | 
				
			||||||
 | 
					  setColor({0, 0, 1}, (CRGB) 0, leds);
 | 
				
			||||||
 | 
					  setColor({0, 1, 0}, (CRGB) 0, leds);
 | 
				
			||||||
 | 
					  setColor({0, 1, 2}, (CRGB) 0, leds);
 | 
				
			||||||
 | 
					  setColor({0, 2, 1}, (CRGB) 0, leds);
 | 
				
			||||||
 | 
					  mirror(0, leds);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user