update
This commit is contained in:
parent
b37e3c32ab
commit
f84e54e870
22
server.js
22
server.js
@ -27,7 +27,6 @@ const sensehat = {
|
||||
sleep(n) 暂停 n 秒
|
||||
clear() 清除所有
|
||||
clear(rgb) or clear([r,g,b]) 填充颜色
|
||||
|
||||
setPixel(x,y,r,g,b) or setPixel(x,y,rgb) 设置一个点
|
||||
getPixel(x,y) 返回 [r,g,b] 获取一个点
|
||||
setPixels([[r,g,b]*64])
|
||||
@ -60,6 +59,7 @@ 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 }) => {
|
||||
x = Number(x), y = Number(y), delay = Number(delay) | 200
|
||||
switch (action) {
|
||||
case 'clear':
|
||||
if (color == undefined) color = [0, 0, 0]
|
||||
@ -73,18 +73,26 @@ io.on('connection', (client) => {
|
||||
setTimeout(() => {
|
||||
sensehat.led.clear()
|
||||
io.emit('action', { action: 'clear' })
|
||||
}, delay | 200)
|
||||
}, delay)
|
||||
break
|
||||
case 'setPixel':
|
||||
if (color == undefined) color = [255, 255, 255]
|
||||
x = Number(x), y = Number(y)
|
||||
sensehat.led.setPixel(x, y, color)
|
||||
io.emit('action', { action: 'setPixel', x, y, color })
|
||||
break
|
||||
// case 'getPixel':
|
||||
// color = sensehat.led.getPixel(x, y)
|
||||
// client.emit('action', { action: 'setPixel', x, y, color })
|
||||
// break
|
||||
case 'getPixel':
|
||||
color = sensehat.led.getPixel(x, y)
|
||||
client.emit('action', { action: 'setPixel', x, y, color })
|
||||
break
|
||||
case 'setPixels':
|
||||
for (let i = 0; i < pixels.length; i++) {
|
||||
var color = pixels[i]
|
||||
var x = i % 8
|
||||
var y = Math.floor(i / 8)
|
||||
sensehat.led.setPixel(x, y, color)
|
||||
}
|
||||
io.emit('action', { action: 'setPixels', pixels: sensehat.led.pixels })
|
||||
break
|
||||
case 'getPixels':
|
||||
io.emit('action', { action: 'setPixels', pixels: sensehat.led.pixels })
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user