-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.py
78 lines (63 loc) · 2.4 KB
/
Command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#coding:utf-8
import time
import logging
class Command:
# 基底アドレスを車両アドレスに足したものをDSAir2に送信する
LOCO_DEFAULT_ADDR = 0xC000
ACCESSORY_DEFAULT_ADDR = 0x3800 - 1
@classmethod
def setLocoFunction(self, command_queue, loco_addr, func_num, value):
command_queue.put(f'setLocoFunction({loco_addr + self.LOCO_DEFAULT_ADDR},{func_num},{value})')
@classmethod
def setLocoSpeed(self, command_queue, loco_addr, speed):
if speed > 0:
out_speed = int(speed)
else:
out_speed = 0
command_queue.put(f'setLocoSpeed({loco_addr + self.LOCO_DEFAULT_ADDR},{out_speed},2)')
@classmethod
def setLocoDirection(self, command_queue, loco_addr, way):
if way in (1, 2):
command_queue.put(f'setLocoDirection({loco_addr + self.LOCO_DEFAULT_ADDR},{way})')
@classmethod
def switchToDc(self, command_queue):
command_queue.put('setPower(0)')
time.sleep(0.3)
command_queue.put('setPower(0)')
time.sleep(0.3)
command_queue.put('setPower(0)')
time.sleep(0.3)
@classmethod
def switchToDCC(self, command_queue):
command_queue.put('setPower(1)')
time.sleep(0.3)
command_queue.put('setPower(1)')
time.sleep(0.3)
command_queue.put('setPower(1)')
time.sleep(0.3)
@classmethod
def reset(self, command_queue):
command_queue.put('reset()')
@classmethod
def setTurnout(self, command_queue, addr, direction):
command_queue.put(f'setTurnout({self.ACCESSORY_DEFAULT_ADDR + addr},{direction})')
@classmethod
def setPing(self, command_queue):
command_queue.put('setPing()')
# DC駆動用
#@classmethod
#def move_dc(self, speed_level, way):
#if speed_level > 0 and way != 0:
#out_speed = int(speed_level)
#else:
## 仮想的な方向 0(切)
#out_speed = 0
#if out_speed > self.MAX_SPEED:
#out_speed = self.MAX_SPEED
#if out_speed < 0:
#out_speed = 0
#if way != self.last_way:
#self.last_way = way
#if out_speed != self.last_out_speed:
#self.last_out_speed = out_speed
#self.send(f'DC({out_speed},{way})\n')