예제 #1
0
 public GameItem(IProcDevice proc, string name, ushort number, string strNumber = "")
 {
     this.proc    = proc;
     this._name   = name;
     this._number = number;
     _strNumber   = strNumber;
 }
예제 #2
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, bool Simulated = false)
        {
            this.Logger       = logger;
            this._machineType = machineType;
            if (Simulated)
            {
                this._proc        = new FakePinProc(machineType);
                this._proc.Logger = logger;
                this._proc.Reset(1);
            }
            else
            {
                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, IDriver>();
            this._switches    = new AttrCollection <ushort, string, Switch>();
            this._lamps       = new AttrCollection <ushort, string, IDriver>();
            this._leds        = new AttrCollection <ushort, string, LED>();
            this._gi          = new AttrCollection <ushort, string, IDriver>();
            this._old_players = new List <IPlayer>();
            this._players     = new List <IPlayer>();

            this.LampController = new LampController(this);

            testFrame = new byte[128 * 32];
            for (int i = 0; i < (128 * 32); i++)
            {
                testFrame[i] = 0;
            }
        }
예제 #3
0
 public PDLED(IProcDevice proc, uint boardAddress)
 {
     this.proc         = proc;
     this.BoardAddress = boardAddress;
     baseRegAddress    = 0x01000000 | (boardAddress & 0x3F) << 16;
     fadeTime          = 0;
     Console.WriteLine($"Created pdled, board address {boardAddress}");
 }
예제 #4
0
 public I2cServo(uint number, ServoConfiguration config, IProcDevice platform)
 {
     if (number < 0 || number > 15)
     {
         throw new ArgumentException("The servo number must be between 0 and 15");
     }
     this.platform = platform;
     this.number   = number;
     this.config   = config;
 }
예제 #5
0
        public VirtualDriver(IProcDevice proc, string name, ushort number, bool polarity)
            : base(proc, name, number)
        {
            this._state                      = new DriverState();
            this._state.Polarity             = polarity;
            this._state.Timeslots            = 0x0;
            this._state.PatterEnable         = false;
            this._state.DriverNum            = number;
            this._state.PatterOnTime         = 0;
            this._state.PatterOffTime        = 0;
            this._state.State                = false;
            this._state.OutputDriveTime      = 0;
            this._state.WaitForFirstTimeSlot = false;

            this._currentValue = !(_currentState ^ this._state.Polarity);
        }
예제 #6
0
        public void InitializeDrivers(IProcDevice proc)
        {
            // Loop through all of the drivers, initializing them with the polarity
            for (ushort i = 0; i < 208; i++)
            {
                DriverState state = new DriverState();
                state.DriverNum            = i;
                state.OutputDriveTime      = 0;
                state.Polarity             = true;
                state.State                = false;
                state.WaitForFirstTimeSlot = false;
                state.Timeslots            = 0;
                state.PatterOnTime         = 0;
                state.PatterOffTime        = 0;
                state.PatterEnable         = false;
                state.futureEnable         = false;

                proc.driver_update_state(ref state);
            }
        }
예제 #7
0
        public void ConfigureGlobals(IProcDevice proc, List <int> lamp_source_bank_list, bool enable = true)
        {
            if (enable)
            {
                Console.WriteLine(String.Format("Configuring PDB driver globals: polarity = {0}  matrix column index 0 = {1}  matrix column index 1 = {2}", true, lamp_source_bank_list[0], lamp_source_bank_list[1]));
            }

            proc.driver_update_global_config(
                enable, // Don't enable outputs yet
                true,   // Polarity
                false,  // N/A
                false,  // N/A
                1,      // N/A
                (byte)lamp_source_bank_list[0],
                (byte)lamp_source_bank_list[1],
                false,             // Active low rows? nope
                false,             // N/A
                false,             // Stern? Heck no
                false,             // Reset watchdog trigger
                this.use_watchdog, // Use the watchdog
                this.watchdog_time);

            // Now set up globals
            proc.driver_update_global_config(
                true,  // Don't enable outputs yet
                true,  // Polarity
                false, // N/A
                false, // N/A
                1,     // N/A
                (byte)lamp_source_bank_list[0],
                (byte)lamp_source_bank_list[1],
                false,             // Active low rows? nope
                false,             // N/A
                false,             // Stern? Heck no
                false,             // Reset watchdog trigger
                this.use_watchdog, // Use the watchdog
                this.watchdog_time);
        }
예제 #8
0
        public LED(IProcDevice proc, string name, ushort number, string strNumber = "") : base(proc, name, number, strNumber)
        {
            //take the first number in the array to get address. A0-R0-G1-B2
            var crList = strNumber.Split('-');

            boardAddress = uint.Parse(crList[0].Substring(1));

            //get the colors
            addrs = new List <uint>();
            foreach (var item in crList.Skip(1))
            {
                addrs.Add(uint.Parse(item.Substring(1)));
            }

            System.Console.WriteLine($"Creating LED: {name}, board_addr: {boardAddress}, color_addrs: {string.Join(",", addrs)}");
            function = "none";

            //check if the led already exists in collection
            var pdLedExists = false;

            foreach (var pdLed in LEDS.PDLEDS)
            {
                if (pdLed.BoardAddress == this.boardAddress)
                {
                    pdLedExists = true;
                    this.board  = pdLed;
                    continue;
                }
            }

            //add the board if wasn't found into PDLEDS collection
            if (!pdLedExists)
            {
                this.board = new PDLED(proc, boardAddress);
                LEDS.PDLEDS.Add(board);
            }
        }
예제 #9
0
 public Driver(IProcDevice proc, string name, ushort number)
     : base(proc, name, number)
 {
 }
예제 #10
0
        public PDBConfig(IProcDevice proc, MachineConfiguration config)
        {
            this.proc = proc;
            this.GetGlobals(config);

            // Initialize some lists for data collection
            List <int>                   coil_bank_list        = new List <int>();
            List <int>                   lamp_source_bank_list = new List <int>();
            List <PDBLampEntry>          lamp_list             = new List <PDBLampEntry>();
            List <PDBLampListIndexEntry> lamp_list_for_index   = new List <PDBLampListIndexEntry>();

            this.aliases = new List <DriverAlias>();
            this.indexes = new List <object>();

            if (config.PRDriverAliases != null)
            {
                foreach (DriverAliasEntry alias in config.PRDriverAliases)
                {
                    aliases.Add(new DriverAlias(alias.expr, alias.repl));
                }
            }
            // Make a list of unique coil banks
            foreach (CoilConfigFileEntry coil in config.PRCoils)
            {
                Coil coilObj = new Coil(this, coil.Number);
                if (!coil_bank_list.Contains(coilObj.bank()))
                {
                    coil_bank_list.Add(coilObj.bank());
                }
            }

            // Make a list of lamp source banks. The P-ROC only supports 2
            foreach (LampConfigFileEntry lamp in config.PRLamps)
            {
                Lamp lampObj = new Lamp(this, lamp.Number);

                // Catalog PDB banks
                // Dedicated lamps don't use PDB banks, they're direct driver pins.
                if (lampObj.lamp_type == "dedicated")
                {
                    continue;
                }
                else if (lampObj.lamp_type == "pdb")
                {
                    if (!lamp_source_bank_list.Contains(lampObj.SourceBank()))
                    {
                        lamp_source_bank_list.Add(lampObj.SourceBank());
                    }

                    // Create dicts of unique sink banks. The source index is needed when
                    // setting up the driver groups
                    PDBLampEntry lamp_dict = new PDBLampEntry()
                    {
                        source_index  = lamp_source_bank_list.IndexOf(lampObj.SourceBank()),
                        sink_bank     = lampObj.SinkBank(),
                        source_output = lampObj.SourceOutput()
                    };
                    PDBLampListIndexEntry lamp_dict_for_index = new PDBLampListIndexEntry()
                    {
                        source_board  = lampObj.SourceBoard(),
                        sink_bank     = lampObj.SinkBank(),
                        source_output = lampObj.SourceOutput()
                    };

                    if (!lamp_list.Contains(lamp_dict))
                    {
                        lamp_list.Add(lamp_dict);
                        lamp_list_for_index.Add(lamp_dict_for_index);
                    }
                }
            }
            // Create a list of indexes. The PDB banks will be mapped into this list.
            // The index of the bank is used to calculate the P-ROC driver number for
            // each driver.
            int num_proc_banks = PinProc.kPRDriverCount / 8;

            for (int i = 0; i < num_proc_banks; i++)
            {
                indexes.Add(99);
            }

            this.InitializeDrivers(proc);

            // Set up dedicated driver groups (groups 0-3)
            int group_ctr = 0;

            for (group_ctr = 0; group_ctr < 4; group_ctr++)
            {
                bool enable = coil_bank_list.Contains(group_ctr);
                proc.driver_update_group_config(
                    (byte)group_ctr,
                    0,
                    (byte)group_ctr,
                    0,
                    0,
                    false,
                    true,
                    enable,
                    true
                    );
            }
            group_ctr++;

            // Process lamps first. The P-ROC can only control so many drivers directly.
            // Since software won't have the speed to control lamp matrixes, map the lamps
            // first. If there aren't enough P-ROC driver groups for coils, the overflow
            // coils can be controlled by software via VirtualDrivers (which should get set up
            // automagically here)
            for (int i = 0; i < lamp_list.Count; i++)
            {
                PDBLampEntry lamp_dict = lamp_list[i];
                if (group_ctr >= num_proc_banks || lamp_dict.sink_bank >= 16)
                {
                    Console.WriteLine("Lamp matrix banks can't be mapped to index {0} because thats outside of the banks that P-ROC can control.", lamp_dict.sink_bank);
                }
                else
                {
                    Console.WriteLine("Driver group {0}: slow_time={1} enable_index={2} row_activate_index={3} row_enable_index={4} matrix={5}", group_ctr, lamp_matrix_strobe_time, lamp_dict.sink_bank, lamp_dict.source_output, lamp_dict.source_index);
                    this.indexes[group_ctr] = lamp_list_for_index[i];
                    proc.driver_update_group_config((byte)group_ctr,
                                                    (byte)lamp_matrix_strobe_time,
                                                    (byte)lamp_dict.sink_bank,
                                                    (byte)lamp_dict.source_output,
                                                    (byte)lamp_dict.source_index,
                                                    true,
                                                    true,
                                                    true,
                                                    true);
                    group_ctr++;
                }
            }

            for (int i = 0; i < coil_bank_list.Count; i++)
            {
                // If the bank is 16 or higher, the P-ROC can't control it directly. Software
                // will have to do the driver logic and write any changes to the PDB bus.
                // Therefore, map these banks to indexes above the P-ROC's driver count,
                // which will force the drivers to be created as VirtualDrivers.
                // Appending the bank avoids conflicts when the group counter (group_ctr) gets too high.
                if (group_ctr >= num_proc_banks || coil_bank_list[i] >= 16)
                {
                    Console.WriteLine("Driver group {0} mapped to driver index outside of P-ROC control. These drivers will become VirtualDrivers. Note, the index will not match the board/bank number; so software will need to request those values before updating the drivers.", coil_bank_list[i]);
                    indexes.Add(coil_bank_list[i]);
                }
                else
                {
                    Console.WriteLine("Driver group {0}: slow_time={1} Enable Index={2}", group_ctr, 0, coil_bank_list[i]);
                    indexes[group_ctr] = coil_bank_list[i];
                    proc.driver_update_group_config((byte)group_ctr,
                                                    0,
                                                    (byte)coil_bank_list[i],
                                                    0,
                                                    0,
                                                    false,
                                                    true,
                                                    true,
                                                    true);

                    group_ctr++;
                }
            }

            for (int i = group_ctr; i < 26; i++)
            {
                Console.WriteLine("Driver group {0} disabled", i);
                proc.driver_update_group_config((byte)i,
                                                lamp_matrix_strobe_time,
                                                0,
                                                0,
                                                0,
                                                false,
                                                true,
                                                false,
                                                true);
            }
            // Make sure there are two indexes. If not, fill them in
            while (lamp_source_bank_list.Count < 2)
            {
                lamp_source_bank_list.Add(0);
            }

            // Now set up globals. First disable them to allow the P-ROC to set up the
            // polarities on the drivers, then enable them.

            ConfigureGlobals(proc, lamp_source_bank_list, false);
            ConfigureGlobals(proc, lamp_source_bank_list, true);
        }
예제 #11
0
 /// <summary>
 /// Creates a new Switch object
 /// </summary>
 /// <param name="game">The GameController this switch belongs to</param>
 /// <param name="name">The pretty name of this switch</param>
 /// <param name="number">The encoded number of this switch</param>
 /// <param name="sType">Switch type NO = Normally Open (leaf switches), NC = Normally Closed (optos)</param>
 public Switch(IProcDevice proc, string name, ushort number, SwitchType sType = SwitchType.NO)
     : base(proc, name, number)
 {
     this._type = sType;
 }