From 1a2d5c4e653c251ba0e2eb62b7548d9371c00282 Mon Sep 17 00:00:00 2001 From: Zhao Xin <7176466@qq.com> Date: Mon, 5 Sep 2022 11:39:47 +0800 Subject: [PATCH] update --- server.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/server.js b/server.js index 3f7cd9a..45142c0 100644 --- a/server.js +++ b/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 }