Ejemplo n.º 1
0
        static Task RunLoop(ProcDevice proc)
        {
            long loops = 0;

            Event[] events;
            //_coils["trough"].Pulse(255);

            var flasher = _coils["flasher"];

            //flasher.Pulse(255);

            //flasher.Schedule(0x4F4F4F4F, 10); //schedule for 10 sec

            //flasher.Patter(0, 0, 0); // on 1, off 1
            flasher.Patter(10, 0, 0); // on 10ms, off 1

            //flasher.Patter(255, 10); //flash fast
            //flasher.Patter(255, 255); //flash med
            //flasher.Patter(10, 10); //always on (pretty much)


            while (!source.IsCancellationRequested)
            {
                loops++;
                events = proc.Getevents();
                if (events != null)
                {
                    foreach (Event evt in events)
                    {
                        if (evt.Type != EventType.None && evt.Type != EventType.Invalid)
                        {
                            Console.WriteLine($"{evt.Type} event");
                            Switch sw          = _switches[(ushort)evt.Value];
                            bool   recvd_state = evt.Type == EventType.SwitchClosedDebounced;
                            if (!sw.IsState(recvd_state))
                            {
                                Console.WriteLine($"{sw.Name} {recvd_state}");
                                sw.SetState(recvd_state);
                            }
                        }
                    }
                }

                proc.WatchDogTickle();
            }

            proc.Close();
            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            ProcDevice PROC = null;

            try
            {
                Console.WriteLine("Creating PROC");
                PROC = new ProcDevice(MachineType.PDB);
                await Task.Delay(100);

                PROC?.Reset(1);

                //load machine config.
                var config = MachineConfiguration.FromFile("machine.json");

                //create collections to pass into the setup.
                //The GameController does this for you in LoadConfig, but this is to test without a game
                _switches = new AttrCollection <ushort, string, Switch>();
                _leds     = new AttrCollection <ushort, string, LED>();
                _coils    = new AttrCollection <ushort, string, IDriver>();

                //setup machine items to be able to process events.
                (PROC as ProcDevice).SetupProcMachine(config, _switches: _switches, _leds: _leds, _coils: _coils);

                //listen for cancel keypress and end run loop
                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    Console.WriteLine("ctrl+C triggered");
                    source.Cancel();
                    eventArgs.Cancel = true;
                };



                //run game loop
                await RunLoop(PROC);

                //close console
                Console.WriteLine("netprocgame closing...");
                await Task.Delay(500);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public void Test1()
        {
            ProcDevice proc = null;

            try
            {
                proc = new ProcDevice(MACHINE_TYPE);
                System.Threading.Thread.Sleep(100);
                proc.Reset(1);
                proc?.Close();
                Assert.True(true); //got this far to pass as device is initialized in ProcDevice constructor
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                proc?.Close();
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new GameController object with the given machine type and logging infrastructure
        /// </summary>
        /// <param name="machineType">Machine type to use (WPC, STERN, PDB etc)</param>
        /// <param name="logger">The logger interface to use</param>
        public GameController(MachineType machineType, ILogger logger)
        {
            this.Logger       = logger;
            this._machineType = machineType;
            this._proc        = new ProcDevice(machineType, Logger);
            this._proc.reset(1);
            this._modes       = new ModeQueue(this);
            this._bootTime    = Time.GetTime();
            this._coils       = new AttrCollection <ushort, string, Driver>();
            this._switches    = new AttrCollection <ushort, string, Switch>();
            this._lamps       = new AttrCollection <ushort, string, Driver>();
            this._gi          = new AttrCollection <ushort, string, Driver>();
            this._old_players = new List <Player>();
            this._players     = new List <Player>();

            testFrame = new byte[128 * 32];
            for (int i = 0; i < (128 * 32); i++)
            {
                testFrame[i] = 0;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new GameController object with the given machine type and logging infrastructure
        /// </summary>
        /// <param name="machineType">Machine type to use (WPC, STERN, PDB etc)</param>
        /// <param name="logger">The logger interface to use</param>
        public GameController(MachineType machineType, ILogger logger)
        {
            this.Logger = logger;
            this._machineType = machineType;
            this._proc = new ProcDevice(machineType, Logger);
            this._proc.reset(1);
            this._modes = new ModeQueue(this);
            this._bootTime = Time.GetTime();
            this._coils = new AttrCollection<ushort, string, Driver>();
            this._switches = new AttrCollection<ushort, string, Switch>();
            this._lamps = new AttrCollection<ushort, string, Driver>();
            this._gi = new AttrCollection<ushort, string, Driver>();
            this._old_players = new List<Player>();
            this._players = new List<Player>();

            testFrame = new byte[128 * 32];
            for (int i = 0; i < (128 * 32); i++)
            {
                testFrame[i] = 0;
            }
        }