{"id":729,"date":"2014-10-26T09:32:12","date_gmt":"2014-10-26T09:32:12","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=729"},"modified":"2014-10-26T09:33:23","modified_gmt":"2014-10-26T09:33:23","slug":"sbrick-remote-control","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2014\/sbrick-remote-control","title":{"rendered":"SBrick Remote Control"},"content":{"rendered":"<p>Uma incurs\u00e3o r\u00e1pida em Python e Tkinter (uma library para aplica\u00e7\u00f5es GUI muito f\u00e1cil de usar no modo Google-Copy-Paste) para poder comunicar com o SBrick a partir do meu laptop Ubuntu sem usar a linha de comando:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-730\" src=\"https:\/\/i0.wp.com\/ofalcao.pt\/blog\/wp-content\/uploads\/2014\/10\/SBrick-RemoteControl.png?resize=254%2C201\" alt=\"SBrick-RemoteControl\" width=\"254\" height=\"201\" \/><\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"SBrick RemoteControl v01\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/wBU7oMKKVT8?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><\/div>\n<pre>#!\/usr\/bin\/env python \r\n\r\nfrom Tkinter import *\r\nfrom time import sleep\r\nfrom subprocess import call\r\n\r\ndef quit():\r\n\u00a0 global Window\r\n\u00a0 Window.destroy()\r\n\r\n\u00a0 return;\r\n\r\ndef STOP():\r\n\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=0002\",shell=True)\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=0003\",shell=True)\r\n\u00a0 return\r\n\r\ndef NORTH():\r\n\r\n\u00a0 time=scale.get()\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010301FF\",shell=True)\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010200FF\",shell=True)\r\n\u00a0 sleep(time)\r\n\u00a0 STOP()\r\n\u00a0 return\r\n\r\ndef SOUTH():\r\n\r\n\u00a0 time=scale.get()\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010300FF\",shell=True)\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010201FF\",shell=True)\r\n\u00a0 print(\"Backward\")\r\n\u00a0 sleep(time)\r\n\u00a0 STOP()\r\n\u00a0 return\r\n\r\ndef EAST():\r\n\r\n\u00a0 time=scale.get()\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010301FF\",shell=True)\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010201FF\",shell=True)\r\n\u00a0 print(\"RIGHT\")\r\n\u00a0 sleep(time)\r\n\u00a0 STOP()\r\n\u00a0 return\r\n\r\ndef WEST():\r\n\r\n\u00a0 time=scale.get()\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010200FF\",shell=True)\r\n\u00a0 call(\"gatttool -b 00:07:80:7F:28:E1 -i hci0 --char-write --handle=0x0025 --value=010300FF\",shell=True)\r\n\u00a0 sleep(time)\r\n\u00a0 STOP()\r\n\u00a0 return\r\n\r\n\r\nWindow = Tk()\r\nWindow.title(\"SBrick Remote Control v0.1\")\r\n\r\nB_North = Button(text = \"N\", command = NORTH)\r\nB_North.grid(row=0, column=1)\r\n\r\nB_West = Button(text = \"W\", command = WEST)\r\nB_West.grid(row=1, column=0)\r\n\r\nB_STOP = Button(text = \"STOP\", command = STOP)\r\nB_STOP.grid(row=1, column=1)\r\n\r\nB_East = Button(text = \"E\", command = EAST)\r\nB_East.grid(row=1, column=2)\r\n\r\nB_South = Button(text = \"S\", command = SOUTH)\r\nB_South.grid(row=2, column=1)\r\n\r\nscale = Scale(Window, from_=0.125, to=2.5, digits=3, resolution=0.125, orient=HORIZONTAL, length=250, label=\"Time\")\r\nscale.grid(row=3,column=0,columnspan=3)\r\n\r\nB_QUIT = Button(text = \"QUIT\", command = quit)\r\nB_QUIT.grid(row=4, column=1, )\r\n\r\nmainloop()<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uma incurs\u00e3o r\u00e1pida em Python e Tkinter (uma library para aplica\u00e7\u00f5es GUI muito f\u00e1cil de usar no modo Google-Copy-Paste) para poder comunicar com o SBrick a partir do meu laptop Ubuntu sem usar a linha de comando: #!\/usr\/bin\/env python from Tkinter import * from time import sleep from subprocess import call def quit(): \u00a0 global &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2014\/sbrick-remote-control\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;SBrick Remote Control&#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":[18,20],"tags":[217,219,223,225],"series":[],"class_list":["post-729","post","type-post","status-publish","format-standard","hentry","category-lego","category-linux","tag-ble","tag-bluetooth","tag-python","tag-sbrick"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-bL","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/729","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=729"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/729\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=729"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}