{"id":1674,"date":"2020-10-24T09:17:32","date_gmt":"2020-10-24T08:17:32","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1674"},"modified":"2020-10-24T10:47:16","modified_gmt":"2020-10-24T09:47:16","slug":"committed-to-pybricks","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2020\/committed-to-pybricks","title":{"rendered":"Committed to Pybricks"},"content":{"rendered":"\n<p>So I committed <a href=\"https:\/\/github.com\/pybricks\/pybricks-projects\/tree\/master\/sets\/technic\/42109_top_gear_rally_car\/keyboard_remote\">2 files<\/a> to the <a href=\"https:\/\/pybricks.com\/\">Pybricks<\/a> project:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"117\" src=\"https:\/\/i0.wp.com\/ofalcao.pt\/blog\/wp-content\/uploads\/2020\/10\/image-1.png?resize=840%2C117&#038;ssl=1\" alt=\"\" class=\"wp-image-1675\" srcset=\"https:\/\/i0.wp.com\/ofalcao.pt\/blog\/wp-content\/uploads\/2020\/10\/image-1.png?w=877&amp;ssl=1 877w, https:\/\/i0.wp.com\/ofalcao.pt\/blog\/wp-content\/uploads\/2020\/10\/image-1.png?resize=300%2C42&amp;ssl=1 300w, https:\/\/i0.wp.com\/ofalcao.pt\/blog\/wp-content\/uploads\/2020\/10\/image-1.png?resize=768%2C107&amp;ssl=1 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>not really to the project code but with a demo project that shows how to use the new &#8216;getchar&#8217; function to pass commands from the Pybricks Chrome IDE to the hub in runtime.<\/p>\n\n\n\n<p>&#8216;<a href=\"https:\/\/github.com\/pybricks\/support\/issues\/154\">getchar<\/a>&#8216; works like the standard &#8216;input&#8217; function but is doesn&#8217;t wait for ENTER so it is non-blocking. I <a href=\"https:\/\/ofalcao.pt\/blog\/2020\/installing-bluepy-on-ev3\">already used &#8216;input&#8217;<\/a> to send commands to the Top Gear Rally Car and from the &#8216;client&#8217; side (my EV3 python script) the only difference is not having to send a carriage return any more but from the hub side the responsiveness of the code should be now much better.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from pybricks.experimental import getchar\n\nwhile True:\n    c = getchar()\n    if c == ord('a'):\n        print('You pressed a! Now drive forwards...')\n    elif c == ord('b'):\n        print('You pressed b! Self destruct in 3, 2, 1...')<\/code><\/pre>\n\n\n\n<p>Another advantage of &#8216;getchar&#8217; is allowing me to use Nordic nRF Toolbox UART tool to send commands to the hub:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-tumblr\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"tumblr-post\" data-href=\"https:\/\/embed.tumblr.com\/embed\/post\/XYex7bvoF17_RkGj5X9Ebw\/632845645520175104\" data-did=\"f9267a43e36167f0e75a06841094e30eb9cc5a99\"  ><a href=\"https:\/\/cyberxstuff.tumblr.com\/post\/632845645520175104\">https:\/\/cyberxstuff.tumblr.com\/post\/632845645520175104<\/a><\/div><script async src=\"https:\/\/assets.tumblr.com\/post.js\"><\/script>\n<\/div><\/figure>\n\n\n\n<p>The tool always send a termination code (we can choose LF \/ CR \/ CR+LF) but now &#8216;input&#8217; considers it as just another character.<\/p>\n\n\n\n<p>The usual companion video:<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Pybricks - Augmented remote control using keyboard\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/esE_6oiFy20?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>So I committed 2 files to the Pybricks project: not really to the project code but with a demo project that shows how to use the new &#8216;getchar&#8217; function to pass commands from the Pybricks Chrome IDE to the hub in runtime. &#8216;getchar&#8216; works like the standard &#8216;input&#8217; function but is doesn&#8217;t wait for ENTER &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2020\/committed-to-pybricks\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;Committed to Pybricks&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[362],"series":[],"class_list":["post-1674","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","tag-pybricks"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-r0","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=1674"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1674\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1674"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}