Skip to content

Commit bf5004a

Browse files
roman-dvorakpeterbarker
authored andcommitted
support for booth messages - RC_CHANNELS ad RC_CHANNELS_RAW., clean code.
1 parent f54efe2 commit bf5004a

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

dronekit/__init__.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,31 +1142,18 @@ def listener(vehicle, name, m):
11421142
# All keys are strings.
11431143
self._channels = Channels(self, 8)
11441144

1145+
@self.on_message('RC_CHANNELS_RAW')
11451146
@self.on_message('RC_CHANNELS')
11461147
def listener(self, name, m):
11471148
def set_rc(chnum, v):
11481149
'''Private utility for handling rc channel messages'''
11491150
# use port to allow ch nums greater than 8
1150-
self._channels._update_channel(str(0 * 8 + chnum), v)
1151-
1152-
set_rc(1, m.chan1_raw)
1153-
set_rc(2, m.chan2_raw)
1154-
set_rc(3, m.chan3_raw)
1155-
set_rc(4, m.chan4_raw)
1156-
set_rc(5, m.chan5_raw)
1157-
set_rc(6, m.chan6_raw)
1158-
set_rc(7, m.chan7_raw)
1159-
set_rc(8, m.chan8_raw)
1160-
set_rc(9, m.chan9_raw)
1161-
set_rc(10, m.chan10_raw)
1162-
set_rc(11, m.chan11_raw)
1163-
set_rc(12, m.chan12_raw)
1164-
set_rc(13, m.chan13_raw)
1165-
set_rc(14, m.chan14_raw)
1166-
set_rc(15, m.chan15_raw)
1167-
set_rc(16, m.chan16_raw)
1168-
set_rc(17, m.chan17_raw)
1169-
set_rc(18, m.chan18_raw)
1151+
port = 0 if name == "RC_CHANNELS" else m.port
1152+
self._channels._update_channel(str(port * 8 + chnum), v)
1153+
1154+
for i in range(1, (18 if name == "RC_CHANNELS" else 8)+1):
1155+
set_rc(i, getattr(m, "chan{}_raw".format(i)))
1156+
11701157
self.notify_attribute_listeners('channels', self.channels)
11711158

11721159
self._voltage = None

0 commit comments

Comments
 (0)