@@ -13,6 +13,9 @@ import experiments from '@cdo/apps/util/experiments';
13
13
// Polyfill node process.hrtime for the browser, which gets used by johnny-five
14
14
process . hrtime = require ( 'browser-process-hrtime' ) ;
15
15
16
+ const xPins = [ "A0" , "A1" , "A2" , "A3" , "A4" , "A5" , "A6" , "A7" ] ;
17
+ const classicPins = [ 12 , 6 , 9 , 10 , 3 , 2 , 0 , 1 ] ;
18
+
16
19
describe ( 'CircuitPlaygroundBoard' , ( ) => {
17
20
let board , playground ;
18
21
@@ -275,6 +278,15 @@ describe('CircuitPlaygroundBoard', () => {
275
278
expect ( playground . pinMode ) . to . have . been . calledWith ( pin , arg2 ) ;
276
279
} ) ;
277
280
} ) ;
281
+
282
+ it ( 'forwards the call to firmata with the modified CPX value' , ( ) => {
283
+ return board . connect ( ) . then ( ( ) => {
284
+ const pin = xPins [ 0 ] ;
285
+ const arg2 = 1023 ;
286
+ board . pinMode ( pin , arg2 ) ;
287
+ expect ( playground . pinMode ) . to . have . been . calledWith ( classicPins [ 0 ] , arg2 ) ;
288
+ } ) ;
289
+ } ) ;
278
290
} ) ;
279
291
280
292
describe ( `digitalWrite(pin, value)` , ( ) => {
@@ -286,6 +298,15 @@ describe('CircuitPlaygroundBoard', () => {
286
298
expect ( playground . digitalWrite ) . to . have . been . calledWith ( pin , arg2 ) ;
287
299
} ) ;
288
300
} ) ;
301
+
302
+ it ( 'forwards the call to firmata with the modified CPX value' , ( ) => {
303
+ return board . connect ( ) . then ( ( ) => {
304
+ const pin = xPins [ 1 ] ;
305
+ const arg2 = 1023 ;
306
+ board . digitalWrite ( pin , arg2 ) ;
307
+ expect ( playground . digitalWrite ) . to . have . been . calledWith ( classicPins [ 1 ] , arg2 ) ;
308
+ } ) ;
309
+ } ) ;
289
310
} ) ;
290
311
291
312
describe ( `digitalRead(pin, callback)` , ( ) => {
@@ -297,6 +318,15 @@ describe('CircuitPlaygroundBoard', () => {
297
318
expect ( playground . digitalRead ) . to . have . been . calledWith ( pin , arg2 ) ;
298
319
} ) ;
299
320
} ) ;
321
+
322
+ it ( 'forwards the call to firmata with the modified CPX value' , ( ) => {
323
+ return board . connect ( ) . then ( ( ) => {
324
+ const pin = xPins [ 2 ] ;
325
+ const arg2 = ( ) => { } ;
326
+ board . digitalRead ( pin , arg2 ) ;
327
+ expect ( playground . digitalRead ) . to . have . been . calledWith ( classicPins [ 2 ] , arg2 ) ;
328
+ } ) ;
329
+ } ) ;
300
330
} ) ;
301
331
302
332
describe ( `analogWrite(pin, value)` , ( ) => {
@@ -308,6 +338,15 @@ describe('CircuitPlaygroundBoard', () => {
308
338
expect ( playground . analogWrite ) . to . have . been . calledWith ( pin , arg2 ) ;
309
339
} ) ;
310
340
} ) ;
341
+
342
+ it ( 'forwards the call to firmata with the modified CPX value' , ( ) => {
343
+ return board . connect ( ) . then ( ( ) => {
344
+ const pin = xPins [ 3 ] ;
345
+ const arg2 = 1023 ;
346
+ board . analogWrite ( pin , arg2 ) ;
347
+ expect ( playground . analogWrite ) . to . have . been . calledWith ( classicPins [ 3 ] , arg2 ) ;
348
+ } ) ;
349
+ } ) ;
311
350
} ) ;
312
351
313
352
describe ( `analogRead(pin, callback)` , ( ) => {
@@ -319,6 +358,15 @@ describe('CircuitPlaygroundBoard', () => {
319
358
expect ( playground . analogRead ) . to . have . been . calledWith ( pin , arg2 ) ;
320
359
} ) ;
321
360
} ) ;
361
+
362
+ it ( 'forwards the call to firmata with the modified CPX value' , ( ) => {
363
+ return board . connect ( ) . then ( ( ) => {
364
+ const pin = xPins [ 4 ] ;
365
+ const arg2 = ( ) => { } ;
366
+ board . analogRead ( pin , arg2 ) ;
367
+ expect ( playground . analogRead ) . to . have . been . calledWith ( classicPins [ 4 ] , arg2 ) ;
368
+ } ) ;
369
+ } ) ;
322
370
} ) ;
323
371
324
372
describe ( `boardConnected()` , ( ) => {
@@ -349,6 +397,14 @@ describe('CircuitPlaygroundBoard', () => {
349
397
expect ( newLed ) . to . be . an . instanceOf ( Led ) ;
350
398
} ) ;
351
399
} ) ;
400
+
401
+ it ( 'uses the express pin value to make an LED controller with the classic pin value' , ( ) => {
402
+ return board . connect ( ) . then ( ( ) => {
403
+ const pin = xPins [ 5 ] ;
404
+ const newLed = board . createLed ( pin ) ;
405
+ expect ( newLed . pin ) . to . equal ( classicPins [ 5 ] ) ;
406
+ } ) ;
407
+ } ) ;
352
408
} ) ;
353
409
354
410
describe ( `createButton(pin)` , ( ) => {
@@ -360,6 +416,14 @@ describe('CircuitPlaygroundBoard', () => {
360
416
} ) ;
361
417
} ) ;
362
418
419
+ it ( 'uses the express pin value to make a button controller with the classic pin value' , ( ) => {
420
+ return board . connect ( ) . then ( ( ) => {
421
+ const pin = xPins [ 6 ] ;
422
+ const newLed = board . createButton ( pin ) ;
423
+ expect ( newLed . pin ) . to . equal ( classicPins [ 6 ] ) ;
424
+ } ) ;
425
+ } ) ;
426
+
363
427
it ( 'configures the controller as a pullup if passed an external pin' , ( ) => {
364
428
return board . connect ( ) . then ( ( ) => {
365
429
EXTERNAL_PINS . forEach ( ( pin ) => {
@@ -380,4 +444,12 @@ describe('CircuitPlaygroundBoard', () => {
380
444
} ) ;
381
445
} ) ;
382
446
} ) ;
447
+
448
+ describe ( `mappedPin(pin)` , ( ) => {
449
+ it ( `returns the Classic pin value of the provided Express pin value` , ( ) => {
450
+ for ( let i = 0 ; i < xPins . length ; i ++ ) {
451
+ expect ( board . mappedPin ( xPins [ i ] ) ) . to . equal ( classicPins [ i ] ) ;
452
+ }
453
+ } ) ;
454
+ } ) ;
383
455
} ) ;
0 commit comments