@@ -287,6 +287,31 @@ const MbitMoreGestureID =
287287 11 : 'SHAKE'
288288} ;
289289
290+ /**
291+ * Enum for name of tilt direction.
292+ * @readonly
293+ * @enum {string}
294+ */
295+ const MbitMoreTiltDirectionName =
296+ {
297+ FRONT : 'FRONT' ,
298+ BACK : 'BACK' ,
299+ LEFT : 'LEFT' ,
300+ RIGHT : 'RIGHT' ,
301+ ANY : 'ANY'
302+ } ;
303+
304+ /**
305+ * Tilt direction to gesture name mapping
306+ * @readonly
307+ */
308+ const MbitMoreTiltDirectionToGestureName = {
309+ FRONT : MbitMoreGestureName . TILT_UP ,
310+ BACK : MbitMoreGestureName . TILT_DOWN ,
311+ LEFT : MbitMoreGestureName . TILT_LEFT ,
312+ RIGHT : MbitMoreGestureName . TILT_RIGHT
313+ } ;
314+
290315/**
291316 * Enum for event type in the micro:bit runtime.
292317 * @readonly
@@ -1729,43 +1754,43 @@ class MbitMoreBlocks {
17291754 return [
17301755 {
17311756 text : formatMessage ( {
1732- id : 'mbitMore.tiltDirectionMenu.up ' ,
1757+ id : 'mbitMore.tiltDirectionMenu.front ' ,
17331758 default : 'front' ,
17341759 description : 'label for front element in tilt direction picker for Microbit More extension'
17351760 } ) ,
1736- value : MbitMoreGestureName . TILT_UP
1761+ value : MbitMoreTiltDirectionName . FRONT
17371762 } ,
17381763 {
17391764 text : formatMessage ( {
1740- id : 'mbitMore.tiltDirectionMenu.down ' ,
1765+ id : 'mbitMore.tiltDirectionMenu.back ' ,
17411766 default : 'back' ,
17421767 description : 'label for back element in tilt direction picker for Microbit More extension'
17431768 } ) ,
1744- value : MbitMoreGestureName . TILT_DOWN
1769+ value : MbitMoreTiltDirectionName . BACK
17451770 } ,
17461771 {
17471772 text : formatMessage ( {
17481773 id : 'mbitMore.tiltDirectionMenu.left' ,
17491774 default : 'left' ,
17501775 description : 'label for left element in tilt direction picker for Microbit More extension'
17511776 } ) ,
1752- value : MbitMoreGestureName . TILT_LEFT
1777+ value : MbitMoreTiltDirectionName . LEFT
17531778 } ,
17541779 {
17551780 text : formatMessage ( {
17561781 id : 'mbitMore.tiltDirectionMenu.right' ,
17571782 default : 'right' ,
17581783 description : 'label for right element in tilt direction picker for Microbit More extension'
17591784 } ) ,
1760- value : MbitMoreGestureName . TILT_RIGHT
1785+ value : MbitMoreTiltDirectionName . RIGHT
17611786 } ,
17621787 {
17631788 text : formatMessage ( {
17641789 id : 'mbitMore.tiltDirectionMenu.any' ,
17651790 default : 'any' ,
17661791 description : 'label for any direction element in tilt direction picker for Microbit More extension'
17671792 } ) ,
1768- value : ' ANY'
1793+ value : MbitMoreTiltDirectionName . ANY
17691794 }
17701795 ] ;
17711796 }
@@ -1781,31 +1806,31 @@ class MbitMoreBlocks {
17811806 default : 'front' ,
17821807 description : 'label for front element in tilt angle direction picker for Microbit More extension'
17831808 } ) ,
1784- value : ' FRONT'
1809+ value : MbitMoreTiltDirectionName . FRONT
17851810 } ,
17861811 {
17871812 text : formatMessage ( {
17881813 id : 'mbitMore.tiltAngleDirectionMenu.back' ,
17891814 default : 'back' ,
17901815 description : 'label for back element in tilt angle direction picker for Microbit More extension'
17911816 } ) ,
1792- value : ' BACK'
1817+ value : MbitMoreTiltDirectionName . BACK
17931818 } ,
17941819 {
17951820 text : formatMessage ( {
17961821 id : 'mbitMore.tiltAngleDirectionMenu.left' ,
17971822 default : 'left' ,
17981823 description : 'label for left element in tilt angle direction picker for Microbit More extension'
17991824 } ) ,
1800- value : ' LEFT'
1825+ value : MbitMoreTiltDirectionName . LEFT
18011826 } ,
18021827 {
18031828 text : formatMessage ( {
18041829 id : 'mbitMore.tiltAngleDirectionMenu.right' ,
18051830 default : 'right' ,
18061831 description : 'label for right element in tilt angle direction picker for Microbit More extension'
18071832 } ) ,
1808- value : ' RIGHT'
1833+ value : MbitMoreTiltDirectionName . RIGHT
18091834 }
18101835 ] ;
18111836 }
@@ -2441,7 +2466,7 @@ class MbitMoreBlocks {
24412466 DIRECTION : {
24422467 type : ArgumentType . STRING ,
24432468 menu : 'tiltDirectionMenu' ,
2444- defaultValue : ' ANY'
2469+ defaultValue : MbitMoreTiltDirectionName . ANY
24452470 }
24462471 }
24472472 } ,
@@ -2457,7 +2482,7 @@ class MbitMoreBlocks {
24572482 DIRECTION : {
24582483 type : ArgumentType . STRING ,
24592484 menu : 'tiltDirectionMenu' ,
2460- defaultValue : ' ANY'
2485+ defaultValue : MbitMoreTiltDirectionName . ANY
24612486 }
24622487 }
24632488 } ,
@@ -2473,7 +2498,7 @@ class MbitMoreBlocks {
24732498 DIRECTION : {
24742499 type : ArgumentType . STRING ,
24752500 menu : 'tiltAngleDirectionMenu' ,
2476- defaultValue : ' FRONT'
2501+ defaultValue : MbitMoreTiltDirectionName . FRONT
24772502 }
24782503 }
24792504 } ,
@@ -3247,7 +3272,7 @@ class MbitMoreBlocks {
32473272 } , this . runtime . currentStepTime ) ;
32483273 }
32493274 const direction = args . DIRECTION ;
3250- if ( direction === ' ANY' ) {
3275+ if ( direction === MbitMoreTiltDirectionName . ANY ) {
32513276 const tiltGestures = [
32523277 MbitMoreGestureName . TILT_UP ,
32533278 MbitMoreGestureName . TILT_DOWN ,
@@ -3261,10 +3286,11 @@ class MbitMoreBlocks {
32613286 return lastTimestamp !== this . prevGestureEvents [ name ] ;
32623287 } ) ;
32633288 }
3264- const lastTimestamp = this . _peripheral . getGestureEventTimestamp ( direction ) ;
3289+ const gestureName = MbitMoreTiltDirectionToGestureName [ direction ] ;
3290+ const lastTimestamp = this . _peripheral . getGestureEventTimestamp ( gestureName ) ;
32653291 if ( lastTimestamp === null ) return false ;
3266- if ( ! this . prevGestureEvents [ direction ] ) return true ;
3267- return lastTimestamp !== this . prevGestureEvents [ direction ] ;
3292+ if ( ! this . prevGestureEvents [ gestureName ] ) return true ;
3293+ return lastTimestamp !== this . prevGestureEvents [ gestureName ] ;
32683294 }
32693295
32703296 /**
@@ -3277,13 +3303,13 @@ class MbitMoreBlocks {
32773303 switch ( args . DIRECTION ) {
32783304 case 'ANY' :
32793305 return Math . abs ( this . _peripheral . pitch ) > 15 || Math . abs ( this . _peripheral . roll ) > 15 ;
3280- case MbitMoreGestureName . TILT_UP :
3306+ case MbitMoreTiltDirectionName . FRONT :
32813307 return this . _peripheral . pitch < - 15 ;
3282- case MbitMoreGestureName . TILT_DOWN :
3308+ case MbitMoreTiltDirectionName . BACK :
32833309 return this . _peripheral . pitch > 15 ;
3284- case MbitMoreGestureName . TILT_LEFT :
3310+ case MbitMoreTiltDirectionName . LEFT :
32853311 return this . _peripheral . roll < - 15 ;
3286- case MbitMoreGestureName . TILT_RIGHT :
3312+ case MbitMoreTiltDirectionName . RIGHT :
32873313 return this . _peripheral . roll > 15 ;
32883314 default :
32893315 return false ;
@@ -3298,13 +3324,13 @@ class MbitMoreBlocks {
32983324 */
32993325 getTiltAngle ( args ) {
33003326 switch ( args . DIRECTION ) {
3301- case ' FRONT' :
3327+ case MbitMoreTiltDirectionName . FRONT :
33023328 return - this . _peripheral . pitch ;
3303- case ' BACK' :
3329+ case MbitMoreTiltDirectionName . BACK :
33043330 return this . _peripheral . pitch ;
3305- case ' LEFT' :
3331+ case MbitMoreTiltDirectionName . LEFT :
33063332 return - this . _peripheral . roll ;
3307- case ' RIGHT' :
3333+ case MbitMoreTiltDirectionName . RIGHT :
33083334 return this . _peripheral . roll ;
33093335 default :
33103336 return 0 ;
0 commit comments