{"action":"created","issue":{"url":"https://api.github.com/repos/trinketapp/skulpt/issues/26","repository_url":"https://api.github.com/repos/trinketapp/skulpt","labels_url":"https://api.github.com/repos/trinketapp/skulpt/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/trinketapp/skulpt/issues/26/comments","events_url":"https://api.github.com/repos/trinketapp/skulpt/issues/26/events","html_url":"https://github.com/trinketapp/skulpt/pull/26","id":167239190,"number":26,"title":"New SenseStick API Changes","user":{"login":"waywaaard","id":1634468,"avatar_url":"https://avatars.githubusercontent.com/u/1634468?v=3","gravatar_id":"","url":"https://api.github.com/users/waywaaard","html_url":"https://github.com/waywaaard","followers_url":"https://api.github.com/users/waywaaard/followers","following_url":"https://api.github.com/users/waywaaard/following{/other_user}","gists_url":"https://api.github.com/users/waywaaard/gists{/gist_id}","starred_url":"https://api.github.com/users/waywaaard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waywaaard/subscriptions","organizations_url":"https://api.github.com/users/waywaaard/orgs","repos_url":"https://api.github.com/users/waywaaard/repos","events_url":"https://api.github.com/users/waywaaard/events{/privacy}","received_events_url":"https://api.github.com/users/waywaaard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-07-24T15:39:50Z","updated_at":"2016-07-25T14:10:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/trinketapp/skulpt/pulls/26","html_url":"https://github.com/trinketapp/skulpt/pull/26","diff_url":"https://github.com/trinketapp/skulpt/pull/26.diff","patch_url":"https://github.com/trinketapp/skulpt/pull/26.patch"},"body":"This PR implements the new sense stick API.\r\n\r\n- [x] the new `wait_for_event`\r\n- [x] `get_events` (may need some love and further testing)\r\n- [x] direction_up, direction_left, direction_right, direction_down, direction_middle, direction_any (This requires a couple of changes in the SenseStickDevice (please look at the `sense_hat_example`)\r\n- [x] There is still an issue with the the `get_events` (basically the old `wait(0)` way) and killable while loops.\r\n- [ ] Testing\r\n\r\n### Examples\r\n```python\r\nfrom sense_hat import SenseHat\r\nfrom time import sleep\r\n\r\nsense = SenseHat()\r\nevent = sense.stick.wait_for_event()\r\nprint(\"The joystick was {} {}\".format(event.action, event.direction))\r\nsleep(0.1)\r\nevent = sense.stick.wait_for_event()\r\nprint(\"The joystick was {} {}\".format(event.action, event.direction))\r\n```\r\n\r\n```python\r\nfrom sense_hat import SenseHat\r\n\r\nsense = SenseHat()\r\nwhile True:\r\n    for event in sense.stick.get_events():\r\n        print(\"The joystick was {} {}\".format(event.action, event.direction))\r\n```\r\n\r\nThe last example has been modified as we do not support the signal module\r\n```python\r\nfrom sense_hat import SenseHat, ACTION_PRESSED, ACTION_RELEASED\r\n#from signal import pause\r\n\r\nx = 3\r\ny = 3\r\nsense = SenseHat()\r\n\r\ndef clamp(value, min_value=0, max_value=7):\r\n    return min(max_value, max(min_value, value))\r\n\r\ndef pushed_up(event):\r\n    global y\r\n    if event.action != ACTION_RELEASED:\r\n        y = clamp(y - 1)\r\n\r\ndef pushed_down(event):\r\n    global y\r\n    if event.action != ACTION_RELEASED:\r\n        y = clamp(y + 1)\r\n\r\ndef pushed_left(event):\r\n    global x\r\n    if event.action != ACTION_RELEASED:\r\n        x = clamp(x - 1)\r\n\r\ndef pushed_right(event):\r\n    global x\r\n    if event.action != ACTION_RELEASED:\r\n        x = clamp(x + 1)\r\n\r\ndef refresh():\r\n    sense.clear()\r\n    sense.set_pixel(x, y, 255, 255, 255)\r\n\r\nsense.stick.direction_up = pushed_up\r\nsense.stick.direction_down = pushed_down\r\nsense.stick.direction_left = pushed_left\r\nsense.stick.direction_right = pushed_right\r\nsense.stick.direction_any = refresh\r\nrefresh()\r\n\r\nwhile True:\r\n    pass\r\n\r\n# This seems not to be possible in skulpt: https://docs.python.org/2/library/signal.html#signal.pause\r\n#pause()\r\n```"},"comment":{"url":"https://api.github.com/repos/trinketapp/skulpt/issues/comments/234964114","html_url":"https://github.com/trinketapp/skulpt/pull/26#issuecomment-234964114","issue_url":"https://api.github.com/repos/trinketapp/skulpt/issues/26","id":234964114,"user":{"login":"eah13","id":1702745,"avatar_url":"https://avatars.githubusercontent.com/u/1702745?v=3","gravatar_id":"","url":"https://api.github.com/users/eah13","html_url":"https://github.com/eah13","followers_url":"https://api.github.com/users/eah13/followers","following_url":"https://api.github.com/users/eah13/following{/other_user}","gists_url":"https://api.github.com/users/eah13/gists{/gist_id}","starred_url":"https://api.github.com/users/eah13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eah13/subscriptions","organizations_url":"https://api.github.com/users/eah13/orgs","repos_url":"https://api.github.com/users/eah13/repos","events_url":"https://api.github.com/users/eah13/events{/privacy}","received_events_url":"https://api.github.com/users/eah13/received_events","type":"User","site_admin":false},"created_at":"2016-07-25T14:10:55Z","updated_at":"2016-07-25T14:10:55Z","body":"Sounds good.  \r\n\r\nIf it seems like the changes to Skulpt would be complicated I wonder if we could make a pipeline directly into the fb_device's event buffer that the listener that's displaying the joystick changes could populate.  That seems more analogous to the way the hardware works anyways and wouldn't care whether skulpt's ready to listen.  "}}
{"actor":{"display_login":"eah13"}}