Skip to content

Commit

Permalink
scan for wled
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Jun 9, 2021
1 parent 4edf9ed commit dccaba6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
import { useState } from "react";
import {
Button,
Card,
CardHeader,
CardContent,
CardActions,
CircularProgress,
} from '@material-ui/core';
import logo from '../assets/logo.png';
import logoCircle from '../assets/ring.png';
import Guide from '../components/Guide';
import useStore from '../utils/apiStore';


const sleep = ms => {
return new Promise(resolve => setTimeout(resolve, ms));
};


export default function Home() {
const scanForDevices = useStore((state) => state.scanForDevices);
const getDevices = useStore((state) => state.getDevices);
const getDisplays = useStore((state) => state.getDisplays);
const [scanning, setScanning] = useState(false)

const handleScan = () => {
setScanning(true)
scanForDevices().then(async () => {
for (let sec = 1; sec <= 10; sec++) {
await sleep(1000).then(() => {
getDevices();
getDisplays();
setScanning(sec)
});
}
}).then(() => {
setScanning(false)
})
}
return (
<>
<div className="Content">
Expand Down Expand Up @@ -43,8 +71,12 @@ export default function Home() {
<Button disabled variant="outlined">
Docs
</Button>
<Button disabled variant="outlined">
Scan
<Button onClick={() => handleScan()} variant="outlined">
{scanning ? <CircularProgress
variant="determinate"
value={(scanning / 10) * 100}
size={24}
/> : 'Scan'}
</Button>
</CardActions>
</Card>
Expand Down
26 changes: 26 additions & 0 deletions src/utils/apiStore.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ const useStore = create(
set({ dialogs: { nohost: { open: true } } });
}
},
setSystemConfig: async (config) => {
const resp = await Ledfx('/api/config', set, 'PUT', config);
console.log(resp)
},
deleteSystemConfig: async () => {
const resp = await Ledfx('/api/config', set, 'DELETE');
console.log(resp)
Expand Down Expand Up @@ -480,6 +484,28 @@ const useStore = create(
// set({ dialogs: { nohost: { open: true } } });
}
},
scanForDevices: async () => {
const resp = await Ledfx('/api/find_devices', set, 'POST', {});
if (resp && resp.status === 'success') {
console.log(resp)
}
// if (resp && resp.status === 'success') {
// set({
// settings: get().settings,
// ...{
// "settings": {
// audio_inputs: get().settings.audio_inputs,
// "active_device_index": parseInt(index),
// }
// },

// });
// }
else {
set({ dialogs: { nohost: { open: true } } });
}
},



togglePause: async () => {
Expand Down

0 comments on commit dccaba6

Please sign in to comment.