Exemplo n.º 1
0
        private void UpdateUserSetting(bool powerOnFlag, bool powerOffFlag, UserSetting newSetting)
        {
            switch (state)
            {
            case OperatingState.STATE_OFF:
                if (powerOnFlag)
                {
                    state = OperatingState.STATE_POWERING_UP;
                }

                break;

            case OperatingState.STATE_POWERING_UP:
                if (CheckSettingConsistency(newSetting))
                {
                    cmdQueue.Enqueue(POWER_ON_CMD);
                }

                if (receivedSetting.On)
                {
                    state = OperatingState.STATE_ON;
                }

                break;

            case OperatingState.STATE_ON:
                if (powerOffFlag)
                {
                    cmdQueue.Enqueue(POWER_OFF_CMD);
                }

                if (!receivedSetting.On)
                {
                    state = OperatingState.STATE_OFF;
                }

                break;
            }

            if (newSetting.PowerLevel != userSetting.PowerLevel)
            {
                cmdQueue.Enqueue(PowerLevelCmd(newSetting.PowerLevel));
                userSetting.PowerLevel = newSetting.PowerLevel;
            }

            if (newSetting.DutyCycle != userSetting.DutyCycle)
            {
                cmdQueue.Enqueue(DutyCycleCmd(newSetting.DutyCycle));
                userSetting.DutyCycle = newSetting.DutyCycle;
            }

            if (newSetting.PulseTime != userSetting.PulseTime)
            {
                cmdQueue.Enqueue(PulseTimeCmd(newSetting.PulseTime));
                userSetting.PulseTime = newSetting.PulseTime;
            }

            if (newSetting.PulseSpacing != userSetting.PulseSpacing)
            {
                cmdQueue.Enqueue(PulseSpacingCmd(newSetting.PulseSpacing));
                userSetting.PulseSpacing = newSetting.PulseSpacing;
            }
        }
Exemplo n.º 2
0
 private bool CheckSettingConsistency(UserSetting other)
 {
     return(receivedSetting.PowerLevel == other.PowerLevel && receivedSetting.DutyCycle == other.DutyCycle &&
            receivedSetting.PulseTime == other.PulseTime && receivedSetting.PulseSpacing == other.PulseSpacing);
 }