update
This commit is contained in:
parent
4170748507
commit
c911da4dc0
46
sensehat.js
46
sensehat.js
@ -10,19 +10,8 @@ app.use(express.static('public'))
|
||||
sense.setRotation(180)
|
||||
sense.lowLight = true
|
||||
|
||||
const job = new CronJob(
|
||||
'*/5 * * * * *',
|
||||
async () => {
|
||||
// 测试 http://zhao 的连通性
|
||||
request('http://zhao', (err, res, body) => {
|
||||
console.log(err, res.statusCode)
|
||||
})
|
||||
},
|
||||
null,
|
||||
true
|
||||
)
|
||||
|
||||
const blue = [0, 0, 255]
|
||||
const color_red = [255, 0]
|
||||
const color_blue = [0, 0, 255]
|
||||
const leds = [
|
||||
[0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0],
|
||||
@ -35,13 +24,40 @@ const leds = [
|
||||
]
|
||||
read_all_leds()
|
||||
|
||||
let zhao_server_errors = 0
|
||||
|
||||
const job = new CronJob(
|
||||
'*/5 * * * * *',
|
||||
async () => {
|
||||
// 测试 http://zhao 的连通性
|
||||
request('http://zhao', (err, res, body) => {
|
||||
if (res.statusCode != 200) {
|
||||
zhao_server_errors++
|
||||
}
|
||||
if (zhao_server_errors > 0) {
|
||||
for (let i = 0; i < zhao_server_errors; i++) {
|
||||
const x = i % 8
|
||||
const y = Math.floor(i / 8)
|
||||
sense.setPixel(x, y, color_red)
|
||||
}
|
||||
} else {
|
||||
let color = sense.getPixel(0, 0)
|
||||
color[2] = (color[2] + 50) % 255
|
||||
sense.setPixel(0, 0, color)
|
||||
}
|
||||
})
|
||||
},
|
||||
null,
|
||||
true
|
||||
)
|
||||
|
||||
io.on('connection', (client) => {
|
||||
client.emit('leds', leds)
|
||||
client.on('action', ({ action, x, y }) => {
|
||||
console.log({ action, x, y })
|
||||
switch (action) {
|
||||
case 'on':
|
||||
sense.setPixel(Number(x), Number(y), blue)
|
||||
sense.setPixel(Number(x), Number(y), color_blue)
|
||||
leds[y][x] = 1
|
||||
break
|
||||
case 'off':
|
||||
@ -49,7 +65,7 @@ io.on('connection', (client) => {
|
||||
leds[y][x] = 0
|
||||
break
|
||||
case 'hello':
|
||||
sense.flashMessage('HELLO', 1, blue)
|
||||
sense.flashMessage('HELLO', 1, color_blue)
|
||||
sense.clear()
|
||||
read_all_leds(0)
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user