44var microPythonApi = ( function ( ) {
55 'use strict' ;
66
7- var uPyApi = {
7+ var uPyBaseApi = {
88 "microbit" : {
99 "Image" : [ "ALL_CLOCKS" , "ANGRY" , "ARROW_E" , "ARROW_N" , "ARROW_NE" , "ARROW_NW" , "ARROW_S" , "ARROW_SE" , "ARROW_SW" , "ARROW_W" , "ASLEEP" , "BUTTERFLY" , "CHESSBOARD" , "CLOCK1" , "CLOCK10" , "CLOCK11" , "CLOCK12" , "CLOCK2" , "CLOCK3" , "CLOCK4" , "CLOCK5" , "CLOCK6" , "CLOCK7" , "CLOCK8" , "CLOCK9" , "CONFUSED" , "COW" , "DIAMOND" , "DIAMOND_SMALL" , "DUCK" , "FABULOUS" , "GHOST" , "GIRAFFE" , "HAPPY" , "HEART" , "HEART_SMALL" , "HOUSE" , "MEH" , "MUSIC_CROTCHET" , "MUSIC_QUAVER" , "MUSIC_QUAVERS" , "NO" , "PACMAN" , "PITCHFORK" , "RABBIT" , "ROLLERSKATE" , "SAD" , "SILLY" , "SKULL" , "SMILE" , "SNAKE" , "SQUARE" , "SQUARE_SMALL" , "STICKFIGURE" , "SURPRISED" , "SWORD" , "TARGET" , "TORTOISE" , "TRIANGLE" , "TRIANGLE_LEFT" , "TSHIRT" , "UMBRELLA" , "XMAS" , "YES" ] ,
1010 "pin0" : [ "is_touched" , "read_analog" , "read_digital" , "set_analog_period" , "set_analog_period_microseconds" , "write_analog" , "write_digital" ] ,
@@ -64,10 +64,10 @@ var microPythonApi = (function () {
6464 } ;
6565
6666 var extraModules = {
67- "microbitProto " : {
68- "Rhythms " : [ "SIMPLE " , "TRIPLE " , "SWUNG " , "SYNCOPATED " ] ,
69- "Effects " : [ "HIGH_PITCH" , "LOW_PITCH" , "FADE_IN" , "FADE_OUT" , "REVERB" , "ECHO" , "HIGH_PASS" , "LOW_PASS "] ,
70- "AudioProcessor " : [ "apply_effect " ]
67+ "microbit " : {
68+ "microphone " : [ "LOUD " , "QUIET " , "current_sound " , "get_sounds" , "is_sound" , "sound_level" , "was_sound "] ,
69+ "pin_logo " : [ "is_touched "] ,
70+ "pin_speaker " : [ "get_analog_period_microseconds" , "get_mode" , "get_pull" , "read_digital" , "set_analog_period" , "set_analog_period_microseconds" , "set_pull" , "write_analog" , "write_digital "]
7171 }
7272 } ;
7373
@@ -83,15 +83,15 @@ var microPythonApi = (function () {
8383 wordsHorizontal . push ( module ) ;
8484 if ( Array . isArray ( apiObj [ module ] ) ) {
8585 apiObj [ module ] . forEach ( function ( func ) {
86- wordsHorizontal . push ( module + "." + func ) ;
86+ wordsHorizontal . push ( module + '.' + func ) ;
8787 } ) ;
8888 } else {
8989 Object . keys ( apiObj [ module ] ) . forEach ( function ( sub ) {
90- wordsHorizontal . push ( module + "." + sub ) ;
90+ wordsHorizontal . push ( module + '.' + sub ) ;
9191 if ( Array . isArray ( apiObj [ module ] [ sub ] ) ) {
9292 apiObj [ module ] [ sub ] . forEach ( function ( func ) {
93- wordsHorizontal . push ( module + "." + sub + "." + func ) ;
94- wordsHorizontal . push ( sub + "." + func ) ;
93+ wordsHorizontal . push ( module + '.' + sub + '.' + func ) ;
94+ wordsHorizontal . push ( sub + '.' + func ) ;
9595 } ) ;
9696 }
9797 } ) ;
@@ -107,9 +107,35 @@ var microPythonApi = (function () {
107107 * available modules.
108108 */
109109 var getFullMicroPythonApi = function ( ) {
110- return flattenApi ( uPyApi ) . concat ( flattenApi ( extraModules ) ) ;
110+ var finalObj = $ . extend ( true , { } , uPyBaseApi , extraModules ) ;
111+ return flattenApi ( finalObj ) ;
111112 } ;
112113
114+ /**
115+ * Generates the base API in a flat array needed for ACE autocompletion.
116+ *
117+ * @return {string[] } Array with all the autocompletion combinations for
118+ * the base MicroPython API.
119+ */
120+ var getBaseMicroPythonApi = function ( ) {
121+ return flattenApi ( uPyBaseApi ) ;
122+ } ;
123+
124+ /**
125+ * Based on the board ID it generates the appropriate MicroPython API in a
126+ * flat array needed for ACE autocompletion.
127+ *
128+ * @return {string[] } Array with all the autocompletion combinations for
129+ * the MicroPython version relevant to the board ID.
130+ */
131+ var getCompatibleMicroPythonApi = function ( boardId ) {
132+ if ( boardId == '9903' || boardId == '9904' ) {
133+ return getFullMicroPythonApi ( ) ;
134+ } else {
135+ return getBaseMicroPythonApi ( ) ;
136+ }
137+ }
138+
113139 /**
114140 * Detect Python imports in the provided Python code string.
115141 *
@@ -178,7 +204,7 @@ var microPythonApi = (function () {
178204 return imports ;
179205 } ;
180206
181- var compatibleApi = function ( boardId , pyCode ) {
207+ var isApiUsedCompatible = function ( boardId , pyCode ) {
182208 if ( boardId == '9903' || boardId == '9904' ) {
183209 return true ;
184210 } else if ( boardId == '9900' || boardId == '9901' ) {
@@ -198,7 +224,9 @@ var microPythonApi = (function () {
198224
199225 var publicApi = {
200226 'getFullApi' : getFullMicroPythonApi ,
201- 'compatibleApi' : compatibleApi ,
227+ 'getBaseApi' : getBaseMicroPythonApi ,
228+ 'getCompatibleMicroPythonApi' : getCompatibleMicroPythonApi ,
229+ 'isApiUsedCompatible' : isApiUsedCompatible ,
202230 } ;
203231 if ( typeof jasmine !== 'undefined' || typeof jest !== 'undefined' ) {
204232 // Add these private functions when running unit tests
0 commit comments