コード例 #1
0
        //*****************************************************************************************

        //-----------------------------------------------------------------------------------------
        #endregion
        //*****************************************************************************************

        //*****************************************************************************************
        /// <summary>
        /// Initialise le bus de communication avec la carte de gestion de l'heure.
        /// </summary>
        //-----------------------------------------------------------------------------------------
        public static async Task <bool> Initialize()
        {
            //-------------------------------------------------------------------------------------
            ConnectionTick.Snapshot();

            if (!Initializing && I2cCardDevice == null && !DevicePresenceException)
            {
                //---------------------------------------------------------------------------------
                Initializing = true;
                //---------------------------------------------------------------------------------

                //---------------------------------------------------------------------------------
                try
                {
                    //-----------------------------------------------------------------------------
                    var QuerySyntaxString = I2cDevice.GetDeviceSelector("I2C1");

                    var DeviceIds = await DeviceInformation.FindAllAsync(QuerySyntaxString);

                    I2cConnectionSettings ConnSettings = new I2cConnectionSettings(0x68);

                    ConnSettings.BusSpeed    = I2cBusSpeed.FastMode;
                    ConnSettings.SharingMode = I2cSharingMode.Shared;

                    I2cCardDevice = await I2cDevice.FromIdAsync(DeviceIds[0].Id, ConnSettings);

                    ReadTime();
                    //-----------------------------------------------------------------------------
                }
                //---------------------------------------------------------------------------------
                catch (FileNotFoundException)
                { I2cCardDevice = null; DevicePresenceException = true; }
                //---------------------------------------------------------------------------------
                catch { }
                //---------------------------------------------------------------------------------
                finally { Initializing = false; }
                //---------------------------------------------------------------------------------
            }
            //-------------------------------------------------------------------------------------

            //-------------------------------------------------------------------------------------
            return(true);
            //-------------------------------------------------------------------------------------
        }
コード例 #2
0
        private static void LogNewConnection(int connId, int originFrameId, int frameCount, out ConnectionTick offsets)
        {
            int currentFrame = NetMaster.CurrentFrameId;

            /// Apply default offset from current local frame
            int startingFrameId = currentFrame + (SimpleSyncSettings.TargetBufferSize /*+ 1*/);

            while (startingFrameId >= frameCount)
            {
                startingFrameId -= frameCount;
            }

            int originToLocal = startingFrameId - originFrameId;

            if (originToLocal < 0)
            {
                originToLocal += frameCount;
            }

            int localToOrigin = frameCount - originToLocal;

            if (localToOrigin < 0)
            {
                localToOrigin += frameCount;
            }

            /// Curently local and origin are the same.
            /// TODO: Pool these
            offsets = new ConnectionTick(originToLocal, localToOrigin);

            perConnOffsets.Add(connId, offsets);
            connections.Add(connId);

            /// Add this connection to the NetSends list of targets for a reliable update.
            NetMsgSends.reliableTargets.Add(connId);
            needToSendInitialForNewConn = true;
        }