예제 #1
0
        private IntPtr Main_Power_Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            // C# doesn't have definitions for power messages, so we'll get them via C++/CLI. It returns a
            // simple UInt16 that defines only the things we care about.
            var pmsg = PowerManagement.message(msg, wParam, lParam);

            if (pmsg == PowerManagementMessage.Suspend)
            {
                _mgr.suspend();
                handled = true;
            }
            else if (pmsg == PowerManagementMessage.Resume)
            {
                var vstate = _mgr.resume();

                if (vstate == ResumeVaultState.Locked)
                {
                    LockVault();
                }

                handled = true;
            }

            return(IntPtr.Zero);
        }
예제 #2
0
        private static bool TryGetDevice(uint index, out string result, QueryInterpretationFlags?flags = null)
        {
            uint size = 0;
            QueryInterpretationFlags targetFlags = flags ?? flagsAll;

            PowerManagement.DevicePowerEnumDevices(index, targetFlags, flagsQuery, IntPtr.Zero, ref size);

            if (size > 0)
            {
                var buffer = Marshal.AllocHGlobal((int)size);

                try
                {
                    if (PowerManagement.DevicePowerEnumDevices(index, targetFlags, flagsQuery, buffer, ref size) && buffer != IntPtr.Zero)
                    {
                        result = Marshal.PtrToStringUni(buffer);
                        return(true);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(buffer);
                }
            }

            result = null;
            return(false);
        }
예제 #3
0
        public void GetMessageVoltageRequestTest()
        {
            PowerManagementMessage message = PowerManagement.GetMessage("*#3*10*1*1##");

            Assert.AreEqual <WHAT>(message.What, WHAT.PowerManagementVoltageRequest);
            Assert.AreEqual <int>(message.Voltage, 1);
        }
예제 #4
0
        protected void CreatGridInitScript()
        {
            List <String>           n = new List <string>();
            List <jqGrid.colObject> m = new List <jqGrid.colObject>();

            //n.Add("程式名稱");
            m.Add(new jqGrid.colObject()
            {
                name = "prog", width = "180", sortable = false
            });

            PowerManagement pCollect = new PowerManagement(0);

            foreach (Power p in pCollect.Powers)
            {
                n.Add(p.name.ToString());
                m.Add(new jqGrid.colObject()
                {
                    name      = p.name.ToString(),
                    align     = "center",
                    resizable = false,
                    formatter = new funcMethodModule()
                    {
                        funcName = "$.fn.MakeCheckOBJ"
                    }
                });
            }

            //ViewData["array_ColNames"] = n.ToArray();
            ViewData["array_ColModel"] = m.ToArray();
        }
예제 #5
0
        public void Go()
        {
            // turn of Netduino devices that we don't need
            PowerManagement.SetPeripheralState(Peripheral.Ethernet, false);
            PowerManagement.SetPeripheralState(Peripheral.PowerLED, false);
            PowerManagement.SetPeripheralState(Peripheral.SDCard, false);

            // initalize the serial ports
            m_serialPort = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
            m_serialPort.Open();

            m_nmeaInputPort = new NmeaInputPort(m_serialPort);

            m_oled = new Newhaven25664OledDriver(
                chipSelect: Pins.GPIO_PIN_D10,
                reset: Pins.GPIO_PIN_D9,
                dc: Pins.GPIO_PIN_D8);
            m_oled.Initialize();
            m_oled.ClearDisplay();
            m_oled.TestPattern();
            Thread.Sleep(1000);
            m_oled.ClearDisplay();

            InputPort leftButton = new InputPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.PullUp);

            if (!leftButton.Read())
            {
                // debug mode
                //m_nmeaInputPort.RawDataDebugEvent += new NmeaInputDebugEventHandler(m_nmeaInputPort_RawDataDebugEvent);
                m_nmeaInputPort.ParsedDataDebugEvent += new NmeaInputParsedDebugEventHandler(m_nmeaInputPort_ParsedDataDebugEvent);
                m_debugFont = new OledFont(SailboatComputer.Properties.Resources.BinaryResources.fixed5x7);
                m_nmeaInputPort.Initialize();
                while (true)
                {
                    Thread.Sleep(Int16.MaxValue);
                }
            }
            else
            {
                leftButton.Dispose();
                leftButton = null;
                DebugLog.WriteLine("free memory (before fonts) = " + Microsoft.SPOT.Debug.GC(true));

                m_ui = new SimpleUserInterface(m_oled, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D6);

                DebugLog.WriteLine("free memory (after fonts) = " + Microsoft.SPOT.Debug.GC(true));

                // hook up NMEA events
                m_nmeaInputPort.WindEvent   += new NmeaWindEventHandler(m_nmeaInputPort_WindEvent);
                m_nmeaInputPort.COGSOGEvent += new NmeaCOGSOGEventHandler(m_nmeaInputPort_CogSogEvent);
                m_nmeaInputPort.DepthEvent  += new NmeaDepthEventHandler(m_nmeaInputPort_DepthEvent);
                m_nmeaInputPort.Initialize();

                while (true)
                {
                    Thread.Sleep(Int16.MaxValue);
                }
            }
        }
예제 #6
0
 void Start()
 {
     boxC        = GetComponent <BoxCollider2D>();
     _controller = new ControllerPlayer(this);
     _p          = new PowerManagement(this);
     new View(this);
     SpreadMode();
 }
예제 #7
0
        public void GetMessageAllDimensionsTest()
        {
            PowerManagementMessage message = PowerManagement.GetMessage("*#3*10*0*1*2*3*4##");

            Assert.AreEqual <WHAT>(message.What, WHAT.PowerManagementAllDimensionsRequest);
            Assert.AreEqual <int>(message.Voltage, 1);
            Assert.AreEqual <int>(message.Current, 2);
            Assert.AreEqual <int>(message.Power, 3);
            Assert.AreEqual <int>(message.Energy, 4);
        }
예제 #8
0
        private void InitiallizeCollections()
        {
            var schemes = PowerManagement.GetPowerSchemes();

            // Create clones of the list of schemes to use for charging, discharging, and active scheme menus
            PowerSchemes            = new ObservableCollection <PowerScheme>(schemes.Clone());
            DischargingPowerSchemes = new ObservableCollection <PowerScheme>(ActivateScheme(schemes.Clone(), Settings.Default.DischargingScheme));
            ChargingPowerSchemes    = new ObservableCollection <PowerScheme>(ActivateScheme(schemes.Clone(), Settings.Default.ChargingScheme));

            PowerActions = new ObservableCollection <PowerAction>(PowerAction.GetActions());
        }
예제 #9
0
 private void Awake()
 {
     PowerManager = FindObjectOfType <PowerManagement>();
     if (MaxPowerProduced > 0)
     {
         PowerManager.PowerProduced.Add(this);
     }
     else
     {
         PowerManager.RequiresPower.Add(this);
     }
 }
 private void removePowerToTilesFrom(int col, int row)
 {
     for (int i = 0; i < powerPositions.Count; ++i)
     {
         int xPos = powerPositions [i].x + col;
         int yPos = powerPositions [i].y + row;
         if (xPos >= 0 && xPos < StageScript.numCols && yPos >= 0 && yPos < StageScript.numRows)
         {
             PowerManagement.removePower(heroType, (uint)xPos, (uint)yPos);
         }
     }
 }
예제 #11
0
        public static void PreventSleep(Boolean includeDisplay)
        {
            PowerManagement.ExecutionState state
                = PowerManagement.ExecutionState.ES_SYSTEM_REQUIRED
                  | PowerManagement.ExecutionState.ES_CONTINUOUS;

            if (includeDisplay)
            {
                state |= PowerManagement.ExecutionState.ES_DISPLAY_REQUIRED;
            }

            PowerManagement.SetThreadExecutionState(state);
        }
예제 #12
0
        public static IReadOnlyList <PowerDevice> GetPowerDevices()
        {
            var result = new List <PowerDevice>();

            if (PowerManagement.DevicePowerOpen(0))
            {
                var wakeEnabledDevices      = GetWakeEnabledDevices();
                var wakeProgrammableDevices = GetWakeProgrammableDevices();
                var signedDrivers           = DriverUtility.GetSignedDrivers();

                try
                {
                    uint   index      = 0;
                    string lastDevice = null;
                    while (TryGetDevice(index, out lastDevice))
                    {
                        var driver = signedDrivers.Where(x => x.HardWareID == lastDevice).FirstOrDefault();

                        if (driver != null)
                        {
                            TryGetDevice(index, out string name, flagsAllName);

                            var powerDevice = new PowerDevice
                            {
                                ClassGuid          = driver.ClassGuid,
                                Description        = driver.Description,
                                DeviceID           = driver.DeviceID,
                                DeviceName         = driver.DeviceName,
                                FriendlyName       = driver.FriendlyName,
                                HardWareID         = driver.HardWareID,
                                IsWakeEnabled      = wakeEnabledDevices.Contains(driver.HardWareID),
                                IsWakeProgrammable = wakeProgrammableDevices.Contains(name),
                                Location           = driver.Location,
                                Manufacturer       = driver.Manufacturer,
                                Name = name
                            };

                            result.Add(powerDevice);
                        }

                        index++;
                    }
                }
                finally
                {
                    PowerManagement.DevicePowerClose();
                }
            }

            return(result);
        }
예제 #13
0
        private IntPtr Passwd_Power_Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            // C# doesn't have definitions for power messages, so we'll get them via C++/CLI. It returns a
            // simple UInt16 that defines only the things we care about.
            var pmsg = PowerManagement.message(msg, wParam, lParam);

            if (pmsg == PowerManagementMessage.Resume || pmsg == PowerManagementMessage.Suspend)
            {
                // Raise the Closing event which will close our window
                // Don't set handled because we want other windows to process this signal, too.
                _Close();
            }

            return(IntPtr.Zero);
        }
예제 #14
0
        private void OnPowerModeChanged(object sender, PowerModeChangedEventArgs args)
        {
            if (args.Mode != PowerModes.StatusChange)
            {
                return;
            }
            // Todo, base this only on charging/discharging? Or on percentage status?
            Guid id;
            var  message = string.Empty;

            switch (Forms.SystemInformation.PowerStatus.PowerLineStatus)
            {
            case Forms.PowerLineStatus.Online:
                id = Settings.Default.ChargingScheme;
                if (id != Guid.Empty)
                {
                    PowerManagement.SetActiveScheme(id);
                    message = String.Format("The power scheme has been automatically set to {0}", PowerManagement.ReadFriendlyName(id));
                }
                break;

            case Forms.PowerLineStatus.Offline:
                id = Settings.Default.DischargingScheme;
                if (id != Guid.Empty)
                {
                    PowerManagement.SetActiveScheme(id);
                    message = String.Format("The power scheme has been automatically set to {0}", PowerManagement.ReadFriendlyName(id));
                }
                break;

            case Forms.PowerLineStatus.Unknown:
                // todo, what does unknown indicate? How to best handle this case?
                message = "Unknown? Panic!";
                break;

            default:
                message = "Default? Hmmm";
                break;
            }
            NotifyVM.UpdateActiveScheme(PowerManagement.GetActiveScheme());
            NotifyIcon.ShowBalloonTip("QuickPower", message, BalloonIcon.Info);
        }
예제 #15
0
        private static IReadOnlyList <string> GetWakeEnabledDevices()
        {
            var result = new List <string>();

            if (PowerManagement.DevicePowerOpen(0))
            {
                try
                {
                    uint   index      = 0;
                    string lastDevice = null;
                    while (TryGetDevice(index, out lastDevice, flagsWakeEnabled))
                    {
                        result.Add(lastDevice);
                        index++;
                    }
                }
                finally
                {
                    PowerManagement.DevicePowerClose();
                }
            }

            return(result);
        }
예제 #16
0
        public virtual async Task InitiateAsync()
        {
            Settings.Initiate();
            Settings.KnownMonitors.AbsoluteCapacity = MaxKnownMonitorsCount;
            Settings.PropertyChanged += OnSettingsChanged;

            NotifyIconContainer.ShowIcon("pack://application:,,,/Monitorian.Core;component/Resources/Icons/TrayIcon.ico", ProductInfo.Title);

            _current.MainWindow              = new MainWindow(this);
            _current.MainWindow.Deactivated += (sender, e) => MonitorsResetByKey();

            if (StartupAgent.IsWindowShowExpected())
            {
                _current.MainWindow.Show();
            }

            if (Settings.MakesOperationLog)
            {
                _recorder = new OperationRecorder("Initiated");
            }

            await ScanAsync();

            StartupAgent.Requested += (sender, e) => e.Response = OnRequested(sender, e.Args);

            NotifyIconContainer.MouseLeftButtonClick  += OnMainWindowShowRequestedBySelf;
            NotifyIconContainer.MouseRightButtonClick += OnMenuWindowShowRequested;

            _displayWatcher.Subscribe(() => OnMonitorsChangeInferred(nameof(DisplayWatcher)));
            _powerWatcher.Subscribe((e) => OnMonitorsChangeInferred($"{nameof(PowerWatcher)} - {e.Mode}"), PowerManagement.GetOnPowerSettingChanged());
            _brightnessWatcher.Subscribe((instanceName, brightness) => Update(instanceName, brightness));
        }
예제 #17
0
        public void GetMessageLoadForcedTest()
        {
            PowerManagementMessage message = PowerManagement.GetMessage("*3*2*11##");

            Assert.AreEqual <WHAT>(message.What, WHAT.PowerManagementLoadForced);
        }
예제 #18
0
 /// <summary>
 /// Set the active power scheme to the provided Guid
 /// Behavior is undefined is arg is not Guid
 /// The case of an unchecked option is ignored, since having no active power scheme is invalid behavior
 /// </summary>
 /// <param name="arg"></param>
 private void ChangeActive(object arg)
 {
     PowerManagement.SetActiveScheme((Guid)arg);
 }
예제 #19
0
        protected void CreatGridInitScript()
        {
            List<String> n = new List<string>();
            List<jqGrid.colObject> m = new List<jqGrid.colObject>();

            //n.Add("程式名稱");
            m.Add(new jqGrid.colObject() { name = "prog", width = "180", sortable = false });

            PowerManagement pCollect = new PowerManagement(0);

            foreach (Power p in pCollect.Powers)
            {
                n.Add(p.name.ToString());
                m.Add(new jqGrid.colObject()
                {
                    name = p.name.ToString(),
                    align = "center",
                    resizable = false,
                    formatter = new funcMethodModule() { funcName = "$.fn.MakeCheckOBJ" }
                });
            }

            //ViewData["array_ColNames"] = n.ToArray();
            ViewData["array_ColModel"] = m.ToArray();
        }
 public override void PageLoaded(PageLoadedDirection direction)
 {
     base.PageLoaded(direction);
     labelRunningOnBattery.Visible = PowerManagement.CheckBatteryDischarging();
 }
예제 #21
0
 public static bool SetDeviceState(PowerDevice device, bool value)
 {
     return(PowerManagement.DevicePowerSetDeviceState(device.Name, value ? SetFlags.DEVICEPOWER_SET_WAKEENABLED : SetFlags.DEVICEPOWER_CLEAR_WAKEENABLED, IntPtr.Zero) == 0);
 }
 protected override void PageLoadedCore(PageLoadedDirection direction)
 {
     labelRunningOnBattery.Visible = PowerManagement.CheckBatteryDischarging();
 }
예제 #23
0
 private void Shutdown_Click(object sender, RoutedEventArgs e)
 {
     PowerManagement.Set(PowerAction.Hybernate);
 }
예제 #24
0
 private void Logout_Click(object sender, RoutedEventArgs e)
 {
     PowerManagement.Set(PowerAction.Logout);
 }
예제 #25
0
 private void Restart_Click(object sender, RoutedEventArgs e)
 {
     PowerManagement.Set(PowerAction.Restart);
 }
예제 #26
0
 public BaseFormFullMode()
 {
     InitializeComponent();
     this.powerManager = new PowerManagement();
 }
예제 #27
0
 private void Sleep_Click(object sender, RoutedEventArgs e)
 {
     PowerManagement.Set(PowerAction.Sleep);
 }
예제 #28
0
    override protected void Update()
    {
        if (paused)
        {
            return;
        }
        base.Update();

        if (isDragging || isOnBench)
        {
            if (isDragging)
            {
                anim.SetInteger("State", DRAGGING);
            }
            else if (isOnBench)
            {
                idle(false);
            }

            fireTimer = fireRatePerSecond;
            return;
        }

        bool enemyAhead = isEnemyAhead();

        idle(enemyAhead);

        if (enemyAhead)
        {
            List <HeroType> powerList = PowerManagement.getPowerList((uint)colPos, (uint)rowPos);

            fireTimer -= Time.deltaTime;

            bool quickShot = false;
            if (powerList.Contains(HeroType.SPEED_POWER_CONVERTER))
            {
                fireTimer -= Time.deltaTime;                 // subtract it again to double the speed
                quickShot  = true;
            }

            if (fireTimer <= 0.0f)
            {
                fireTimer = fireRatePerSecond;
                anim.SetInteger("State", SHOOT);
                StartCoroutine(waitToIdle());

                GameObject bullet;

                // The problem here is that it can be both heavy and ice
                // need to find a way to make this scale better
                if (powerList.Contains(HeroType.DAMAGE_POWER_CONVERTER))
                {
                    if (powerList.Contains(HeroType.ICE_POWER_CONVERTER))
                    {
                        bullet = fireHeavyIceBullet();
                    }
                    else
                    {
                        bullet = fireSniperBullet();
                    }
                }
                else if (powerList.Contains(HeroType.ICE_POWER_CONVERTER))
                {
                    bullet = fireIceBullet();
                }
                else
                {
                    bullet = fireSimpleBullet();
                }

                bullet.GetComponent <BulletScript> ().setWasQuickShot(quickShot);
            }

            return;
        }
    }