fdsg

Dependencies:   BLE_API MicroBitEffectsPedal nRF51822

Fork of microbit-dal by Lancaster University

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Wed Jul 13 12:17:51 2016 +0100
Parent:
19:ebc07f856999
Child:
21:cab56b701601
Commit message:
Synchronized with git rev 94e2c661
Author: Joe Finney
microbit: Additional optional autoClear parameter to MicroBitDisplay::animate

The MicroBitDisplay::animate() and MicroBitDisplayAnimateAsync() function both
assumed that the display should be cleared once the requested animation was
complete.

This patch allows the user to control this funcitonality through an
addiitonal, optional boolean parameter to the animate() and animateAsync()
functions.

Changed in this revision

inc/drivers/MicroBitDisplay.h Show annotated file Show diff for this revision Revisions of this file
source/drivers/MicroBitDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/inc/drivers/MicroBitDisplay.h	Wed Jul 13 12:17:50 2016 +0100
+++ b/inc/drivers/MicroBitDisplay.h	Wed Jul 13 12:17:51 2016 +0100
@@ -44,7 +44,7 @@
 //
 // Internal constants
 //
-
+#define MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR      1
 #define MICROBIT_DISPLAY_SPACING                1
 #define MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH    8
 #define MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS    -255
@@ -56,6 +56,7 @@
     ANIMATION_MODE_PRINT_TEXT,
     ANIMATION_MODE_SCROLL_IMAGE,
     ANIMATION_MODE_ANIMATE_IMAGE,
+    ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR,
     ANIMATION_MODE_PRINT_CHARACTER
 };
 
@@ -463,6 +464,8 @@
       * @param startingPosition the starting position on the display for the animation
       *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
       *
+      * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
+      *
       * @return MICROBIT_OK, MICROBIT_BUSY if the screen is in use, or MICROBIT_INVALID_PARAMETER.
       *
       * @code
@@ -474,7 +477,7 @@
       * display.animateAsync(i,100,5);
       * @endcode
       */
-    int animateAsync(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS);
+    int animateAsync(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR);
 
     /**
       * "Animates" the current image across the display with a given stride, finishing on the last frame of the animation.
@@ -488,6 +491,8 @@
       * @param startingPosition the starting position on the display for the animation
       *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
       *
+      * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
+      *
       * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
       *
       * @code
@@ -499,7 +504,7 @@
       * display.animate(i,100,5);
       * @endcode
       */
-    int animate(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS);
+    int animate(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR);
 
     /**
       * Configures the brightness of the display.
@@ -636,4 +641,4 @@
     ~MicroBitDisplay();
 };
 
-#endif
+#endif
\ No newline at end of file
--- a/source/drivers/MicroBitDisplay.cpp	Wed Jul 13 12:17:50 2016 +0100
+++ b/source/drivers/MicroBitDisplay.cpp	Wed Jul 13 12:17:51 2016 +0100
@@ -287,7 +287,7 @@
         if (animationMode == ANIMATION_MODE_SCROLL_IMAGE)
             this->updateScrollImage();
 
-        if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE)
+        if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE || animationMode == ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR)
             this->updateAnimateImage();
 
         if(animationMode == ANIMATION_MODE_PRINT_CHARACTER)
@@ -384,8 +384,11 @@
     //wait until we have rendered the last position to give a continuous animation.
     if (scrollingImagePosition <= -scrollingImage.getWidth() + (MICROBIT_DISPLAY_WIDTH + scrollingImageStride) && scrollingImageRendered)
     {
+        if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR)
+            this->clear();
+
         animationMode = ANIMATION_MODE_NONE;
-        this->clear();
+
         this->sendAnimationCompleteEvent();
         return;
     }
@@ -891,6 +894,8 @@
   * @param startingPosition the starting position on the display for the animation
   *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
   *
+  * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
+  *
   * @return MICROBIT_OK, MICROBIT_BUSY if the screen is in use, or MICROBIT_INVALID_PARAMETER.
   *
   * @code
@@ -902,7 +907,7 @@
   * display.animateAsync(i,100,5);
   * @endcode
   */
-int MicroBitDisplay::animateAsync(MicroBitImage image, int delay, int stride, int startingPosition)
+int MicroBitDisplay::animateAsync(MicroBitImage image, int delay, int stride, int startingPosition, int autoClear)
 {
     //sanitise the delay value
     if(delay <= 0)
@@ -922,7 +927,7 @@
 
         animationDelay = stride == 0 ? 0 : delay;
         animationTick = delay-1;
-        animationMode = ANIMATION_MODE_ANIMATE_IMAGE;
+        animationMode = autoClear ? ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR : ANIMATION_MODE_ANIMATE_IMAGE;
     }
     else
     {
@@ -944,6 +949,8 @@
   * @param startingPosition the starting position on the display for the animation
   *                         to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
   *
+  * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
+  *
   * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
   *
   * @code
@@ -955,7 +962,7 @@
   * display.animate(i,100,5);
   * @endcode
   */
-int MicroBitDisplay::animate(MicroBitImage image, int delay, int stride, int startingPosition)
+int MicroBitDisplay::animate(MicroBitImage image, int delay, int stride, int startingPosition, int autoClear)
 {
     //sanitise the delay value
     if(delay <= 0)
@@ -969,7 +976,7 @@
     if (animationMode == ANIMATION_MODE_NONE)
     {
         // Start the effect.
-        this->animateAsync(image, delay, stride, startingPosition);
+        this->animateAsync(image, delay, stride, startingPosition, autoClear);
 
         // Wait for completion.
         //TODO: Put this in when we merge tight-validation
@@ -1215,4 +1222,4 @@
 MicroBitDisplay::~MicroBitDisplay()
 {
     system_timer_remove_component(this);
-}
+}
\ No newline at end of file