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

View File

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