widgets: gyroscope widget 1st draft
This commit is contained in:
parent
711ee53a0f
commit
e9e8d572ee
5 changed files with 213 additions and 1 deletions
|
|
@ -52,6 +52,7 @@ module.exports.widgets = {
|
|||
input: require('./inputs/input'),
|
||||
keys: require('./inputs/keys'),
|
||||
script: require('./inputs/script'),
|
||||
gyroscope: require('./inputs/gyroscope'),
|
||||
|
||||
// maths
|
||||
// deprecated / hidden
|
||||
|
|
@ -67,5 +68,5 @@ module.exports.categories = {
|
|||
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg'],
|
||||
'Containers':['panel','strip','modal', 'clone'],
|
||||
'Switchers':['switcher','crossfader'],
|
||||
'Inputs':['input', 'keys', 'script']
|
||||
'Inputs':['input', 'keys', 'script', 'gyroscope']
|
||||
}
|
||||
|
|
|
|||
116
src/browser/js/app/widgets/inputs/gyroscope.js
Normal file
116
src/browser/js/app/widgets/inputs/gyroscope.js
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
var Widget = require('../common/widget'),
|
||||
GyroNorm = require('gyronorm/dist/gyronorm.complete.js'),
|
||||
{iconify} = require('../../ui/utils'),
|
||||
{clip} = require('../utils')
|
||||
|
||||
class Gyroscope extends Widget {
|
||||
|
||||
static defaults() {
|
||||
|
||||
return {
|
||||
type:'gyroscope',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
_geometry:'geometry',
|
||||
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
|
||||
_style:'style',
|
||||
|
||||
label:'auto',
|
||||
color:'auto',
|
||||
css:'',
|
||||
|
||||
_gyroscope: 'gyroscope',
|
||||
|
||||
frequency: 30,
|
||||
normalize: true,
|
||||
compass: false,
|
||||
screenAdjusted: false
|
||||
precision: 2,
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
||||
var html = `
|
||||
<div class="gyroscope">
|
||||
${iconify('^arrows-alt')}
|
||||
</div>
|
||||
`
|
||||
|
||||
super({...options, html: html})
|
||||
|
||||
this.sensor = new GyroNorm()
|
||||
this.sensor.init({
|
||||
|
||||
frequency: 1000 / clip(this.getProp('frequency'), [0.01, 60]),
|
||||
gravityNormalized: this.getProp('normalize'),
|
||||
orientationBase: this.getProp('compass') ? GyroNorm.WORLD : GyroNorm.GAME,
|
||||
decimalCount: this.getProp('precision'),
|
||||
screenAdjusted: this.getProp('screenAdjusted'),
|
||||
logger: null
|
||||
|
||||
}).then(()=>{
|
||||
|
||||
this.sensor.start((data)=>{
|
||||
|
||||
this.setValue(data, {sync: true})
|
||||
|
||||
// data.do.alpha ( deviceorientation event alpha value )
|
||||
// data.do.beta ( deviceorientation event beta value )
|
||||
// data.do.gamma ( deviceorientation event gamma value )
|
||||
// data.do.absolute ( deviceorientation event absolute value )
|
||||
|
||||
// data.dm.x ( devicemotion event acceleration x value )
|
||||
// data.dm.y ( devicemotion event acceleration y value )
|
||||
// data.dm.z ( devicemotion event acceleration z value )
|
||||
|
||||
// data.dm.gx ( devicemotion event accelerationIncludingGravity x value )
|
||||
// data.dm.gy ( devicemotion event accelerationIncludingGravity y value )
|
||||
// data.dm.gz ( devicemotion event accelerationIncludingGravity z value )
|
||||
|
||||
// data.dm.alpha ( devicemotion event rotationRate alpha value )
|
||||
// data.dm.beta ( devicemotion event rotationRate beta value )
|
||||
// data.dm.gamma ( devicemotion event rotationRate gamma value )
|
||||
|
||||
|
||||
})
|
||||
|
||||
}).catch((e)=>{
|
||||
|
||||
console.log(e)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
setValue(v, options={} ) {
|
||||
|
||||
this.value = v
|
||||
|
||||
// if (options.send) this.sendValue()
|
||||
if (options.sync) this.changed(options)
|
||||
|
||||
}
|
||||
|
||||
onRemove() {
|
||||
|
||||
this.sensor.end()
|
||||
|
||||
super.onRemove()
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = Gyroscope
|
||||
|
|
@ -160,3 +160,43 @@
|
|||
border: 1rem solid var(--color-bg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.gyroscope-container {
|
||||
width: 100rem;
|
||||
height:60rem;
|
||||
flex-shrink: 0;
|
||||
padding:1rem;
|
||||
--opacity: .75;
|
||||
.gyroscope {
|
||||
flex: 1 1 100%;
|
||||
height:35rem;
|
||||
padding: 10rem;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: var(--color-track);
|
||||
color:var(--color-custom);
|
||||
border: 1rem solid var(--color-bg);
|
||||
@extend .glass-effect;
|
||||
i {
|
||||
opacity: var(--opacity);
|
||||
}
|
||||
span {
|
||||
font-family: monospace;
|
||||
letter-spacing: 0;
|
||||
margin-left: 4rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.panel:not(.tab) > .gyroscope-container {
|
||||
--color-border:transparent;
|
||||
padding: 0rem;
|
||||
.gyroscope {
|
||||
margin: 1rem;
|
||||
box-shadow: 0 0 0 1rem var(--color-light),
|
||||
0 0 0 1rem var(--color-fg);
|
||||
border: 1rem solid var(--color-bg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue