예제 #1
0
        public override ActionBase InitAll()
        {
            var by = IMask.Gen(0);

            foreach (var ent in Injector.Entercloses)
            {
                by[ent.Index] = (int)ent.YZero;
            }
            var inject_list = Injector.Entercloses.Where(item => item.InjEnable).ToList();
            var act         = Sequence.create(InitXyz.create(this, 30000, inject_list.ToArray(), false, false, true));

            act.AddAction(InitXyz.create(this, 30000, inject_list.ToArray(), true, true, false, by));


            var device = new ActionDevice(this);
            int x      = 0;

            int[]  y = new int[4];
            int [] z = new int [4];
            device.GetRealX(ref x);
            device.GetRealY(inject_list.ToArray(), ref y);
            device.GetRealZ(inject_list.ToArray(), ref z);
            Injector.XMotor.CurrentDistance = x;
            for (int i = 0; i < inject_list.Count(); i++)
            {
                inject_list[i].YMotor.CurrentDistance = y[i] + (int)inject_list[i].TipDis;
                inject_list[i].ZMotor.CurrentDistance = z[i];
            }
            return(act);
        }
        public async Task <IActionResult> Get(int actionDeviceId)
        {
            ActionDevice actionDevice = await _repository.FindAsync(actionDeviceId);

            if (actionDevice == null)
            {
                return(NotFound(actionDeviceId));
            }
            else
            {
                return(Ok(_mapper.Map <ActionDeviceViewModel>(actionDevice)));
            }
        }
예제 #3
0
        /// <summary>
        /// Extends the input to a device input if not already done
        /// </summary>
        /// <param name="input">An input</param>
        /// <param name="aDevice">The ActionDevice</param>
        /// <returns>A valid devInput (dev_input) format</returns>
        static public String DevInput(string input, ActionDevice aDevice)
        {
            switch (aDevice)
            {
            case ActionDevice.AD_Gamepad: return(GamepadCls.DevInput(input));

            case ActionDevice.AD_Joystick: return(JoystickCls.DevInput(input));

            case ActionDevice.AD_Keyboard: return(KeyboardCls.DevInput(input));

            case ActionDevice.AD_Mouse: return(MouseCls.DevInput(input));

            default: return(input);
            }
        }
        public async Task <IActionResult> Delete(int actionDeviceId)
        {
            ActionDevice actionDevice = await _repository.FindAsync(actionDeviceId);

            if (actionDevice == null)
            {
                return(NotFound(actionDeviceId));
            }
            ActionDeviceViewModel actionDeviceVM = _mapper.Map <ActionDeviceViewModel>(actionDevice);

            _repository.Delete(actionDevice);
            await _unitOfWork.SaveChangesAsync();

            return(Ok(actionDeviceVM));
        }
예제 #5
0
        /// <summary>
        /// 移动Y
        /// </summary>
        public void MoveY()
        {
            var move_act = Sequence.create();
            var device   = new ActionDevice(injectorDevice);

            move_act.AddAction(InjectMoveTo.create(10000, injectorDevice.GetSeleteced(), -1, IMask.Gen(-1), IMask.Gen(0)));
            int    x         = 0;
            int    y         = (int)DistanceY;
            double min_width = 1.0f;
            var    points    = IMask.Gen(new ActionPoint(-1, -1, -1));

            if (device.GetRealX(ref x))
            {
                var   ens = injectorDevice.Injector.Entercloses;
                int[] py  = { 0, (int)(ens[1].TipDis), (int)(ens[2].TipDis + ens[2].InjWidth), (int)(ens[3].TipDis + ens[3].InjWidth) };
                foreach (var ent in injectorDevice.GetSeleteced())
                {
                    points[ent.Index].x        = x;
                    points[ent.Index].y        = y + py[ent.Index];
                    points[ent.Index].minwidth = min_width;
                }
                move_act.AddAction(InjectMoveActs.create(3001, points.ToArray(), true));
                move_act.runAction(injectorDevice);
            }
            //var canComm = IoC.Get<AbstractCanComm>();
            //var injects = injectorDevice.GetSeleteced();
            //if(IsUseTMotor)
            //{
            //    var act = InjectMoveTo.create(5001, injects.ToArray(), -1, IMask.Gen((int)DistanceY), IMask.Gen(0), 2);
            //    act.runAction(injectorDevice);
            //}
            //else
            //{
            //    var points = IMask.Gen(new ActionPoint(-1, -1, -1));
            //    var device = new ActionDevice(injectorDevice);
            //    int x = 0;
            //    if(device.GetRealX(ref x))
            //    {
            //        var min_index = injects.Min(et => et.Index);
            //        points[min_index].x = x;
            //        points[min_index].y = (int)DistanceY;
            //        points[min_index].minwidth = 1.0f;
            //        var act = InjectMoveActs.create(3001, points.ToArray(), true);
            //        act.runAction(injectorDevice);
            //    }
            //}
        }
예제 #6
0
파일: Act.cs 프로젝트: phizch/SCJMapper-V2
        /// <summary>
        /// Return the color of a device
        /// </summary>
        /// <param name="devInput">The devinput (determine JS colors)</param>
        /// <param name="aDevice">The ActionDevice</param>
        /// <returns>The device color</returns>
        static public System.Drawing.Color DeviceColor(string devInput)
        {
            // background is along the input
            ActionDevice aDevice = ADeviceFromInput(devInput);

            switch (aDevice)
            {
            case ActionDevice.AD_Gamepad: return(GamepadCls.XiColor( ));

            case ActionDevice.AD_Joystick: return(JoystickCls.JsNColor(JoystickCls.JSNum(devInput)));// need to know which JS

            case ActionDevice.AD_Keyboard: return(KeyboardCls.KbdColor( ));

            case ActionDevice.AD_Mouse: return(MouseCls.MouseColor( ));

            default: return(MyColors.UnassignedColor);
            }
        }
        public async Task <IActionResult> PutState(int actionDeviceId, [FromBody] ActionDeviceStates state)
        {
            ActionDevice actionDevice = await _repository.FindAsync(actionDeviceId);

            if (actionDevice == null)
            {
                return(NotFound(actionDeviceId));
            }
            dynamic parameters = JObject.Parse(actionDevice.Parameters);

            switch (actionDevice.Type)
            {
            case ActionDeviceTypes.iHome:

                string id = parameters.id;
                using (HttpClient client = new HttpClient())
                {
                    using HttpRequestMessage request = new HttpRequestMessage();
                    string json = "[{\"value\":\"" + state + "\"}]";
                    request.RequestUri = new Uri($"https://api.evrythng.com/thngs/{id}/properties/targetpowerstate1", UriKind.RelativeOrAbsolute);
                    request.Method     = HttpMethod.Put;
                    request.Content    = new StringContent(json);
                    request.Content.Headers.ContentType   = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
                    request.Content.Headers.ContentLength = json.Length;
                    request.Content.Headers.Add("Authorization", "z8RdfbcZfXDiIxxilVmiqg4fMr154fVoxKTor2V7CDWkOP7iiSjf7NPb9Qq8siLaXmxtJOmbeVbQw1GZ");
                    request.Content.Headers.Add("Accept", "application/json");
                    await client.SendAsync(request);
                }
                break;

            case ActionDeviceTypes.WiFi:
                string url = parameters.url + state;
                using (HttpClient client = new HttpClient())
                {
                    using HttpRequestMessage request = new HttpRequestMessage();
                    request.RequestUri = new Uri(url, UriKind.RelativeOrAbsolute);
                    request.Method     = HttpMethod.Get;
                    await client.SendAsync(request);
                }
                break;
            }

            return(NoContent());
        }
예제 #8
0
        public override ActionBase InitAll()
        {
            InitHandTongs();
            var act = Sequence.create(InitXyz.create(this, 30000, false, false, true));

            act.AddAction(InitXyz.create(this, 30000, true, true, false));
            var device = new ActionDevice(this);
            int x      = 0;
            int y      = 0;
            int z      = 0;

            device.GetRealX(ref x);
            device.GetRealY(ref y);
            device.GetRealZ(ref z);
            Hand.XMotor.CurrentDistance = x;
            Hand.YMotor.CurrentDistance = y;
            Hand.ZMotor.CurrentDistance = z;
            return(act);
        }
        public async Task <IActionResult> Post([FromBody] ActionDeviceViewModel actionDeviceVM)
        {
            if (ModelState.IsValid)
            {
                if (actionDeviceVM == null)
                {
                    return(BadRequest($"{nameof(actionDeviceVM)} cannot be null"));
                }
                ActionDevice actionDevice = _mapper.Map <ActionDevice>(actionDeviceVM);
                EntityEntry <ActionDevice> addedActionDevice = await _repository.InsertAsync(actionDevice);

                await _unitOfWork.SaveChangesAsync();

                actionDeviceVM = _mapper.Map <ActionDeviceViewModel>(addedActionDevice.Entity);
                return(CreatedAtAction("GetByActionDeviceId", new { actionDeviceId = actionDeviceVM.ActionDeviceId }, actionDeviceVM));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
예제 #10
0
        //得到恢复当前状态的动作
        public bool GetReSetAct(ref Sequence seque_act)
        {
            int x = 0;

            int [] y           = IMask.Gen(-1);
            int[]  z           = IMask.Gen(-1);
            var    device      = new ActionDevice(this);
            var    inject_list = Injector.Entercloses.Where(item => item.InjEnable).ToList();
            bool   ret         = device.GetRealX(ref x);

            ret = ret && device.GetRealY(inject_list.ToArray(), ref y);
            ret = ret && device.GetRealZ(inject_list.ToArray(), ref z);
            for (int i = 0; i < inject_list.Count; i++)
            {
                y[inject_list[i].Index] += (int)inject_list[i].TipDis;
            }
            seque_act.AddAction(InjectMoveTo.create(3000, inject_list.ToArray(), -1, IMask.Gen(-1), IMask.Gen(0)));
            seque_act.AddAction(InjectMoveTo.create(3000, inject_list.ToArray(), x, y, IMask.Gen(-1)));
            seque_act.AddAction(InjectMoveTo.create(3000, inject_list.ToArray(), -1, IMask.Gen(-1), z));
            return(ret);
        }
예제 #11
0
        /// <summary>
        /// Blend the input using the device specific format of the input is generic Blind
        /// </summary>
        /// <param name="input">An input (generic blend or a valid command)</param>
        /// <param name="aDevice">A valid device</param>
        /// <returns>A device blend or the original input if it was not a blend</returns>
        static public String BlendInput(String input, ActionDevice aDevice)
        {
            if (DeviceCls.IsBlendedInput(input))
            {
                // was generic blind
                switch (aDevice)
                {
                case ActionDevice.AD_Gamepad: return(GamepadCls.BlendedInput);

                case ActionDevice.AD_Joystick: return(JoystickCls.BlendedInput);

                case ActionDevice.AD_Keyboard: return(KeyboardCls.BlendedInput);

                case ActionDevice.AD_Mouse: return(MouseCls.BlendedInput);

                default: return("");
                }
            }
            else
            {
                return(input); // just return
            }
        }
예제 #12
0
파일: Act.cs 프로젝트: phizch/SCJMapper-V2
        /// <summary>
        /// Disable the input for a specific device - input is a generic Disabled Input
        /// </summary>
        /// <param name="input">An input (generic disable or a valid command)</param>
        /// <param name="aDevice">A valid device</param>
        /// <returns>A device diabled or the original input if it was not a disabled</returns>
        static public string DisableInput(string input, ActionDevice aDevice)
        {
            if (DeviceCls.IsDisabledInput(input))
            {
                // was generic blind - return a device specific disabled input
                switch (aDevice)
                {
                case ActionDevice.AD_Gamepad: return(GamepadCls.DisabledInput);

                case ActionDevice.AD_Joystick: return(JoystickCls.DisabledInput);

                case ActionDevice.AD_Keyboard: return(KeyboardCls.DisabledInput);

                case ActionDevice.AD_Mouse: return(MouseCls.DisabledInput);

                default: return("");
                }
            }
            else
            {
                return(input); // not disabled - just return the input
            }
        }
예제 #13
0
 /// <summary>
 /// Creates a new Action.
 /// </summary>
 /// <param name="validator">The validator to use for validation.</param>
 /// <param name="node">The "action" node.</param>
 internal Action(NodeValidator validator, Node node)
     : base(validator, node)
 {
     if (node.Attributes.ContainsKey(DEVICE_ATTRIBUTE))
     {
         device = ActionDeviceHelper.TryParse(node.Attributes[DEVICE_ATTRIBUTE]);
     }
     if (node.Attributes.ContainsKey(TIME_ATTRIBUTE))
     {
         time = ConversionHelper.ParseHexValue(node.Attributes[TIME_ATTRIBUTE]);
     }
     if (node.Attributes.ContainsKey(USAGE_ATTRIBUTE))
     {
         usage = (ActionKey)ConversionHelper.ParseHexValue(node.Attributes[USAGE_ATTRIBUTE]);
     }
     if (node.Attributes.ContainsKey(PAGE_ATTRIBUTE))
     {
         page = ConversionHelper.ParseHexValue(node.Attributes[PAGE_ATTRIBUTE]);
     }
     if (node.Attributes.ContainsKey(VALUE_ATTRIBUTE))
     {
         value = (ActionValue)ConversionHelper.ParseHexValue(node.Attributes[VALUE_ATTRIBUTE]);
     }
 }
예제 #14
0
 internal static string ToString(ActionDevice device)
 {
     return(device.ToString("G").ToLowerInvariant());
 }