/// <summary>
        /// Create a new machine configuration representation in memory from a file on disk
        /// </summary>
        /// <param name="PathToFile">The path to the configuration XML file</param>
        public void LoadConfig(string PathToFile)
        {
            MachineConfiguration config = MachineConfiguration.FromFile(PathToFile);

            _config          = config;
            _num_balls_total = config.PRGame.numBalls;

            //setup machine items
            (PROC as ProcDevice).SetupProcMachine(config, _coils, _switches, _lamps, _leds, _gi);
        }
Example #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());
            }
        }
Example #3
0
        /// <summary>
        /// Create a new machine configuration representation in memory from a file on disk
        /// </summary>
        /// <param name="PathToFile">The path to the configuration XML file</param>
        public void LoadConfig(string PathToFile)
        {
            MachineConfiguration config = MachineConfiguration.FromFile(PathToFile);

            foreach (CoilConfigFileEntry ce in config.PRCoils)
            {
                Driver d = new Driver(this, ce.Name, PinProc.PRDecode(_machineType, ce.Number));
                Log("Adding driver " + d.ToString());
                _coils.Add(d.Number, d.Name, d);
            }

            foreach (LampConfigFileEntry le in config.PRLamps)
            {
                Driver d = new Driver(this, le.Name, PinProc.PRDecode(_machineType, le.Number));
                Log("Adding lamp " + d.ToString());
                _lamps.Add(d.Number, d.Name, d);
            }

            foreach (GIConfigFileEntry ge in config.PRGI)
            {
                Driver d = new Driver(this, ge.Name, PinProc.PRDecode(_machineType, ge.Number));
                _gi.Add(d.Number, d.Name, d);
            }

            foreach (SwitchConfigFileEntry se in config.PRSwitches)
            {
                Switch s = new Switch(this, se.Name, PinProc.PRDecode(_machineType, se.Number), se.Type);

                _proc.switch_update_rule(s.Number,
                                         EventType.SwitchClosedDebounced,
                                         new SwitchRule {
                    NotifyHost = true, ReloadActive = false
                },
                                         null,
                                         false
                                         );
                _proc.switch_update_rule(s.Number,
                                         EventType.SwitchOpenDebounced,
                                         new SwitchRule {
                    NotifyHost = true, ReloadActive = false
                },
                                         null,
                                         false
                                         );
                Log("Adding switch " + s.ToString());
                _switches.Add(s.Number, s.Name, s);
            }

            /// TODO: THIS SHOULD RETURN A LIST OF STATES
            EventType[] states = _proc.switch_get_states();
            foreach (Switch s in _switches.Values)
            {
                s.SetState(states[s.Number] == EventType.SwitchClosedDebounced);
            }

            _num_balls_total = config.PRGame.numBalls;
            _config          = config;

            if (_config.PRGame.displayMonitor)
            {
            }
        }