<template>
	<view class="content">	 
		<view class="text" >
			
            <text >自动模式</text> <switch style="transform:scale(0.7)" :checked="treatmentStatu.checked"  @change="switchChange" /> <text >手动模式 </text>  
			<button type="primary" class="button" @touchstart="AxisXReducePress()"  @touchend= "AxisXReduceRelease()" size="mini">X轴-</button>
		    <button type="primary" class="button" @touchstart="AxisXAddPress()"     @touchend= "AxisXAddRelease()"    size="mini">X轴+</button>
		</view>
		
		<view class="tex-box" >
			<text>X轴位置：</text> <text>{{AxisPositions_X}}</text>
		</view>

		<button type="primary" class="button"  @touchstart="StartUpPress()"       @touchend= "StartUpRelease()"     size="mini">启动</button>
		<button type="primary" class="button"  @touchstart="AxisYReducePress()"  @touchend= "AxisYReduceRelease()" size="mini">Y轴-</button>
		<button type="primary" class="button"  @touchstart="AxisYAddPress()"     @touchend= "AxisYAddRelease()"    size="mini">Y轴+</button>
		
		<view class="tex-box" >
			<text>Y轴位置：</text> <text>{{AxisPositions_Y}}</text>
		</view>
		
		<button type="primary" class="button"  @touchstart="StopPress()"          @touchend= "StopRelease()"        size="mini">停止</button>
		<button type="primary" class="button"  @touchstart="AxisZReducePress()"   @touchend= "AxisZReduceRelease()" size="mini">Z轴-</button>
		<button type="primary" class="button"  @touchstart="AxisZAddPress()"      @touchend= "AxisZAddRelease()"    size="mini">Z轴+</button>
		
		<view class="tex-box" >
			<text>Z轴位置：</text> <text>{{AxisPositions_Z}}</text>
		</view>
		
        <button type="primary" class="button"  @touchstart="ResetPress()"         @touchend= "ResetRelease()"         size="mini">复位</button>
		<button type="primary" class="button"  @touchstart="AxisRReducePress()"   @touchend= "AxisRReduceRelease()" size="mini">R轴-</button>
		<button type="primary" class="button"  @touchstart="AxisRAddPress()"      @touchend= "AxisRAddRelease()"    size="mini">R轴+</button>
		
		<view class="tex-box">
			<text>R轴位置：</text> <text>{{_self.AxisPositions_R}}</text>
		</view>
		<button type="primary" class="button"  @touchstart="StepBackZeroPress()"  @touchend= "StepBackZeroRelease()"  size="mini">步进回零</button>
		<button type="primary" class="button"  @touchstart="AxisROGReducePress()" @touchend= "AxisROGReduceRelease()" size="mini">ROG轴-</button>
		<button type="primary" class="button"  @touchstart="AxisROGAddPress()"    @touchend= "AxisROGAddRelease()"    size="mini">ROG轴+</button>
		
		<view class="propertyBox">
			<button type="primary" class="button"  @touchstart="PositionWritePress()" @touchend= "PositionWriteRelease()" size="mini">位置写入</button>	
			<view class="mytest">
				<text>位置写入值{{_self.StepWrite}}</text>
				<!-- <input   @input="onKeyInput" placeholder="位置写入的值"/> -->
				<input  type = "type" v-model=" StepWrite"  placeholder="位置写入的值" />
			</view>
			<button type="primary" class="button"  @touchstart="SingleStepPress()"    @touchend= "SingleStepRelease()"    size="mini">单步</button>
		</view>
					
		<button type="primary" class="button"  @touchstart ="CheckoutRisePress()"     @touchend= "CheckoutRiseRelease()"      size="mini">出签上升</button>
		<button type="primary" class="button"  @touchstart="CheckoutDropPress()"      @touchend= "CheckoutDropRelease()"      size="mini">出签下降</button>
		<button type="primary" class="button"  @touchstart="PowerOnPress()"           @touchend= "PowerOnRelease()"           size="mini">开机</button>
		<button type="primary" class="button"  @touchstart="ElectricDoorOpenPress()"  @touchend= "ElectricDoorOpenRelease()"  size="mini">电动门打开</button>
		<button type="primary" class="button"  @touchstart="ElectricDoorClosePress()" @touchend= "ElectricDoorCloseRelease()" size="mini">电动门关闭</button>
		<button type="primary" class="button"  @touchstart="ShutDownPress()"          @touchend= "ShutDownRelease()"          size="mini">关机</button>	
			
		<view class="tex-box"  >
			<text>当前位置：</text> <text>{{ _self.CurrentLocation }}</text>  
		</view>
		
		<button type="primary" class="button"  @touchstart="WaterPumpPress()"           @touchend= "WaterPumpRelease()"          size="mini">水泵</button>	
		<button type="primary" class="button"  @touchstart="FanPress()"                 @touchend= "FanRelease()"                size="mini">风机</button>
		<button type="primary" class="button"  @touchstart="SugarControlMotor1Press()"  @touchend= "SugarControlMotor1Release()" size="mini">1#糖电机</button>
		<button type="primary" class="button"  @touchstart="SugarControlMotor2Press()"  @touchend= "SugarControlMotor2Release()" size="mini">2#糖电机</button>
		<button type="primary" class="button"  @touchstart="SugarControlMotor3Press()"  @touchend= "SugarControlMotor3Release()" size="mini">3#糖电机</button>
		<button type="primary" class="button"  @touchstart="SugarControlMotor4Press()"  @touchend= "SugarControlMotor4Release()" size="mini">4#糖电机</button>
		<button type="primary" class="button"  @touchstart="SugarHeadStartPress()"      @touchend= "SugarHeadStartRelease()"     size="mini">糖头启动</button>
		<button type="primary" class="button"  @touchstart="SugarHeadStopPress()"       @touchend= "SugarHeadStopRelease()"      size="mini">糖头停止</button>
		<button type="primary" class="button"  @touchstart="HeatingStartPress()"        @touchend= "HeatingStartRelease()"       size="mini">加热启动</button>
		<button type="primary" class="button"  @touchstart="HeatingStopPress()"         @touchend= "HeatingStopRelease()"        size="mini">加热停止</button>
		<button type="primary" class="button"  @tap="MechanicalArm1"     size="mini">机械臂1</button>
		<button type="primary" class="button"  @tap="MechanicalArm2"     size="mini">机械臂2</button>
		<button type="primary" class="button"  @tap="MechanicalArm3"     size="mini">机械臂3</button>
		<button type="primary" class="button"  @tap="SetPattern"         size="mini">花型</button>
		<button type="primary" class="button"  @tap="ParameterSet"       size="mini">参数设定</button>
		<button type="primary" class="button"  @tap="shangping"       size="mini">商品列表</button>
		
		<input style="width: 750rpx;" @input="TargetIP" placeholder="目标IP"/>
		<input style="width: 750rpx;" @input="TargetProt" placeholder="目标端口"/>
		<!-- <input style="width: 750rpx;" @input="ReadProt" placeholder="本地接收端口"/>  -->  

	</view>
</template>

<script>
	//自定义 
	var _self;
	import process from '../../utils/process.js'	
	export default {
		data() {	
			return {	
				ip: '192.168.10.166',
				port: '8011',
				AxisPositions_X:null,   //x轴位置
				AxisPositions_Y:null,   //Y轴位置
				AxisPositions_Z:null,   //Z轴位置
				AxisPositions_R:null,   //R轴位置
				CurrentLocation:null,   //当前位置
				StepWrite:0 ,          //步数写入 
				treatmentStatu:{ checked: false},
				timer: null            //定时器名称
			};
		}, 	
		onShow() {
			 process.bushu = 0	
             this.StepWrite =  process.SetSteps[0]    //位置写入
	         if(0x01 === process.glbFFBB_Byte06.AutomaticAndManual){   //自动模式按下
				this.treatmentStatu = { checked: true}
			 }
			 else{ }
			 this.timer = setInterval(() => {
			 this.ReadData();   
			 }, 100);
		 },
		onLoad() {
			_self = this;
		},	
		//uniapp中onHide()能监听到页面离开
		onHide() {   //离开页面前清除计时器
			console.log('onHide');
			clearInterval(this.timer);
			this.timer = null;
		},
		methods: {
			TargetIP: function(event) {                    //目标Ip
				this.ip = event.detail.value;
				process.address = this.ip;	
			},
			TargetProt: function(event) {                 //目标端口
				this.port = event.detail.value;
				process.port = this.port;	
			},
			//处理数据
			ReadData(){			
				process.SetSteps[0] = _self.StepWrite;   //步数写入
				this.CurrentLocation = process.recData1.recCurrentSteps           //当前位置步数   
				this.AxisPositions_X = process.recData1.recCurrentAxis_X          //当前x轴位置
				this.AxisPositions_Y = process.recData1.recCurrentAxis_Y          //当前y轴位置
				this.AxisPositions_Z = process.recData1.recCurrentAxis_Z          //当前z轴位置
				this.AxisPositions_R = process.recData1.recCurrentAxis_R          //当前r轴位置
			},
			//跳转到商品列表
			shangping(){
				uni.reLaunch({
					url: '/pages/productlist/productlist'
				})		
			},
			//跳转机械臂1界面
			MechanicalArm1(){
				uni.navigateTo({
					url:'/pages/cottonCandy/MechanicalArm1'
				})		
			},
			//跳转机械臂2界面
			MechanicalArm2(){
				uni.navigateTo({
					url:'/pages/cottonCandy/MechanicalArm2'
				})
			},
			//跳转机械臂3界面
			MechanicalArm3(){
				uni.navigateTo({
					url:'/pages/cottonCandy/MechanicalArm3'
				})
			},
			//跳转花型设置界面
			SetPattern() {
				 uni.navigateTo({
					url:'/pages/cottonCandy/SetPattern'
				})
			},
			//跳转到参数设置
			ParameterSet(){		
				 uni.navigateTo({
					url:'/pages/cottonCandy/ParameterSet'
				})
			},
			//控制命令
			// AutomaticModePress() {
			// 	process.Pattern[0] = 0x00 // 自动模式模式 
			// },
			AxisXReducePress() {	 
				process.glbFFBB_Byte08.X_axis = 0x01   //x轴-按下
			},
			AxisXReduceRelease() {			     				
				process.glbFFBB_Byte08.X_axis = 0x00   //x轴-松开		  	
			},
			AxisXAddPress() { 
				process.glbFFBB_Byte08.X_axis = 0x02   //x轴+按下
			},
			AxisXAddRelease() {   
				process.glbFFBB_Byte08.X_axis = 0x00   //x轴+松开					
			},
			// ManualModePress() {	     				 
			// 	process.Pattern[0] = 0x01 // 手动动模式
			// }, 
			
			switchChange() {
				if(process.glbFFBB_Byte06.AutomaticAndManual === 0x0)         //手动模式按下
				{
					process.glbFFBB_Byte06.AutomaticAndManual = 0x1
					
				}
				else if(process.glbFFBB_Byte06.AutomaticAndManual === 0x1){   //自动模式按下
					process.glbFFBB_Byte06.AutomaticAndManual = 0x0
				} 
				else{ }
			},
			
			AxisYReducePress(){
				process.glbFFBB_Byte09.Y_axis = 0x01   //Y轴-按下
			},
			AxisYReduceRelease(){	     
				process.glbFFBB_Byte09.Y_axis = 0x00   //Y轴-松开
			},
			AxisYAddPress() {
				process.glbFFBB_Byte09.Y_axis = 0x02   //Y轴+按下
			},
			AxisYAddRelease() {		     
				process.glbFFBB_Byte09.Y_axis = 0x00   //Y轴+松开
			},
			
			StartUpPress() {
				//把启动按下0x01  改成0x00 进制在调试页面做糖
				process.glbFFBB_Byte06.StartAndStop = 0x01   //启动按下 
			},	
			StartUpRelease() {
				process.glbFFBB_Byte06.StartAndStop = 0x00   //启动松开   			 
			},
			AxisZReducePress() {
				process.glbFFBB_Byte09.Z_axis = 0x01         //Z轴-按下			    				 
			},
			AxisZReduceRelease() {
				process.glbFFBB_Byte09.Z_axis = 0x00         //Z轴-松开			 
			},			
			AxisZAddPress() {
				process.glbFFBB_Byte09.Z_axis = 0x02         //Z轴+按下	   			 
			},
			AxisZAddRelease() {
				process.glbFFBB_Byte09.Z_axis = 0x00         //Z轴+松开	    	 
			},
			StopPress() {
				process.glbFFBB_Byte06.StartAndStop = 0x02   //停止按下     
			},
			StopRelease() { 
				process.glbFFBB_Byte06.StartAndStop = 0x00   //停止松开	 
			},
			AxisRReducePress() {
				process.glbFFBB_Byte09.R_axis = 0x01         //R轴-按下	    	 
			},
			AxisRReduceRelease() {				 
				process.glbFFBB_Byte09.R_axis = 0x00        //R轴-松开		    	 
			},
			AxisRAddPress() { 
			    process.glbFFBB_Byte09.R_axis = 0x02        //R轴+按下	
			},
			AxisRAddRelease() {
				process.glbFFBB_Byte09.R_axis = 0x00        //R轴+松开   	 
			},
			
			ResetPress() {
				process.glbFFBB_Byte06.Reset = 0x01         //复位按下 		     
			},
			ResetRelease() {
			    process.glbFFBB_Byte06.Reset = 0x00          //松开按下  				 
			},
			AxisROGReducePress() {
				process.glbFFBB_Byte09.ROG_axis = 0x01       //ROG轴-按下			    	 
			},
			AxisROGReduceRelease() {				     
				process.glbFFBB_Byte09.ROG_axis = 0x00       //ROG轴-松开
			},
			AxisROGAddPress() {
				process.glbFFBB_Byte09.ROG_axis = 0x02       //ROG轴+按下	     
			},
			AxisROGAddRelease() {
				process.glbFFBB_Byte09.ROG_axis = 0x00       //ROG轴+松开			    				 
			},
			StepBackZeroPress() {		 
				process.glbFFBB_Byte06.StepBack0 = 0x01      // 步进回零按下  			
			},
			StepBackZeroRelease() { 
				process.glbFFBB_Byte06.StepBack0 = 0x00      // 步进回零松开	    	 
			},
			PositionWritePress() {
				process.glbFFBB_Byte11.StepPositionWrite = 0x01     // 步数位置写入指令按下	
				process.bushu = 1			
				 for (let i = 0; i < 51; i++) {
				  		// 判断 当前步数 是多少步  process.recData1.recCurrentSteps
				  		if (i === (process.SetSteps[0]) ) {		
				  			process.glbStrSendData_FFCC.sendAxis_x[i] = process.recData1.recCurrentAxis_X
				  			process.glbStrSendData_FFCC.sendAxis_y[i] = process.recData1.recCurrentAxis_Y
				  			process.glbStrSendData_FFCC.sendAxis_z[i] = process.recData1.recCurrentAxis_Z
				  			process.glbStrSendData_FFCC.sendAxis_r[i] = process.recData1.recCurrentAxis_R						
				  	}			  	
				}
			},
			PositionWriteRelease() {
				process.glbFFBB_Byte11.StepPositionWrite = 0x00     // 步数位置写入指令 松开  
				process.bushu = 0
			},
			SingleStepPress() {
				process.glbFFBB_Byte11.SingleStep = 0x01      // 单步按下		    	 
			},
			SingleStepRelease() {
				process.glbFFBB_Byte11.SingleStep = 0x00      // 单步松开		     
			},	
			CheckoutRisePress() {
				process.glbFFBB_Byte06.SignOut = 0x01        // 出签上升按下 	 
			},                                                
			CheckoutRiseRelease() {                           
				process.glbFFBB_Byte06.SignOut = 0x00        // 出签上升松开   	 
			},                                                
			CheckoutDropPress() {	                          
				process.glbFFBB_Byte06.SignOut = 0x02        // 出签 下降按下	     
			},                                                
			CheckoutDropRelease() {				              
				process.glbFFBB_Byte06.SignOut = 0x00        // 出签下降松开		     
			},                                                  
			ElectricDoorOpenPress() {                         
				process.glbFFBB_Byte07.PowerDoors = 0x01     //电动门开启按下			     	
			},                                                
			ElectricDoorOpenRelease() {                       
				process.glbFFBB_Byte07.PowerDoors = 0x00     //电动门开启松开				    	 
			},                                                
			ElectricDoorClosePress() {                        
				process.glbFFBB_Byte07.PowerDoors = 0x02     //电动门关闭按下											      
			},
			ElectricDoorCloseRelease() {	 
				process.glbFFBB_Byte07.PowerDoors = 0x00     //电动门关闭松开 
			},
			WaterPumpPress() {			
				process.glbFFBB_Byte06.WaterPump = 0x01      //水泵按下
			},                                                 
			WaterPumpRelease() {                               
				process.glbFFBB_Byte06.WaterPump = 0x00      //水泵松开 			 
			},                                                 
			FanPress() {                                       
				process.glbFFBB_Byte07.Fan = 0x01           //风机按下
			},                                                 
			FanRelease() {                                     
				process.glbFFBB_Byte07.Fan = 0x00           //风机松开
			},                                                 
			SugarControlMotor1Press() {				           
				process.glbFFBB_Byte07.SugarControlMotor_1 = 0x01      //1#糖控电机按下	     
			},                                                 
			SugarControlMotor1Release() {                      
				process.glbFFBB_Byte07.SugarControlMotor_1 = 0x00      //1#糖控电机松开	
			},                                                 
			SugarControlMotor2Press() {                        
				process.glbFFBB_Byte07.SugarControlMotor_2 = 0x01      //2#糖控电机按下
			},                                                 
			SugarControlMotor2Release() {                      
				process.glbFFBB_Byte07.SugarControlMotor_2 = 0x00      //2#糖控电机松开
			},
			SugarControlMotor3Press() {
				process.glbFFBB_Byte07.SugarControlMotor_3 = 0x01      //3#糖控电机按下  	 
			},
			SugarControlMotor3Release() {
			   process.glbFFBB_Byte07.SugarControlMotor_3  = 0x00      //3#糖控电机松开  	  
			},
			SugarControlMotor4Press() { 
				process.glbFFBB_Byte07.SugarControlMotor_4 = 0x01     //4#糖控电机按下  
			},                                                
			SugarControlMotor4Release() {                     
				process.glbFFBB_Byte07.SugarControlMotor_4 = 0x00     //4#糖控电机松开				 
			},                                                                                              
			SugarHeadStartPress() {	                          
				process.glbFFBB_Byte08.SugarHead = 0x01        //糖头启动按下
			},                                                
			SugarHeadStartRelease() {	                      
				process.glbFFBB_Byte08.SugarHead = 0x00        //糖头启动松开	
			},
			SugarHeadStopPress() {
				process.glbFFBB_Byte08.SugarHead = 0x02       //糖头停止按下
			},
			SugarHeadStopRelease() {
				process.glbFFBB_Byte08.SugarHead = 0x00       //糖头停止松开
			},
			HeatingStartPress() { 
				process.glbFFBB_Byte08.Heating = 0x01         //加热启动按下
			},
			HeatingStartRelease() {				
				process.glbFFBB_Byte08.Heating = 0x00         //加热启动松开
			},
			HeatingStopPress() {
				process.glbFFBB_Byte08.Heating = 0x02         //加热停止按下	     
			},
			HeatingStopRelease() {
				process.glbFFBB_Byte08.Heating = 0x00         //加热停止松开		    
			},
			PowerOnPress() {
				process.glbFFBB_Byte08.StartUp = 0x01         //开机按下
			},
			PowerOnRelease() {
				process.glbFFBB_Byte08.StartUp = 0x00         //开机松开	     
			},
			ShutDownPress() {
				process.glbFFBB_Byte08.StartUp = 0x02         //关机按下	 
			},
			ShutDownRelease() {
				process.glbFFBB_Byte08.StartUp = 0x00         //关机松开	 
			}		
		}
	};
</script>

<style scoped>	
.button{
		height: 60rpx;
		width: 200rpx;
		margin-top: 20rpx;
		margin-left: 20rpx;
		border-radius: 10px;
}
.mytest input{
	margin-top: 20rpx;
	border: 1rpx solid black;
	width: 120rpx;
}	
.propertyBox{
	flex-flow: row;
	justify-content: space-evenly;
	display: flex;
}
.tex-box{
    text-align: center;
}
.text{
	font-size: 10rpx;
/* 	font-size: 14px;
	 vertical-align: middle; */
}

</style>
