Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
naive reset
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed Jul 24, 2016
1 parent eca06f3 commit c08682d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 14 additions & 0 deletions reset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

from xy.device import Device


def main():
with Device() as device:
device.reset()


if __name__ == '__main__':
main()

23 changes: 18 additions & 5 deletions xy/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

PEN_URL = '/v1/pen'
BOT_SETTINGS_URL = '/v1/settings/bot'
BUFFER_URL = '/v1/buffer'


class Device(object):
Expand All @@ -36,8 +37,10 @@ def __init__(
self._penup = float(penup)
self._pendown = float(pendown)
self._host = host

self._pen_url = host + PEN_URL
self._bot_settings_url = host + BOT_SETTINGS_URL
self._buffer_url = host + BUFFER_URL

self._drawing_speed = int(drawing_speed)
self._moving_speed = int(moving_speed) # TODO: this does not nothing atm?
Expand Down Expand Up @@ -79,6 +82,15 @@ def _settings(self):
self._bot_settings_url
)

def _cmd_del(self, url):
req = urllib.request.Request(url, method='DELETE')
with urllib.request.urlopen(req) as res:
if res.status != 200:
print('WARNING: error status ' + str(res.status) + ' ' + str(res.reason))
a = json.loads(res.readall().decode('utf-8'))
if self.verbose:
print(json.dumps(a, sort_keys=True, indent=2))

def _cmd(self, d, url):
jsn = json.dumps(d)
post = jsn.encode('utf-8')
Expand Down Expand Up @@ -115,8 +127,12 @@ def _xy_transform(self, xy):

return txy

def move(self, xy):
def reset(self):
self._cmd_del(self._buffer_url)
self.penup()
self.move(array([0,0], 'float'))

def move(self, xy):
self._moves += 1
txy = self._xy_transform(xy)
self._cmd(
Expand Down Expand Up @@ -144,8 +160,7 @@ def _get_total_moves(self, paths):
num += len(p)-1
return num

def do_paths(self, paths, info_leap=10):
# t0 = time()
def do_paths(self, paths, info_leap=200):
num = len(paths)
moves = self._get_total_moves(paths)
print('# paths: {:d}'.format(num))
Expand All @@ -163,8 +178,6 @@ def do_paths(self, paths, info_leap=10):
self.move(xy)
if flip > info_leap:
per = self._moves/float(moves)
# tot = (time()-t0)/3600.
# rem = tot/per - tot
s = 'progress: {:d}/{:d} ({:3.03f})'
print(s.format(self._moves, moves, per))
flip = 0
Expand Down

0 comments on commit c08682d

Please sign in to comment.