Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRF52LEDMatrix::rotateTo #227

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

martinwork
Copy link
Collaborator

Implements NRF52LEDMatrix::rotateTo. Demo hex: HelloRotate.zip

#include "MicroBit.h"

MicroBit uBit;


void setRotationForGesture( uint16_t gesture)
{
  switch ( gesture)
  {
    case MICROBIT_ACCELEROMETER_EVT_TILT_UP:
      uBit.display.rotateTo(MICROBIT_DISPLAY_ROTATION_0);
      break;
    case MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT:
      uBit.display.rotateTo(MICROBIT_DISPLAY_ROTATION_90);
      break;
    case MICROBIT_ACCELEROMETER_EVT_TILT_DOWN:
      uBit.display.rotateTo(MICROBIT_DISPLAY_ROTATION_180);
      break;
    case MICROBIT_ACCELEROMETER_EVT_TILT_LEFT:
      uBit.display.rotateTo(MICROBIT_DISPLAY_ROTATION_270);
      break;
  }
}


void onGesture( MicroBitEvent e)
{
  switch ( e.value)
  {
    case MICROBIT_ACCELEROMETER_EVT_TILT_UP:
    case MICROBIT_ACCELEROMETER_EVT_TILT_DOWN:
    case MICROBIT_ACCELEROMETER_EVT_TILT_LEFT:
    case MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT:
      setRotationForGesture( e.value);
      break;
  }
}


void forever()
{
    while (true)
    {
      uBit.display.scroll("HELLO WORLD");
    }
}


int main()
{
    uBit.init();

    uBit.messageBus.listen( MICROBIT_ID_GESTURE, 0, onGesture);

    setRotationForGesture( uBit.accelerometer.getGesture());

    create_fiber( forever);

    release_fiber();
    return 0;
}

@finneyj
Copy link
Contributor

finneyj commented Sep 5, 2022

ooh, thanks @martinwork. I always liked this on v1!

Looks good to me.

@martinwork
Copy link
Collaborator Author

@finneyj Phew! It would be good to get this merged soon, as @bsiever has an extension to expose it in MakeCode.

@finneyj
Copy link
Contributor

finneyj commented Sep 5, 2022

cool. Yeah, I'm happy for this to be merged.

@bsiever
Copy link

bsiever commented Sep 5, 2022

Thanks @finneyj! My first approach suffered from a CODAL memory leak due to reallocation of MicroBitDisplay (leak due to new here). My workaround was an abuse of new and delete to be able to cleanup the lost memory.

Reallocating the MicroBitDisplay was a hack that didn't behave as smoothly as the rotateTo() does. Very happy to have a better option! (Thanks @martinwork!)

@finneyj
Copy link
Contributor

finneyj commented Sep 5, 2022

Can you schedule this merge this in for the next release please @JohnVidler?

@JohnVidler JohnVidler added this to the v0.2.42 milestone Sep 12, 2022
@JohnVidler JohnVidler added enhancement New feature or request p3 example-app labels Sep 12, 2022
@JohnVidler
Copy link
Collaborator

Looks good to me, happy to merge :) Thanks @martinwork and @bsiever

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants