3
3
4
4
X_GRID_NAMES = string .ascii_uppercase [0 :11 ]
5
5
6
- def position_trans (p ):
6
+ def position_trans (p , num_rows ):
7
7
"""convert led number (strip number) to moonboard grid """
8
- col = p // 18
9
- row = (p % 18 ) + 1
8
+ col = p // num_rows
9
+ row = (p % num_rows ) + 1
10
10
if col % 2 == 1 :
11
- row = 19 - row
11
+ row = ( num_rows + 1 ) - row
12
12
return X_GRID_NAMES [col ]+ str (row )
13
13
14
- def decode_problem_string (s ):
15
- holds = {'START' :[],'MOVES' :[],'TOP' :[]}
14
+ def decode_problem_string (s , flags ):
15
+ holds = {'START' :[],'MOVES' :[],'TOP' :[], 'FLAGS' :[flags ]}
16
+
17
+ if flags .find ("M" ) != - 1 :
18
+ num_rows = 12
19
+ else :
20
+ num_rows = 18
21
+
16
22
for h in s .split (',' ):
17
- t ,p = h [0 ],position_trans (int (h [1 :]))
23
+ t ,p = h [0 ],position_trans (int (h [1 :]), num_rows )
18
24
if t == 'S' :
19
25
holds ['START' ].append (p )
20
26
if t == 'P' :
@@ -37,6 +43,7 @@ def __init__(self,logger=None):
37
43
else :
38
44
self .logger = logger
39
45
self .s = ''
46
+ self .flags = ''
40
47
41
48
def process_bytes (self , ba ):
42
49
"""
@@ -47,7 +54,14 @@ def process_bytes(self, ba):
47
54
s = bytearray .fromhex (ba ).decode ()
48
55
self .logger .debug ("incoming bytes:" + str (s ))
49
56
50
- if s [:2 ]== self .START :
57
+ if s [0 ] == '~' and s [- 1 ] == '*' :
58
+ # Flag processing
59
+ self .flags = s [1 :- 1 ]
60
+ if s .find ("M" ) != - 1 :
61
+ self .logger .debug ('MINI' )
62
+ if s .find ("D" ) != - 1 :
63
+ self .logger .debug ('BothLights' )
64
+ elif s [:2 ]== self .START :
51
65
self .logger .debug ('START' )
52
66
if self .s == '' :
53
67
if s [- 1 ]== self .STOP :
@@ -67,4 +81,4 @@ def process_bytes(self, ba):
67
81
self .logger .debug ('error: not started' )
68
82
self .s = ''
69
83
else :
70
- self .s += s
84
+ self .s += s
0 commit comments