Skip to content

Commit

Permalink
Some quality of life changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
euphy committed Oct 6, 2018
1 parent c84a67f commit 3b944e7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/exec.ino
Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions src/polargraph_server_polarshield_esp32.ino
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions test/polargraph.py
Expand Up @@ -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")
Expand Down
34 changes: 29 additions & 5 deletions test/test_serial_immediate.py
Expand Up @@ -5,24 +5,22 @@
# 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'
CMD_SETMACHINESTEPSPERREV = 'C30,{steps_per_rev},END'
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):

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 3b944e7

Please sign in to comment.