def stop() -> None: ops_read = b''.join([ ev3.opInput_Device, ev3.READY_SI, ev3.LCX(0), # LAYER ev3.LCX(1), # NO ev3.LCX(16), # TYPE - EV3-Touch ev3.LCX(0), # MODE - Touch ev3.LCX(1), # VALUES ev3.GVX(0), # VALUE1 ev3.opInput_Device, ev3.READY_SI, ev3.LCX(0), # LAYER ev3.LCX(1), # NO ev3.LCX(16), # TYPE - EV3-Touch ev3.LCX(1), # MODE - Bump ev3.LCX(1), # VALUES ev3.GVX(4) # VALUE1 ]) ops_sound = play_sound(10, 200, 100) reply = my_ev3.send_direct_cmd(ops_sound + ops_read, global_mem=8) (touched, bumps) = struct.unpack('<ff', reply[5:]) if touched == 1: bumps += 0.5 print(bumps, "bumps")
def test_brickname(): '''set and read brickname''' my_ev3.verbosity = 0 my_ev3.sync_mode = ev3.STD ops_get = b''.join(( ev3.opCom_Get, ev3.GET_BRICKNAME, # CMD ev3.LCX(32), # LENGTH ev3.GVX(0) # NAME (out) )) reply = my_ev3.send_direct_cmd(ops_get, global_mem=32) name_orig = struct.unpack('32s', reply[5:])[0].split(b'\x00')[0].decode("ascii") ops_set = b''.join((ev3.opCom_Set, ev3.SET_BRICKNAME, ev3.LCS('Bernie'))) my_ev3.send_direct_cmd(ops_set) reply = my_ev3.send_direct_cmd(ops_get, global_mem=32) name_tmp = struct.unpack('32s', reply[5:])[0].split(b'\x00')[0].decode("ascii") assert name_tmp == 'Bernie' ops_set = b''.join((ev3.opCom_Set, ev3.SET_BRICKNAME, ev3.LCS(name_orig))) my_ev3.send_direct_cmd(ops_set) my_ev3.sync_mode = ev3.ASYNC msg_cnt = my_ev3.send_direct_cmd(ops_get, global_mem=32) reply = my_ev3.wait_for_reply(msg_cnt) name = struct.unpack('32s', reply[5:])[0].split(b'\x00')[0].decode("ascii") assert name == name_orig
def ConstructCommand(self, daisyChainLayer, port, sensorType, sensorMode, values=1, values1=0): return b''.join(( ev3.opInput_Device, # operation ev3.READY_SI, # CMD ev3.LCX(daisyChainLayer), # LAYER ev3.LCX(port), # NO ev3.LCX(sensorType), # TYPE ev3.LCX(sensorMode), # MODE ev3.LCX(values), # VALUES ev3.GVX(values1), # VALUE1 ))