This commit is contained in:
赵鑫 2022-09-01 13:20:50 +08:00
parent ace13b7f6d
commit 4e17a28519
2 changed files with 8 additions and 13 deletions

View File

@ -129,25 +129,20 @@
</div>
</div>
<button class="button" data-action="clear">clear all</button>
<button onclick="emit('clear')">clear all</button>
<br>
<button class="button" data-action="hello">hello</button>
<button onclick="emit('hello')">hello</button>
<br>
<button class="button" data-action="flash">flash</button>
<button onclick="emit('flash')">flash</button>
<br>
<button class="button" data-action="temp">temp</button>
<button onclick="emit('temp')">temp</button>
<script src="socket.io/socket.io.js"></script>
<script>
const client = io()
document.addEventListener('click', (event) => {
const item = event.target
if (item.classList.contains('button')) {
const { action } = item.dataset
document.querySelectorAll('.led').forEach((led) => led.classList.remove('on'))
client.emit('action', { action })
}
})
function emit(action) {
client.emit('action', { action })
}
function turnon(led) {
const { x, y } = led.dataset
const action = led.classList.toggle('on') ? 'on' : 'off'

View File

@ -8,7 +8,7 @@ app.use(express.static('public'))
sense.setRotation(180)
sense.lowLight = true
const blue = [50, 50, 200]
const blue = [0, 0, 100]
flash()
io.on('connection', (client) => {
client.on('action', ({ action, x, y }) => {