diff --git a/src/exec.ino b/src/exec.ino index 2172364..d47ce0c 100644 --- a/src/exec.ino +++ b/src/exec.ino @@ -26,7 +26,7 @@ boolean exec_executeBasicCommand(String inCmd, String inParam1, String inParam2, exec_changeLength(); else if (inCmd.startsWith(CMD_CHANGELENGTHDIRECT)) exec_changeLengthDirect(); - else if (inCmd.startsWith(CMD_CHANGEPENWIDTH)) + else if (inCmd.startsWith(CMD_SETPENWIDTH)) exec_changePenWidth(); else if (inCmd.startsWith(CMD_SETMOTORSPEED)) exec_setMotorSpeedFromCommand(); diff --git a/src/polargraph_server_polarshield_esp32.ino b/src/polargraph_server_polarshield_esp32.ino index e13e6d7..24cff08 100644 --- a/src/polargraph_server_polarshield_esp32.ino +++ b/src/polargraph_server_polarshield_esp32.ino @@ -327,9 +327,7 @@ static const byte SAW_SHAPE = 1; const static char COMMA[] = ","; const static char CMD_END[] = ",END"; const static String CMD_CHANGELENGTH = "C01"; -const static String CMD_CHANGEPENWIDTH = "C02"; -// const static String CMD_CHANGEMOTORSPEED = "C03"; -// const static String CMD_CHANGEMOTORACCEL = "C04"; +const static String CMD_SETPENWIDTH = "C02"; const static String CMD_DRAWPIXEL = "C05"; const static String CMD_DRAWSCRIBBLEPIXEL = "C06"; const static String CMD_CHANGEDRAWINGDIRECTION = "C08"; diff --git a/test/polargraph.py b/test/polargraph.py index 79c863b..9306293 100644 --- a/test/polargraph.py +++ b/test/polargraph.py @@ -58,6 +58,7 @@ def read_line(self, echo=True): def write_command(self, command): if self.ready: + self.commands_written_count += 1 print("Command {}: {}" .format(self.commands_written_count, command)) self.serial_port.write(command + "\n") diff --git a/test/test_serial_immediate.py b/test/test_serial_immediate.py index 3e2337b..1de64be 100644 --- a/test/test_serial_immediate.py +++ b/test/test_serial_immediate.py @@ -5,10 +5,7 @@ # Immediate commands are interpreted quickly CMD_SETPENWIDTH = 'C02,{pen_width},END' -# CMD_CHANGEMOTORSPEED = 'C03,{motor_speed},END' -# CMD_CHANGEMOTORACCEL = 'C04,{motor_accel},END' CMD_SETMACHINESIZE = 'C24,{width},{height},END' -# CMD_SETMACHINENAME = 'C25,{name},END' CMD_GETMACHINEDETAILS = 'C26,END' # CMD_RESETEEPROM = 'C27,END' CMD_SETMACHINEMMPERREV = 'C29,{mm_per_rev},END' @@ -16,13 +13,14 @@ CMD_SETMOTORSPEED = 'C31,{motor_speed},END' CMD_SETMOTORACCEL = 'C32,{motor_accel},END' CMD_SETMACHINESTEPMULTIPLIER = 'C37,{step_multiplier},END' -# CMD_SETPENLIFTRANGE = 'C45,{down_pos},{up_pos},END' +CMD_SETPENLIFTRANGE = 'C45,{down_pos},{up_pos},{write},END' # CMD_SET_ROVE_AREA = 'C21,{pos_x},{pos_y},{width},{height},END' # CMD_SET_DEBUGCOMMS = 'C47,END' # CMD_MODE_STORE_COMMANDS = 'C33,{newfilename},{replace},END' # CMD_MODE_EXEC_FROM_STORE = 'C34,{filename},END' # CMD_MODE_LIVE = 'C35,END' -# CMD_START_TEXT = 'C38,END' + +CMD_SETPENLIFTRANGE_TEST_RANGE = 'C45,{down_pos},{up_pos},END' class TestImmediateTests(object): @@ -66,6 +64,19 @@ def get_speed_spec(self): return {'speed': current_speed, 'accel': current_accel} + + def test_get_machine_details(self): + spec = self.get_machine_spec() + expected = \ + ['PGSIZE', 'PGMMPERREV', 'PGSTEPSPERREV', 'PGSTEPMULTIPLIER', + 'PGLIFT', 'PGSPEED', 'PGPENWIDTH'] + assert len(spec) >= len(expected) + + for response in expected: + match = [x for x in spec if x.startswith(response)] + assert len(match) == 1 + + @pytest.mark.skip() def test_set_pen_width(self): command = CMD_SETPENWIDTH.format(pen_width=1.0) @@ -130,3 +141,16 @@ def test_set_size(self): assert 'New size: 700, 800' in self.get_response_to(command) assert 'PGSIZE,700,800,END' in self.get_machine_spec() + def test_set_lift_range(self): + command = CMD_SETPENLIFTRANGE.format(down_pos=20, up_pos=60, write=1) + responses = self.get_response_to(command) + assert 'Down: 20' in responses + assert 'Up: 60' in responses + assert 'PGLIFT,20,60,END' in self.get_machine_spec() + + command = CMD_SETPENLIFTRANGE.format(down_pos=90, up_pos=180, write=1) + responses = self.get_response_to(command) + assert 'Down: 90' in responses + assert 'Up: 180' in responses + assert 'PGLIFT,90,180,END' in self.get_machine_spec() +