Skip to main content
Version: v1.0

STAND

Creating Sensors

const stand = hmSensor.createSensor(hmSensor.id.STAND)

console.log(stand.current)

STAND instance

stand: object

PropertiesDescriptionType
currentNumber of hours with current standing behaviornumber
targetNumber of hours with standing targetsnumber

Registering sensor instance callback events

calorie.addEventListener(event, callback: Callback)

The events of CHANGE

The value of event

hmSensor.event.CHANGE

Callback

() => void

Full Example

class TextByLine {
constructor(params) {
const { text = '', y = undefined, line = 0 } = params

this.text = text
this.y = y
this.line = line
this.y_computed = Number.isInteger(this.y) ? this.y : px(this.line * 60 + 120)
}

render() {
return hmUI.createWidget(hmUI.widget.TEXT, {
x: px(0),
y: this.y_computed,
w: px(480),
h: px(46),
color: 0xffffff,
text_size: px(20),
align_h: hmUI.align.CENTER_H,
align_v: hmUI.align.CENTER_V,
text_style: hmUI.text_style.NONE,
text: this.text
})
}
}

Page({
build() {
const stand = hmSensor.createSensor(hmSensor.id.STAND)

new TextByLine({
text: `current:${stand.current};target:${stand.target}`,
line: 0
}).render()

const changeEventText = new TextByLine({
text: `EVENT-CHANGE:${stand.current}`,
line: 1
}).render()

const changeCallback = () => {
const current = stand.current

changeEventText.setProperty(hmUI.prop.MORE, {
text: `EVENT-CHANGE: ${current}`
})
}

const standChangeListener = () => {
stand.addEventListener(hmSensor.event.CHANGE, changeCallback)
}

hmUI.createWidget(hmUI.widget.BUTTON, {
x: px(80),
y: px(300),
w: px(300),
h: px(60),
radius: px(12),
normal_color: 0xfc6950,
press_color: 0xfeb4a8,
text: 'REGISTER_CHANGE',
click_func: standChangeListener
})
}
})