示例#1
0
    public static void LogPowerState()
    {
        int            secs, pct;
        SDL_PowerState state = SDL_GetPowerInfo(out secs, out pct);

        Debug.Log(state + " (" + pct + "%) With " + secs + " Seconds Remaining !");
    }
        /// <summary>
        /// Updates the service's cached state values.
        /// </summary>
        private unsafe void UpdateCache()
        {
            var now = DateTime.UtcNow;
            if ((now - lastCacheUpdate).TotalSeconds > 1.0)
            {
                int sdlPct;

                this.sdlPowerState = SDL.GetPowerInfo(null, &sdlPct);
                this.pct = sdlPct;

                switch (sdlPowerState)
                {
                    case SDL_PowerState.UNKNOWN:
                    case SDL_PowerState.NO_BATTERY:
                        this.isBatteryPowered = false;
                        this.isPluggedIn = false;
                        break;

                    case SDL_PowerState.ON_BATTERY:
                        this.isBatteryPowered = true;
                        this.isPluggedIn = false;
                        break;

                    case SDL_PowerState.CHARGING:
                    case SDL_PowerState.CHARGED:
                        this.isBatteryPowered = true;
                        this.isPluggedIn = true;
                        break;
                }

                this.lastCacheUpdate = now;
            }
        }