update
This commit is contained in:
parent
85cdc3abaf
commit
1a2d5c4e65
34
server.js
34
server.js
@ -57,6 +57,7 @@ sensehat.led.loadImage('images/heart.png')
|
||||
// socketio 服务
|
||||
const io = require('socket.io')(server, { cors: { origin: '*' } })
|
||||
io.on('connection', (client) => {
|
||||
io.emit('action', { action: 'setPixels', pixels: sensehat.led.pixels })
|
||||
client.on('action', ({ action, x, y, color, pixels, delay }) => {
|
||||
switch (action) {
|
||||
case 'clear':
|
||||
@ -64,20 +65,24 @@ io.on('connection', (client) => {
|
||||
sensehat.led.clear(color)
|
||||
client.emit('action', { action: 'clear', color })
|
||||
break
|
||||
case 'flash':
|
||||
if (color == undefined) color = [255, 255, 255]
|
||||
sensehat.led.clear(color)
|
||||
setTimeout(sensehat.led.clear, delay | 200)
|
||||
client.emit('action', { action: 'clear' })
|
||||
break
|
||||
case 'getPixel':
|
||||
color = sensehat.led.getPixel(x, y)
|
||||
client.emit('action', { action: 'setPixel', x, y, color })
|
||||
break
|
||||
case 'setPixel':
|
||||
if (color == undefined) color = [255, 255, 255]
|
||||
sensehat.led.setPixel(x, y, color)
|
||||
io.emit('action', { action: 'setPixel', x, y, color })
|
||||
// case 'flash':
|
||||
// if (color == undefined) color = [255, 255, 255]
|
||||
// sensehat.led.clear(color)
|
||||
// setTimeout(sensehat.led.clear, delay | 200)
|
||||
// client.emit('action', { action: 'clear' })
|
||||
// break
|
||||
// case 'getPixel':
|
||||
// color = sensehat.led.getPixel(x, y)
|
||||
// client.emit('action', { action: 'setPixel', x, y, color })
|
||||
// break
|
||||
// case 'setPixel':
|
||||
// if (color == undefined) color = [255, 255, 255]
|
||||
// sensehat.led.setPixel(x, y, color)
|
||||
// io.emit('action', { action: 'setPixel', x, y, color })
|
||||
// break
|
||||
case 'getPixels':
|
||||
const pixels = sensehat.led.setPixels()
|
||||
io.emit('action', { action: 'setPixels', pixels })
|
||||
break
|
||||
// case 'on':
|
||||
// sense.setPixel(Number(x), Number(y), color_blue)
|
||||
@ -94,7 +99,6 @@ io.on('connection', (client) => {
|
||||
// break
|
||||
|
||||
default:
|
||||
console.log('okokokokok')
|
||||
break
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user