added function to play two frame-equal animations simulatniously on one eye each; some minor code cleanups

This commit is contained in:
Stefan H. 2018-12-29 20:13:02 +01:00
parent 6484f6dc71
commit 42a7dd2805
2 changed files with 70 additions and 38 deletions

View file

@ -61,23 +61,70 @@ void playFile(char* file, int framespeed) {
}
}
f.close();
}
/*Serial.println(frameNumber);
for(int frame=0; frame<frameNumber; frame++) {
//Serial.print("Sending Frame: "); Serial.println(frame);
for(int i=0; i<strip.PixelCount()/2; i++) {
strip.SetPixelColor( i , *anim[frame][i]);
strip.SetPixelColor( 64+i , *anim[frame][i]);
void playLRFile(char* lfile, char* rfile, int framespeed) {
int leftFrameNumber = getFileFrames(lfile);
int rightFrameNumber = getFileFrames(rfile);
int n = -1;
RgbColor *lanim[64];
RgbColor *ranim[64];;
File lf = SPIFFS.open(lfile, "r");
File rf = SPIFFS.open(rfile, "r");
String lline, rline;
char rgbChar[8];
String rgbStr;
uint32_t rgb;
if(leftFrameNumber != rightFrameNumber) { Serial.println("Frame mismatch for playLRFile"); return; }
// load file into array
if (!lf | !rf) {
Serial.println("Cannot open any of the left-/rightfile!");
return;
} else {
// forward to first hex number
while(lf.available() && n<0) {
lline = lf.readStringUntil('\n');
n = lline.lastIndexOf("0x");
}
n=-1;
while(rf.available() && n<0) {
rline = rf.readStringUntil('\n');
n = rline.lastIndexOf("0x");
}
for(int frame=0; frame<leftFrameNumber; frame++) {
for(int j=0; j<8; j++) {
for(int i=0; i<8; i++) {
rgbStr=lline.substring(4+i*12,4+i*12+6);
rgb = strtol(rgbStr.c_str(), NULL, 16);
lanim[i*8+j] = new RgbColor(rgb & 0xFF, rgb>>8 & 0xFF, rgb>>16);
strip.SetPixelColor( i*8+j , *lanim[i*8+j]);
rgbStr=rline.substring(4+i*12,4+i*12+6);
rgb = strtol(rgbStr.c_str(), NULL, 16);
ranim[i*8+j] = new RgbColor(rgb & 0xFF, rgb>>8 & 0xFF, rgb>>16);
strip.SetPixelColor( 64+i*8+j , *ranim[i*8+j]);
}
lline = lf.readStringUntil('\n');
rline = rf.readStringUntil('\n');
}
strip.Show();
delay(framespeed);
}*/
/*for(int frame=0; frame<frameNumber; frame++) {
for(int j=0; j<8; j++) {
for(int i=0; i<8; i++) {
delete anim[frame][i*8+j];
if(frame<leftFrameNumber-1) {
lline = lf.readStringUntil('\n'); lline = lf.readStringUntil('\n');
rline = rf.readStringUntil('\n'); rline = rf.readStringUntil('\n');
}
for(int i=0; i<64; i++) {
delete lanim[i];
delete ranim[i];
}
}
}*/
}
lf.close();
rf.close();
}

View file

@ -113,7 +113,7 @@ void loop() {
playFile("/Move_right.c", 100);
playFile("/Blink_right.c", 100);
playFile("/Move_right_center.c", 100);
playFile("/Blink_center_getAngry.c", 100);
playLRFile("/Blink_center_getAngry.c", "/Blink_center_getAngry.c", 100);
/*Serial.println("Animation test ...");
@ -126,23 +126,8 @@ void loop() {
playBwAnimation(50, eye_blink_c); delay(3000);
playBwAnimation(50, eye_move_cl); delay(3000);
playBwAnimation(50, eye_blink_l); delay(2000);
playBwAnimation(50, eye_move_lc); delay(3000);*/
/*playMapAnimation(150, terminator);delay(3000);*/
/* for(int n=0; n<strip.PixelCount(); n++) {
strip.SetPixelColor(n, 20 );
strip.Show(); delay(100);
}*/
/* Serial.println("Colormap test ...");
strip.ClearTo(black);
for(int n=0; n<strip.PixelCount()/2; n++) {
strip.SetPixelColor( 2*n , *c[(test2[n]>>4 )] );
strip.SetPixelColor( 2*n+1, *c[(test2[n]&0x0F)] );
strip.Show(); delay(1000);
}
delay(10000);*/
playBwAnimation(50, eye_move_lc); delay(3000);
playMapAnimation(150, terminator);delay(3000);*/
Serial.println("Loop end ...");
}