Skip to content

Commit

Permalink
added some early prototype code for haptic vibration, see #104
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Apr 18, 2022
1 parent 6ac6487 commit 62974db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions js/quadrilateral/view/SideNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import QuadrilateralShapeModel from '../model/QuadrilateralShapeModel.js';
import QuadrilateralModel from '../model/QuadrilateralModel.js';
import { Line, Shape } from '../../../../kite/js/imports.js';
import QuadrilateralColors from '../../common/QuadrilateralColors.js';
import vibrationManager from '../../../../tappi/js/vibrationManager.js';

// The dilation around side shapes when drawing the focus highlight.
const FOCUS_HIGHLIGHT_DILATION = 15;
Expand Down Expand Up @@ -253,6 +254,19 @@ class SideNode extends Voicing( Path, 1 ) {
side.isPressedProperty.value = false;
}
} );

// vibration
// TODO: This code for vibration is a prototype, and only vibrates for a finite time. It will need to be improved
// and finalized before publication. See https://github.com/phetsims/quake/issues/13.
side.isPressedProperty.lazyLink( isPressed => {

if ( isPressed ) {
navigator.vibrate( [ 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 ] );
}
else {
navigator.vibrate( 0 );
}
} );
}

/**
Expand Down
5 changes: 3 additions & 2 deletions js/quadrilateral/view/VertexNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Vector2 from '../../../../dot/js/Vector2.js';
import QuadrilateralModel from '../model/QuadrilateralModel.js';
import QuadrilateralColors from '../../common/QuadrilateralColors.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import vibrationManager from '../../../../tappi/js/vibrationManager.js';

// constants
const LABEL_TEXT_FONT = new PhetFont( { size: 16, weight: 'bold' } );
Expand Down Expand Up @@ -137,10 +138,10 @@ class VertexNode extends Voicing( Circle, 1 ) {
// vibration
vertex.isPressedProperty.lazyLink( isPressed => {
if ( isPressed ) {
navigator.vibrate( [ 10000 ] );
vibrationManager.startVibrate( [ 100, 100 ] );
}
else {
navigator.vibrate( 0 );
vibrationManager.stopVibrate();
}
} );

Expand Down

0 comments on commit 62974db

Please sign in to comment.