新增步进电机方向控制,振动引脚
This commit is contained in:
30
Network.py
30
Network.py
@ -42,7 +42,11 @@ class NetworkHandler:
|
||||
'set_tare_num_time': 0,
|
||||
'get_weight': False,
|
||||
'set_vibrate': False,
|
||||
'set_vibrate_time': 0
|
||||
'set_vibrate_time': 0,
|
||||
'direction_control': False,
|
||||
'start_weighting': False,
|
||||
'weighting_isok': False,
|
||||
'vibrate_isok': False
|
||||
}
|
||||
self.lock = threading.Lock()
|
||||
self.running = True
|
||||
@ -71,6 +75,23 @@ class NetworkHandler:
|
||||
self._process_command(cmd)
|
||||
time.sleep(0.5)
|
||||
# 返回当前状态
|
||||
if self.status['start_weighting'] == True :
|
||||
while True:
|
||||
if self.status['start_weighting'] == False:
|
||||
with self.lock:
|
||||
response = json.dumps(self.status)
|
||||
conn.send(response.encode())
|
||||
break
|
||||
time.sleep(0.5)
|
||||
elif self.status['set_vibrate'] == True:
|
||||
while True:
|
||||
if self.status['set_vibrate'] == False:
|
||||
with self.lock:
|
||||
response = json.dumps(self.status)
|
||||
conn.send(response.encode())
|
||||
break
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
with self.lock:
|
||||
response = json.dumps(self.status)
|
||||
conn.send(response.encode())
|
||||
@ -87,10 +108,14 @@ class NetworkHandler:
|
||||
|
||||
self.status['target_weight'] = cmd['payload']['target_weight']
|
||||
self.status['algorithm'] = cmd['payload'].get('algorithm', 'pid')
|
||||
self.status['direction_control'] = cmd['payload']['direction_control']
|
||||
self.status['measuring'] = True
|
||||
self.status['start_weighting'] = True
|
||||
self.status['weighting_isok'] = False
|
||||
print("收到指令set_target:", self.status['target_weight'])
|
||||
elif cmd.get('command') == 'stop':
|
||||
self.status['measuring'] = False
|
||||
self.status['start_weighting'] = False
|
||||
|
||||
elif cmd.get('command') == 'set_zero':
|
||||
self.status['set_tare'] = True
|
||||
@ -100,4 +125,5 @@ class NetworkHandler:
|
||||
|
||||
elif cmd.get('command') == 'set_vibrate':
|
||||
self.status['set_vibrate'] = True
|
||||
self.status['set_vibrate_time'] = cmd['payload']['time']
|
||||
self.status['set_vibrate_time'] = cmd['payload']['time']
|
||||
self.status['vibrate_isok'] = False
|
||||
Reference in New Issue
Block a user