Beispiel #1
0
    // Override GetHashCode().
    public override int GetHashCode()
    {
        int hashIsAlive  = IsAlive.GetHashCode();
        int hashIdetifer = Id.GetHashCode();

        return(hashIsAlive ^ hashIdetifer);
    }
Beispiel #2
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (IsAlive != false)
        {
            hash ^= IsAlive.GetHashCode();
        }
        if (FoodX != 0F)
        {
            hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(FoodX);
        }
        if (FoodZ != 0F)
        {
            hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(FoodZ);
        }
        if (Hp != 0F)
        {
            hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Hp);
        }
        if (Satiety != 0F)
        {
            hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Satiety);
        }
        if (Reward != 0F)
        {
            hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Reward);
        }
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
        public override int GetHashCode()
        {
            int hash = 1;

            if (FirstName.Length != 0)
            {
                hash ^= FirstName.GetHashCode();
            }
            if (LastName.Length != 0)
            {
                hash ^= LastName.GetHashCode();
            }
            if (EmailAddress.Length != 0)
            {
                hash ^= EmailAddress.GetHashCode();
            }
            if (IsAlive != false)
            {
                hash ^= IsAlive.GetHashCode();
            }
            if (Age != 0)
            {
                hash ^= Age.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #4
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,
            FPGA.OutputSignal <bool> Bank3,

            // WS2812
            FPGA.OutputSignal <bool> DOUT,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD

            // SERVO IO is generated inside handlers
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);
            QuokkaBoard.OutputBank(Bank3);

            IsAlive.Blink(LED1);

            DeviceControl(DOUT, RXD, TXD);
        }
Beispiel #5
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD

            )
        {
            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            IsAlive.Blink(LED1);

            Sequential handler = () =>
            {
                for (byte b = 0; b < 10; b++)
                {
                    UART.RegisteredWrite(115200, b, out internalTXD);
                }

                UART.RegisteredWrite(115200, 255, out internalTXD);
            };

            FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler);
        }
Beispiel #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IsAliveResponse Any(IsAlive request)
        {
            if (request == null)
            {
                return new IsAliveResponse
                {
                    Description = "传入的参数错误",
                    Status = (int)Status.InvalidArgument,
                    ReasonPhrase = Status.InvalidArgument.ToName(),
                    IsAlive = false
                };
            }
            ApiVersion apiVersion;
            if (string.IsNullOrEmpty(request.Version) || !request.Version.TryParse(out apiVersion))
            {
                return new IsAliveResponse
                {
                    Description = "非法的api版本号",
                    Status = (int)Status.InvalidApiVersion,
                    ReasonPhrase = Status.InvalidApiVersion.ToName(),
                    IsAlive = false
                };
            }

            return new IsAliveResponse
            {
                IsAlive = true,
                Status = (int)Status.Ok,
                ReasonPhrase = Status.Ok.ToName(),
                Description = "服务可用"
            };
        }
Beispiel #7
0
 public override int GetHashCode()
 {
     return(FirstName.GetHashCode()
            ^ LastName.GetHashCode()
            ^ Age.GetHashCode()
            ^ IsAlive.GetHashCode());
 }
Beispiel #8
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD

            )
        {
            IsAlive.Blink(LED1);

            Sequential handler = () =>
            {
                byte[] buff = new byte[11];
                for (byte b = 0; b < 10; b++)
                {
                    buff[b] = b;
                }
                buff[10] = 255;

                for (byte i = 0; i < buff.Length; i++)
                {
                    byte data = 0; // TODO: initializer from memory not supported yet
                    data = buff[i];
                    UART.Write(115200, data, TXD);
                }
            };

            FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler);
        }
Beispiel #9
0
        public static async Task Aggregator(
            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,

            // blinker
            FPGA.OutputSignal <bool> LED1,

            // WS2812
            FPGA.OutputSignal <bool> DOUT
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);

            IsAlive.Blink(LED1);

            bool internalDOUT = false;

            FPGA.Config.Link(internalDOUT, DOUT);

            byte state = 0;

            eCellType[] fieldMatrix = new eCellType[64];

            Sequential handler = () =>
            {
                state++;
                FieldMatrix.Reset(fieldMatrix);

                switch (state)
                {
                case 1:
                    fieldMatrix[0]  = eCellType.RedCross;
                    fieldMatrix[63] = eCellType.GreenCross;
                    break;

                case 2:
                    FieldMatrix.DrawCross(fieldMatrix, eCellType.GreenCross);
                    break;

                case 3:
                    FieldMatrix.DrawCross(fieldMatrix, eCellType.RedCross);
                    break;

                case 4:
                    Position head = new Position(), tail = new Position();
                    FieldMatrix.Seed(fieldMatrix, head, tail);
                    break;

                default:
                    state = 0;
                    break;
                }

                Graphics.DrawFieldMatrix(1, fieldMatrix, out internalDOUT);
            };

            FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler);
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IsAliveResponse Any(IsAlive request)
        {
            if (request == null)
            {
                return(new IsAliveResponse
                {
                    Description = "传入的参数错误",
                    Status = (int)Status.InvalidArgument,
                    ReasonPhrase = Status.InvalidArgument.ToName(),
                    IsAlive = false
                });
            }
            ApiVersion apiVersion;

            if (string.IsNullOrEmpty(request.Version) || !request.Version.TryParse(out apiVersion))
            {
                return(new IsAliveResponse
                {
                    Description = "非法的api版本号",
                    Status = (int)Status.InvalidApiVersion,
                    ReasonPhrase = Status.InvalidApiVersion.ToName(),
                    IsAlive = false
                });
            }

            return(new IsAliveResponse
            {
                IsAlive = true,
                Status = (int)Status.Ok,
                ReasonPhrase = Status.Ok.ToName(),
                Description = "服务可用"
            });
        }
Beispiel #11
0
        /// <summary>
        /// Used to set previous values for every <see cref="AbstractVariable{T}"/>. Must use the same order and logic as the <see cref="Scan"/> method.
        /// </summary>
        public void PreScan()
        {
            PlayerID.PreScan();
            Username.PreScan();

            IsReplay.PreScan();
            if (IsReplay.Value)
            {
                return;
            }

            IsAlive.PreScan();
            Time.PreScan();
            Kills.PreScan();
            Gems.PreScan();
            ShotsFired.PreScan();
            ShotsHit.PreScan();

            if (IsAlive.Value)
            {
                EnemiesAlive.PreScan();
            }

            if (!IsAlive.Value)
            {
                DeathType.PreScan();
            }
        }
Beispiel #12
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = IsAlive.GetHashCode();
         hashCode = (hashCode * 397) ^ Y;
         hashCode = (hashCode * 397) ^ X;
         return(hashCode);
     }
 }
Beispiel #13
0
 public BlockchainApi(string url = null)
 {
     BaseUrl       = url;
     _Address      = new Address(BaseUrl);
     _Assets       = new Assets(BaseUrl);
     _Balances     = new Balances(BaseUrl);
     _IsAlive      = new IsAlive(BaseUrl);
     _Operations   = new Operations(BaseUrl);
     _Capabilities = new Capabilities(BaseUrl);
     _Testing      = new Testing(BaseUrl);
     _Constants    = new Constants(BaseUrl);
 }
Beispiel #14
0
 public static async Task Aggregator(
     // blinker
     FPGA.OutputSignal <bool> LED1,
     FPGA.OutputSignal <bool> LED2,
     FPGA.OutputSignal <bool> LED3,
     FPGA.OutputSignal <bool> LED4
     )
 {
     IsAlive.Blink(LED1);
     IsAlive.Blink(LED2);
     IsAlive.Blink(LED3);
     IsAlive.Blink(LED4);
 }
Beispiel #15
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = base.GetHashCode();
         hash = hash * 37 + Key.GetHashCode();
         hash = hash * 37 + (Url != null ? Url.GetHashCode() : 0);
         hash = hash * 37 + IsAlive.GetHashCode();
         hash = hash * 37 + State.GetHashCode();
         hash = hash * 37 + (Error != null ? Error.GetHashCode() : 0);
         return(hash);
     }
 }
Beispiel #16
0
 public async Task IsAlive()
 {
     var client = new JsonServiceClient(AcDomain.NodeHost.Nodes.ThisNode.Node.AnycmdApiAddress);
     var isAlive = new IsAlive
     {
         Version = "v1"
     };
     var response = await client.GetAsync(isAlive);
     Assert.IsTrue(response.IsAlive);
     isAlive.Version = "version2";
     response = await client.GetAsync(isAlive);
     Assert.IsFalse(response.IsAlive);
     Assert.IsTrue(Status.InvalidApiVersion.ToName() == response.ReasonPhrase, response.Description);
 }
Beispiel #17
0
    public Character Initialize <T>(UInt32 id, string name_) where T : Actor, new()
    {
        if (!isInitialized)
        {
            isInitialized = true;
            name          = name_;
            tag           = "Character";
            Actor         = new T();
            ID            = id;
            Instances[ID] = this;
            Animator      = GetComponent <Animator>();
            Collider      = GetComponent <Collider>();
            Rigidbody     = gameObject.AddComponent <Rigidbody>();
            ActionManager = gameObject.AddComponent <ActionManager>();

            ActionManager.Action(ActionType.Normal);

            statusCanvas = Instantiate(ObjectManager.StatusCanvas).GetComponent <StatusCanvas>().Initialize(this);

            HP.Pairwise().Subscribe(hp =>
            {
                if (hp.Previous <= 0 && hp.Current > 0)
                {
                    IsAlive.Value = true;
                }

                if (hp.Previous > 0 && hp.Current <= 0)
                {
                    IsAlive.Value = false;
                }
            });

            IsAlive.Subscribe(isAlive =>
            {
                if (isAlive)
                {
                    Animator.SetTrigger("Normal");
                }
                else
                {
                    Animator.SetTrigger("Death");
                }

                Collider.enabled = CanAct.Value = isAlive;
            });
        }

        return(this);
    }
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // keypad
            FPGA.OutputSignal <bool> K7,
            FPGA.OutputSignal <bool> K6,
            FPGA.OutputSignal <bool> K5,
            FPGA.OutputSignal <bool> K4,
            FPGA.InputSignal <bool> K3,
            FPGA.InputSignal <bool> K2,
            FPGA.InputSignal <bool> K1,
            FPGA.InputSignal <bool> K0,

            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,

            // WS2812
            FPGA.OutputSignal <bool> DOUT,

            // ADC
            FPGA.OutputSignal <bool> ADC1NCS,
            FPGA.OutputSignal <bool> ADC1SLCK,
            FPGA.OutputSignal <bool> ADC1DIN,
            FPGA.InputSignal <bool> ADC1DOUT,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);

            GameControlsState controlsState = new GameControlsState();

            IsAlive.Blink(LED1);

            Peripherals.GameControls(
                ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT,
                K7, K6, K5, K4, K3, K2, K1, K0,
                controlsState);

            SnakeControl(
                controlsState,
                DOUT, TXD);
        }
Beispiel #19
0
        public async Task IsAlive()
        {
            var client  = new JsonServiceClient(AcDomain.NodeHost.Nodes.ThisNode.Node.AnycmdApiAddress);
            var isAlive = new IsAlive
            {
                Version = "v1"
            };
            var response = await client.GetAsync(isAlive);

            Assert.IsTrue(response.IsAlive);
            isAlive.Version = "version2";
            response        = await client.GetAsync(isAlive);

            Assert.IsFalse(response.IsAlive);
            Assert.IsTrue(Status.InvalidApiVersion.ToName() == response.ReasonPhrase, response.Description);
        }
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,
            FPGA.OutputSignal <bool> LED2,

            // keypad
            FPGA.OutputSignal <bool> K7,
            FPGA.OutputSignal <bool> K6,
            FPGA.OutputSignal <bool> K5,
            FPGA.OutputSignal <bool> K4,
            FPGA.InputSignal <bool> K3,
            FPGA.InputSignal <bool> K2,
            FPGA.InputSignal <bool> K1,
            FPGA.InputSignal <bool> K0,

            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,

            // ADC
            FPGA.OutputSignal <bool> ADC1NCS,
            FPGA.OutputSignal <bool> ADC1SLCK,
            FPGA.OutputSignal <bool> ADC1DIN,
            FPGA.InputSignal <bool> ADC1DOUT,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            IsAlive.Blink(LED1);

            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);

            KeysDTO controlsState = new KeysDTO();

            Peripherals.Controls(
                ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT,
                K7, K6, K5, K4, K3, K2, K1, K0,
                ref controlsState);

            ConfigureReporting(controlsState, TXD, LED2);
        }
Beispiel #21
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD

            )
        {
            IsAlive.Blink(LED1);

            SnakeDBG   dbg     = new SnakeDBG();
            Sequential handler = () =>
            {
                dbg.C1++;
                JSON.SerializeToUART(ref dbg, TXD);
            };

            FPGA.Config.OnStartup(handler);
        }
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // keypad
            FPGA.OutputSignal <bool> K7,
            FPGA.OutputSignal <bool> K6,
            FPGA.OutputSignal <bool> K5,
            FPGA.OutputSignal <bool> K4,
            FPGA.InputSignal <bool> K3,
            FPGA.InputSignal <bool> K2,
            FPGA.InputSignal <bool> K1,
            FPGA.InputSignal <bool> K0,

            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,

            // WS2812
            FPGA.OutputSignal <bool> DOUT
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);

            IndicatorsControlsState controlsState = new IndicatorsControlsState();

            IsAlive.Blink(LED1);

            Peripherals.IndicatorsControls(
                K7, K6, K5, K4, K3, K2, K1, K0,
                controlsState);

            LEDControl(controlsState);

            IndicatorsControl(
                controlsState,
                DOUT);
        }
Beispiel #23
0
        public void Scan()
        {
            try
            {
                // Always scan these values.
                PlayerID.Scan();
                Username.Scan();

                // Always calculate the spawnset in menu or lobby.
                // Otherwise you can first normally load a spawnset to set the hash, exit and load an empty spawnset in the menu/lobby, then during playing the empty spawnset change it back to the same original spawnset and upload a cheated score.
                if (Time.Value == 0 && Time.ValuePrevious == 0)
                {
                    SpawnsetHash = CalculateCurrentSurvivalHash();
                }

                // Stop scanning if it is a replay.
                IsReplay.Scan();
                if (IsReplay.Value)
                {
                    return;
                }

                IsAlive.Scan();
                Time.Scan();
                Kills.Scan();
                Gems.Scan();
                ShotsFired.Scan();
                ShotsHit.Scan();

                if (IsAlive.Value)
                {
                    // Enemy count might increase on death, so only scan while player is alive.
                    EnemiesAlive.Scan();

                    // TODO: Clean up
                    byte[] bytes = Memory.Read(Process.MainModule.BaseAddress + 0x001F8084, 4, out _);
                    int    ptr   = AddressUtils.ToDec(AddressUtils.MakeAddress(bytes));
                    bytes     = Memory.Read(new IntPtr(ptr), 4, out _);
                    ptr       = AddressUtils.ToDec(AddressUtils.MakeAddress(bytes));
                    bytes     = Memory.Read(new IntPtr(ptr) + 0x218, 4, out _);
                    LevelGems = BitConverter.ToInt32(bytes, 0);

                    bytes  = Memory.Read(new IntPtr(ptr) + 0x224, 4, out _);
                    Homing = BitConverter.ToInt32(bytes, 0);
                    HomingLog.Add(Homing);
                    if (HomingLog.Count > 5)
                    {
                        HomingLog.Remove(HomingLog[0]);
                    }

                    if (LevelUpTimes[0] == 0 && LevelGems >= 10 && LevelGems < 70)
                    {
                        LevelUpTimes[0] = Time.Value;
                    }
                    if (LevelUpTimes[1] == 0 && LevelGems == 70)
                    {
                        LevelUpTimes[1] = Time.Value;
                    }
                    if (LevelUpTimes[2] == 0 && LevelGems == 71)
                    {
                        LevelUpTimes[2] = Time.Value;
                    }
                }
                else
                {
                    // Only scan death type when dead.
                    DeathType.Scan();
                }

                if (string.IsNullOrEmpty(SpawnsetHash))
                {
                    SpawnsetHash = CalculateCurrentSurvivalHash();
                }
            }
            catch (Exception ex)
            {
                Logging.Log.Error("Scan failed", ex);
            }
        }
Beispiel #24
0
 public bool Equals(Cell otherCell)
 {
     return(IsAlive.Equals(otherCell.IsAlive) && PositionX.Equals(otherCell.PositionX) && PositionY.Equals(otherCell.PositionY));
 }
Beispiel #25
0
 public override string ToString()
 {
     return("{IsAlive:" + IsAlive.ToString() + ",PositionX:" + PositionX.ToString() + ",PositionY:" + PositionY.ToString() + "}");
 }
Beispiel #26
0
        public static async Task Aggregator(
            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,

            // blinker
            FPGA.OutputSignal <bool> LED1,
            FPGA.OutputSignal <bool> LED2,
            FPGA.OutputSignal <bool> LED3,
            FPGA.OutputSignal <bool> LED4,

            // WS2812
            FPGA.OutputSignal <bool> DOUT,

            // keypad
            FPGA.OutputSignal <bool> K7,
            FPGA.OutputSignal <bool> K6,
            FPGA.OutputSignal <bool> K5,
            FPGA.OutputSignal <bool> K4,
            FPGA.InputSignal <bool> K3,
            FPGA.InputSignal <bool> K2,
            FPGA.InputSignal <bool> K1,
            FPGA.InputSignal <bool> K0,

            // ADC
            FPGA.OutputSignal <bool> ADC1NCS,
            FPGA.OutputSignal <bool> ADC1SLCK,
            FPGA.OutputSignal <bool> ADC1DIN,
            FPGA.InputSignal <bool> ADC1DOUT,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD

            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);

            GameControlsState controlsState = new GameControlsState();

            IsAlive.Blink(LED1);

            IsAlive.Blink(LED2);
            IsAlive.Blink(LED3);
            IsAlive.Blink(LED4);

            Peripherals.GameControls(
                ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT,
                K7, K6, K5, K4, K3, K2, K1, K0,
                controlsState);

            LEDControl(controlsState.keyCode, DOUT);

            byte       data    = 0;
            Sequential handler = () =>
            {
                UART.Write(115200, data, TXD);
                data++;
            };

            FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler);
        }
Beispiel #27
0
 public override bool Equals(object obj)
 {
     return(obj is Cell other && (X.Equals(other.X) && Y.Equals(other.Y) && IsAlive.Equals(other.IsAlive)));
 }
Beispiel #28
0
        void Awake()
        {
            _currentPlayerParameter = new ReactiveProperty <PlayerParameters>(DefaultPlayerParameter);

            cameraMultiTarget = GetComponent <CameraMultiTargetObjective>();

            _onInitializeAsyncSubject.Subscribe(_ =>
            {
                IsAlive.Where(x => x).Skip(1)
                .Subscribe(__ =>
                {
                    //生き返ったら座標を書き換える

                    var p = _respawnPoints[UnityEngine.Random.Range(0, _respawnPoints.Length)];
                    transform.position = p;
                });

                //画面外に出たら死ぬ
                this.ObserveEveryValueChanged(x => x.transform.position.y)
                .Where(x => x < -3 && this.IsAlive.Value)
                .Subscribe(__ => Kill(NonPlayerAttacker.Default))
                .AddTo(this);

                //ダメージを受けたら誰からのダメージか記憶する
                OnDamaged
                .Do(x => _lastDamagedAttacker = x.Attacker)
                .Throttle(TimeSpan.FromSeconds(3))
                .Subscribe(__ => _lastDamagedAttacker = null);

                IsAlive.Subscribe(x => cameraMultiTarget.EnableTracking = x);

                //死んだ
                OnDead
                .Subscribe(__ =>
                {
                    //死んだら4秒後に復活
                    Observable.Timer(TimeSpan.FromSeconds(2))
                    .Subscribe(___ => _isAlive.Value = true);
                });

                this.OnTriggerEnterAsObservable()
                .Where(__ => IsAlive.Value)
                .Subscribe(x =>
                {
                    var i = x.GetComponent <ItemBase>();
                    if (i != null)
                    {
                        _pickUpItemSubject.OnNext(i.ItemEffect);
                        i.PickedUp();
                    }
                });

                this.OnTriggerEnterAsObservable()
                .Where(__ => IsAlive.Value)
                .Subscribe(x =>
                {
                    var i = x.GetComponent <ItemBase>();
                    if (i != null)
                    {
                        _pickUpItemSubject.OnNext(i.ItemEffect);
                        i.PickedUp();
                    }
                });
            });
        }
Beispiel #29
0
 public void setAlive(bool alive)
 {
     IsAlive.Equals(alive);
 }
Beispiel #30
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // IO banks for Quokka board, not needed for another boards
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,
            FPGA.OutputSignal <bool> Bank5,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);
            QuokkaBoard.OutputBank(Bank5);
            IsAlive.Blink(LED1);

            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            const int servosCount = 3;

            byte[] servosData = new byte[servosCount];

            Sequential servoHandler = () =>
            {
                uint instanceId     = FPGA.Config.InstanceId();
                var  servoOutputPin = new FPGA.OutputSignal <bool>();
                byte value          = 0;
                bool servoOutput    = false;
                byte requestValue   = 0;

                FPGA.Config.Link(servoOutput, servoOutputPin);

                while (true)
                {
                    requestValue = servosData[instanceId];

                    if (requestValue != value)
                    {
                        if (requestValue < value)
                        {
                            value--;
                        }
                        else
                        {
                            value++;
                        }
                    }

                    MG996R.Write(value, out servoOutput);
                }
            };

            FPGA.Config.OnStartup(servoHandler, servosCount);

            Sequential readHandler = () =>
            {
                byte counter = 0;
                byte step    = 5;
                while (true)
                {
                    while (counter < 180)
                    {
                        servosData[0] = counter;
                        servosData[1] = counter;
                        servosData[2] = counter;
                        counter      += step;
                        FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(100));
                    }

                    while (counter > 0)
                    {
                        servosData[0] = counter;
                        servosData[1] = counter;
                        servosData[2] = counter;
                        counter      -= step;
                        FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(100));
                    }
                }
            };

            FPGA.Config.OnStartup(readHandler);
        }
Beispiel #31
0
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // banks
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,
            FPGA.OutputSignal <bool> Bank5,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);
            QuokkaBoard.OutputBank(Bank5);
            IsAlive.Blink(LED1);

            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            const int servosCount = 3;

            byte[] servosData = new byte[servosCount];

            Sequential servoHandler = () =>
            {
                uint instanceId     = FPGA.Config.InstanceId();
                var  servoOutputPin = new FPGA.OutputSignal <bool>();
                byte value          = 0;
                bool servoOutput    = false;
                byte requestValue   = 0;

                FPGA.Config.Link(servoOutput, servoOutputPin);

                while (true)
                {
                    requestValue = servosData[instanceId];

                    if (requestValue != value)
                    {
                        if (requestValue < value)
                        {
                            value--;
                        }
                        else
                        {
                            value++;
                        }
                    }

                    MG996R.Write(value, out servoOutput);
                }
            };

            FPGA.Config.OnStartup(servoHandler, servosCount);

            Sequential readHandler = () =>
            {
                byte data    = 0;
                byte counter = 0;
                while (true)
                {
                    data = UART.Read(115200, RXD);
                    if (data == 255 || counter == 255)
                    {
                        // begin of packet or overflow
                        counter = 0;
                    }
                    else
                    {
                        if (counter < servosCount)
                        {
                            servosData[counter] = data;
                        }

                        counter++;
                    }
                }
            };

            FPGA.Config.OnStartup(readHandler);
        }
        public static async Task Aggregator(
            // blinker
            FPGA.OutputSignal <bool> LED1,

            // IO banks for Quokka board, not needed for another boards
            FPGA.OutputSignal <bool> Bank1,
            FPGA.OutputSignal <bool> Bank2,
            FPGA.OutputSignal <bool> Bank5,

            // ADC
            FPGA.OutputSignal <bool> ADC1NCS,
            FPGA.OutputSignal <bool> ADC1SLCK,
            FPGA.OutputSignal <bool> ADC1DIN,
            FPGA.InputSignal <bool> ADC1DOUT,

            // UART
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            QuokkaBoard.OutputBank(Bank1);
            QuokkaBoard.InputBank(Bank2);
            QuokkaBoard.OutputBank(Bank5);
            IsAlive.Blink(LED1);

            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            const int servosCount = 4;

            byte[] servosData = new byte[servosCount]
            {
                90, // main panel starts lookup up
                90, // main panel starts lookup up
                50, // sensor panel starts at beginning of measurement cycle
                50, // sensor panel starts at beginning of measurement cycle
            };
            object servosLock = new object();
            bool   autoScan   = true;

            Sequential servoHandler = () =>
            {
                uint instanceId     = FPGA.Config.InstanceId();
                var  servoOutputPin = new FPGA.OutputSignal <bool>();
                byte value          = 0;
                bool servoOutput    = false;
                byte requestValue   = 0;

                FPGA.Config.Link(servoOutput, servoOutputPin);

                while (true)
                {
                    requestValue = servosData[instanceId];

                    if (FPGA.Config.InstanceId() <= 1)
                    {
                        // large panel moves with smoothing
                        if (requestValue != value)
                        {
                            if (requestValue < value)
                            {
                                value--;
                            }
                            else
                            {
                                value++;
                            }
                        }
                    }
                    else
                    {
                        value = requestValue;
                    }

                    MG996R.Write(value, out servoOutput);
                }
            };

            FPGA.Config.OnStartup(servoHandler, servosCount);

            Sequential autoScanHandler = () =>
            {
                while (true)
                {
                    if (!autoScan)
                    {
                        continue;
                    }

                    byte   s2Delta = 5;
                    sbyte  s3Delta = 5;
                    ushort maxChannel1Value = 0;
                    byte   s2Max = 0, s3Max = 0;

                    // reset sensor panel to center
                    for (byte i = 2; i < servosCount; i++)
                    {
                        servosData[i] = 90;
                    }
                    FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(50));

                    byte s3 = 50;

                    for (byte s2 = 50; s2 <= 130; s2 += s2Delta)
                    {
                        servosData[2] = s2;
                        while (s3 >= 50 && s3 <= 130)
                        {
                            servosData[3] = s3;

                            // TODO: barrier sync all servo handlers
                            FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(50));

                            ushort adcChannel1Value = 0, adcChannel2Value = 0;
                            ADC102S021.Read(out adcChannel1Value, out adcChannel2Value, ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT);

                            if (adcChannel1Value > maxChannel1Value)
                            {
                                s2Max            = s2;
                                s3Max            = s3;
                                maxChannel1Value = adcChannel1Value;

                                byte[] buff = new byte[3];
                                byte   tmp;
                                buff[0] = 255;
                                buff[1] = s2Max;
                                buff[2] = s3Max;

                                for (byte i = 0; i < buff.Length; i++)
                                {
                                    tmp = buff[i];
                                    UART.Write(115200, tmp, internalTXD);
                                }
                            }

                            s3 = (byte)(s3 + s3Delta);
                        }
                        s3Delta = (sbyte)(-s3Delta);
                        s3      = (byte)(s3 + s3Delta); // compensate for overshoot
                    }

                    servosData[1] = (byte)(180 - s2Max); // should be mirrored around 90 as servo is backwards
                    servosData[0] = s3Max;               // same value

                    FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(1000));
                }
            };

            FPGA.Config.OnStartup(autoScanHandler);

            SetServos request = new SetServos();

            FPGA.Signal <bool> requestDeserialized = new FPGA.Signal <bool>();
            JSON.DeserializeFromUART <SetServos>(ref request, RXD, requestDeserialized);

            Sequential onRequest = () =>
            {
                autoScan      = request.autoRun == 0 ? false : true;
                servosData[0] = request.s0;
                servosData[1] = request.s1;
                servosData[2] = request.s2;
                servosData[3] = request.s3;
            };

            FPGA.Config.OnSignal(requestDeserialized, onRequest);
        }