Fix Warnings, code cleanups

This commit is contained in:
2018-04-18 00:34:14 +02:00
parent 2b23b391b4
commit 00d7ae6d73
3 changed files with 57 additions and 60 deletions

View File

@@ -256,9 +256,6 @@ struct FrameBuffer {
} FrameBuffer;
#endif
extern char position2pin[MAX_X][MAX_Y];
extern char layer[MAX_Z];
void FrameBufferSwitch(void) {
#if FRAMEBUFFER_POINTERS
Frame * t = FrameBuffer.back;
@@ -285,20 +282,24 @@ static Frame *FrameBufferGetBack(void) {
#endif
}
void FrameBufferReadFront(char x, char y, char z, unsigned char *val) {
void FrameBufferReadFront(unsigned char x, unsigned char y, unsigned char z,
unsigned char *val) {
*val = FrameBufferGetFront()->data[x][y][z];
}
void FrameBufferReadBack(char x, char y, char z, unsigned char *val) {
void FrameBufferReadBack(unsigned char x, unsigned char y, unsigned char z,
unsigned char *val) {
*val = FrameBufferGetBack()->data[x][y][z];
}
void FrameBufferCopy(char x1, char y1, char z1, char x2, char y2, char z2) {
void FrameBufferCopy(unsigned char x1, unsigned char y1, unsigned char z1,
unsigned char x2, unsigned char y2, unsigned char z2) {
FrameBufferGetBack()->data[x1][y1][z1] =
FrameBufferGetFront()->data[x2][y2][z2];
}
void FrameBufferWrite(char x, char y, char z, unsigned char val) {
void FrameBufferWrite(unsigned char x, unsigned char y, unsigned char z,
unsigned char val) {
FrameBufferGetBack()->data[x][y][z] = val;
}
@@ -306,14 +307,14 @@ void FrameBufferSet(unsigned char val) {
memset(FrameBufferGetBack(), val, FRAME_SIZE());
}
void FrameBufferBlank() {
void FrameBufferBlank(void) {
FrameBufferSet(0);
}
static void letter(char l, char brightness) {
static void letter(unsigned char l, unsigned char brightness) {
memset(FrameBufferGetBack(), 0, FRAME_SIZE());
for (char x = 0; x < MAX_X; x++) {
for (char y = 0; y < MAX_Y; y++) {
for (unsigned char x = 0; x < MAX_X; x++) {
for (unsigned char y = 0; y < MAX_Y; y++) {
FrameBufferGetBack()->data[3][y][3-x] =
font[l - 'a'][x][y] * brightness;
}
@@ -322,16 +323,16 @@ static void letter(char l, char brightness) {
delay(200);
}
void printAllSymbols() {
for(char c = 0; c < sizeof(font)/sizeof(font[0]); c++) {
void printAllSymbols(void) {
for(unsigned char c = 0; c < sizeof(font)/sizeof(font[0]); c++) {
letter(c+'a', 127);
delay(500);
}
}
void FrameBufferWriteStr(char * str, const short delayPerLetter,
void FrameBufferWriteStr(char const * str, const short delayPerLetter,
const unsigned char brightness) {
unsigned char *c = str;
char const *c = str;
while(*c != 0) {
if (*c == ' ') {
memset(FrameBufferGetBack(), 0, FRAME_SIZE());
@@ -351,7 +352,13 @@ void FrameBufferWriteStr(char * str, const short delayPerLetter,
}
}
void FrameBufferRefresh(void) {
static void FrameBufferRefresh(void) {
#if DEBUG_FB_REFRESH
static long int timeStartRefresh = micros();
static long int timeLastRefresh = 0;
#endif
Frame *f = FrameBufferGetFront();
#if BRIGHTNESS_INCREMENT
FrameBuffer.intensity =
@@ -360,15 +367,10 @@ void FrameBufferRefresh(void) {
FrameBuffer.intensity = 128;
#endif
#if DEBUG_FB_REFRESH
static int timeStartRefresh = micros();
static int timeLastRefresh = 0;
#endif
for (char z = 0; z < MAX_Z; z++) {
for (unsigned char z = 0; z < MAX_Z; z++) {
// 1. Set up the layer leds to be turned on / off
for (char x = 0; x < MAX_X; x++) {
for (char y = 0; y < MAX_Y; y++) {
for (unsigned char x = 0; x < MAX_X; x++) {
for (unsigned char y = 0; y < MAX_Y; y++) {
if (f->data[x][y][z] > FrameBuffer.intensity) {
digitalWrite(position2pin[x][y], HIGH);
} else {
@@ -404,15 +406,15 @@ void FrameBufferRefresh(void) {
void FrameBufferInit(void) {
// Setting rows to ouput
for (char x = 0; x < MAX_X; x++) {
for (char y = 0; y < MAX_Y; y++) {
for (unsigned char x = 0; x < MAX_X; x++) {
for (unsigned char y = 0; y < MAX_Y; y++) {
pinMode(position2pin[x][y], OUTPUT);
digitalWrite(position2pin[x][y], LOW);
}
}
// Setting layers to output
for (char z = 0; z < MAX_Z; z++) {
for (unsigned char z = 0; z < MAX_Z; z++) {
pinMode(layer[z], OUTPUT);
digitalWrite(layer[z], HIGH);
}

View File

@@ -32,9 +32,8 @@
*/
/* Either 1 (Enabled) or 0 (disabled) */
#define DEBUG 0
#if DEBUG
#define DEBUG_FB_REFRESH 1
#define DEBUG_FB_REFRESH 0
#endif
/* All the code assumes dimensions are below 127, as signed chars are used to
@@ -71,19 +70,22 @@ void FrameBufferSwitch(void);
* Read the brightness ``val'' of the led at position (x,y,z), in the front
* buffer.
*/
void FrameBufferReadFront(char x, char y, char z, unsigned char *val);
void FrameBufferReadFront(unsigned char x, unsigned char y, unsigned char z,
unsigned char *val);
/**
* Read the brightness ``val'' of the led at position (x,y,z), in the back
* buffer.
*/
void FrameBufferReadBack(char x, char y, char z, unsigned char *val);
void FrameBufferReadBack(unsigned char x, unsigned char y, unsigned char z,
unsigned char *val);
/**
* Copy the value from (x2, y2, z2) in the front buffer, to (x1,y1,z1) in
* the back buffer.
*/
void FrameBufferCopy(char x1, char y1, char z1, char x2, char y2, char z2);
void FrameBufferCopy(unsigned char x1, unsigned char y1, unsigned char z1,
unsigned char x2, unsigned char y2, unsigned char z2);
/**
* Write the brightness ``val'' to the led at position (x,y,z), in the back
@@ -92,7 +94,8 @@ void FrameBufferCopy(char x1, char y1, char z1, char x2, char y2, char z2);
* In order to make the value visible, a call to FrameBufferSwitch is needed,
* once the drawing of the frame is complete.
*/
void FrameBufferWrite(char x, char y, char z, unsigned char val);
void FrameBufferWrite(unsigned char x, unsigned char y, unsigned char z,
unsigned char val);
/**
* Write the brightness ``val'' to the whole back buffer.
@@ -108,7 +111,7 @@ void FrameBufferSet(unsigned char val);
* In order to make the value visible, a call to FrameBufferSwitch is needed,
* once the drawing of the frame is complete.
*/
void FrameBufferBlank();
void FrameBufferBlank(void);
/**
* Print the string, a letter at a time, showing each for delayPerLetter time,
@@ -117,7 +120,7 @@ void FrameBufferBlank();
* This has minimal checks, only lowercase font, space and zero to terminate
* the string.
*/
void FrameBufferWriteStr(char * str, const short delayPerLetter,
void FrameBufferWriteStr(char const * str, const short delayPerLetter,
const unsigned char brightness);
/**
@@ -125,11 +128,6 @@ void FrameBufferWriteStr(char * str, const short delayPerLetter,
*/
void printAllSymbols(void);
/**
* Draw the front frame on the ``screen''.
*/
void FrameBufferRefresh(void);
/**
* Initialize the framebuffer, and start the timer to refresh the ``screen''.
*/

View File

@@ -47,14 +47,14 @@
/* Either 1 (Enabled) or 0 (disabled) */
#define DEBUG 0
#include "FrameBuffer.h"
#if DEBUG
#define DEBUG_SETUP 1
#define DEBUG_LOOP 1
#endif
#include "FrameBuffer.h"
/******************************* ANIMATIONS ********************************/
/* Taken from PWMallPins.pde by Paul Badger, 2007;
@@ -165,17 +165,17 @@ void sine2(int period /* [ms] */) {
void sine3(int period /* [ms] */) {
for(int i = 0; i < 256; i++) {
FrameBufferBlank();;
for (char x = 1; x < 3; x++) {
for (char y = 1; y < 3; y++) {
for (char z = 1; z < 3; z++) {
for (unsigned char x = 1; x < 3; x++) {
for (unsigned char y = 1; y < 3; y++) {
for (unsigned char z = 1; z < 3; z++) {
FrameBufferWrite(x, y, z, sinewave[i]);
}
}
}
for (char x = 0; x < MAX_X; x++) {
for (char y = 0; y < MAX_Y; y++) {
for (char z = 0; z < MAX_Z; z++) {
for (unsigned char x = 0; x < MAX_X; x++) {
for (unsigned char y = 0; y < MAX_Y; y++) {
for (unsigned char z = 0; z < MAX_Z; z++) {
if ( ((x == 0) || (x == 3))
||((y == 0) || (y == 3))
||((z == 0) || (z == 3))) {
@@ -193,12 +193,11 @@ void sine3(int period /* [ms] */) {
/**
* Random rain drpos fall to the bottom of the cube
*/
void randomRain() {
unsigned char val;
for (char a = MAX_Z; a > 0; a--) {
void randomRain(void) {
for (unsigned char a = MAX_Z; a > 0; a--) {
// animation of 4 steps, requiring computing 4 full frames
for (char x = 0; x < MAX_X; x++) {
for (char y = 0; y < MAX_Y; y++) {
for (unsigned char x = 0; x < MAX_X; x++) {
for (unsigned char y = 0; y < MAX_Y; y++) {
FrameBufferWrite(x, y, 3,
(random(0, 4) == 0) ? 1 : random(0, BRIGHTNESS_MAX));
FrameBufferCopy(x, y, 2, x, y, 3);
@@ -214,7 +213,7 @@ void randomRain() {
/********************************** BODY ***********************************/
void setup()
void setup(void)
{
#if DEBUG_SETUP
static long timeStartSetup = micros();
@@ -223,20 +222,19 @@ void setup()
// Seeding random for random pattern
randomSeed(analogRead(10));
FrameBufferInit();
#if DEBUG
Serial.begin(9600);
Serial.println("\nSetup DONE");
#endif
FrameBufferInit();
#if DEBUG_SETUP
Serial.print("Setup Time: ");
Serial.println((micros() - timeStartSetup), DEC);
#endif
}
void loop() {
void loop(void) {
static char a = -1;
#if DEBUG_LOOP
@@ -261,7 +259,6 @@ void loop() {
}
}
#if DEBUG_LOOP
Serial.print("Loop Time: ");
Serial.println((micros() - timeStartLoop), DEC);