Exemple #1
0
        static void Main(string[] args)
        {
            logger.Info("Starting!");

            TheSockets      sockets = new TheSockets();
            SimpleWebServer nws     = new SimpleWebServer(4567);

            nws.Start();

            InfluxConnection c = new InfluxConnection();

            c.URL = "http://localhost:8086/";

            // HttpInfluxDB db = new HttpInfluxDB(c);
            // db.CreateDatabase("influxdays");
            // sockets.influx = new HttpInfluxWriter(db, "influxdays", 50000);


            foreach (var d in HidSharp.DeviceList.Local.GetHidDevices())
            {
                logger.Info("DEVICE: " + d.DevicePath);
                try
                {
                    logger.Info(" > " + d.GetFriendlyName());
                }
                catch { }
            }


            DeviceWatcher watcherSide  = null;
            DeviceWatcher watcherWheel = null;

            HidSharp.HidDevice dev = DeviceWatcher.find("Saitek Side Panel Control Deck");
            if (dev != null)
            {
                watcherSide = new DeviceWatcher("panel_", dev, sockets);
            }

            dev = DeviceWatcher.find("Saitek Heavy Eqpt. Wheel & Pedal");
            if (dev != null)
            {
                watcherWheel = new DeviceWatcher("wheel_", dev, sockets);
            }

            WebSocketServer server = new WebSocketServer("ws://0.0.0.0:8181");

            server.RestartAfterListenError = true;
            server.Start(socket =>
            {
                socket.OnOpen = () => {
                    sockets.open.Add(socket);
                    logger.Info("WebSocket Open! " + sockets.open.Count);

                    if (watcherSide != null)
                    {
                        watcherSide.broadcast();
                    }
                    if (watcherWheel != null)
                    {
                        watcherWheel.broadcast();
                    }
                };
                socket.OnClose   = () => { sockets.open.Remove(socket); logger.Info("WebSocket Remove! " + sockets.open.Count); };
                socket.OnMessage = message => logger.Info("WebSocket: " + message);
            });


            while (true)
            {
                var x = Console.ReadLine();
                Console.WriteLine("ECHO: " + x);
            }
        }
Exemple #2
0
 public HttpInfluxDB(InfluxConnection c)
 {
     this.conn = c;
 }