Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: movie.cpp
- Revision:
- 2:3935d2ed40cd
- Child:
- 3:9376bf1f1bbd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/movie.cpp Wed Aug 20 05:24:38 2014 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "movie.h"
+#include "sbDriver.h"
+
+movie::movie(unsigned short int * movie_p, shiftBriteDisplay &display, unsigned int movieSize):r_display(display){
+ //Constructor - sets up initial condition
+ //r_display = display; //setup a reference to the actual display
+ this->movie_p = movie_p; // pointer to the data. This data is simply and array of short integers but sequenced as frames
+ //i.e. if the display has 2 leds and the data is {12,13,14,15,16,17,18,19,20,21,22} then the first frame is 12,13,14+15,16,17
+ //corresponding to rgb_led1 and rgb_led2
+ currentFrame = 0;
+ frameSize = r_display.getModuleCount();
+ this->movieSize = movieSize; // in BYTES. Need to (((movieSize/sizeof(unsigned short int))/frameSize)/3) to get actual frames
+}
+
+void movie::play(){
+ /**Advance therough the movie one frame whenever this member method is called
+ Display is referenced with r_display
+ */
+
+ unsigned int dot = 0;
+// unsigned int dotCol = 0;
+ unsigned short int rTemp, gTemp, bTemp;
+ //moduleCount is how many LEDS, assume 4, called frameSize
+ //currentFrame is how many frames we've loaded
+ //currentDot is which module in the frame, i.e. 0-3 in this example
+ //starts at 0
+ //So, first value is at *(movie_p + (currentFrame*moduleCount*currentDot))
+ // i.e. *(movie_p + 0*4*0) which is *(movie_p + 0), i.e. the very first byte
+ // so, colours are are *(movie_p + 0 + 0,1,2)
+ // Increment current Dot
+ // *(movie_p + (0*4*1) + 0,1,2) = 4+0, 4+1, 4+2)
+ // Iterate through all Dots
+ //then, increment the currentFrame and store for next time
+ //remember to check that we do not exceed the bounds of the data
+ //serial_p->printf("movie pointer l=%p r=%u v=%u",&movie_p,movie_p,*movie_p);
+ for(dot = 0; dot != frameSize; dot++){
+ // movie_p+=(unsigned short int*)((currentFrame*frameSize*dot)+0);
+ /* rTemp = *(movie_p + ((currentFrame*frameSize*dot)+0));
+ gTemp = *(movie_p + ((currentFrame*frameSize*dot)+1));
+ bTemp = *(movie_p + ((currentFrame*frameSize*dot)+2)); */
+ rTemp = *(movie_p + ((currentFrame*frameSize*3)+(dot*3)+0));
+ gTemp = *(movie_p + ((currentFrame*frameSize*3)+(dot*3)+1));
+ bTemp = *(movie_p + ((currentFrame*frameSize*3)+(dot*3)+2));
+ //serial_p->printf("Frame: %d Module: %d r:%d g:%d b:%d\r\n",currentFrame,dot,rTemp,gTemp,bTemp);
+ r_display.setLed(dot,rTemp,gTemp,bTemp);
+ }
+
+ r_display.displayFrame();//update the display - MAKE IT HAPPEN
+
+ currentFrame++;
+ //Check bounds
+ if((currentFrame)>=((movieSize/sizeof(unsigned short int))/frameSize)/3){
+ if(f_repeat == 1) currentFrame = 0;//start from first frame
+ else currentFrame--; //force to repeat last frame
+ }
+ }
\ No newline at end of file