79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import HttpServer from './http';
|
|
import IO, { ISensors } from './io';
|
|
import VideoSocket from './ws';
|
|
|
|
const HTTP_PORT = process.env.HTTP_PORT ? parseInt(process.env.HTTP_PORT, 10) : 8080;
|
|
const WS_PORT = process.env.WS_PORT ? parseInt(process.env.WS_PORT, 10) : 3003;
|
|
const STATIC_ROOT = process.cwd() + "/dist/static";
|
|
const TV_DEV_0 = process.env.TV_DEV_0 ?? '/dev/video0'
|
|
|
|
// const zap = new Zap();
|
|
|
|
|
|
// const tune = (reqChannel: string, reqAdapter?: number) => {
|
|
// const adapter = reqAdapter === 0 || reqAdapter === 1 ? reqAdapter : 0;
|
|
// zap.zapTo(reqChannel, adapter).then((zap: IZap) => {
|
|
// console.log(`Tuned ${zap.adapter} to ${zap.channel}`)
|
|
// }).catch((err: Error) => {
|
|
// console.error(err.message);
|
|
// });
|
|
// }
|
|
|
|
// const getChannels = () =>
|
|
// zap.getChannels();
|
|
|
|
// const getSignal = (adapter: number) =>
|
|
// zap.getSignal(adapter)
|
|
|
|
const io = new IO();
|
|
const getSensors: ()=>ISensors = io.getSensors.bind(io);
|
|
// setTimeout(()=>{
|
|
// console.log("sen ",io.getSensors())
|
|
// console.log("sen2 ",getSensors())
|
|
// },200)
|
|
// const setPower = io.setPower.bind(this, true)
|
|
// const togglePower = io.togglePower.bind(this)
|
|
const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, io);
|
|
const videoSocket = new VideoSocket(WS_PORT, TV_DEV_0, getSensors);
|
|
|
|
httpServer.start();
|
|
|
|
|
|
process.stdin.setEncoding("utf8");
|
|
process.stdin.resume();
|
|
|
|
console.log("Menu:\n1) Power off\n2)Power on\n3) Power flop\n4)Read Sensors");
|
|
|
|
process.stdin.on("data", async (data: string) => {
|
|
const input = data.trim();
|
|
console.log(`Received: "${input}"`);
|
|
const val = parseInt(input);
|
|
switch(val) {
|
|
case 0:
|
|
|
|
break;
|
|
case 1:
|
|
io.setPower(false);
|
|
break;
|
|
case 2:
|
|
io.setPower(true);
|
|
break;
|
|
case 3:
|
|
io.togglePower();
|
|
break;
|
|
case 4:
|
|
|
|
console.log("a ", getSensors())
|
|
break;
|
|
default:
|
|
console.log("No option for "+input)
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|