index.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <!DOCTYPE html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="generator" content="Hugo 0.88.0" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="/assets/css/theme.css">
  8. <link rel="alternate" href="/rss.xml" type="application/rss+xml" title="Pleasant Programmer">
  9. <script type="text/javascript" src="//use.typekit.net/iwm5axp.js"></script>
  10. <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
  11. <title>Pleasant Programmer</title>
  12. </head>
  13. <body>
  14. <header id="header" role="banner">
  15. <div id="thomas">
  16. <img src="/assets/img/thomas.gif" alt="DJ THOMAS IN DA HAUS">
  17. <img src="/assets/img/thomas.png" alt="Pleasant Programmer">
  18. </div>
  19. <h1 class="site-title"><a href="/">Pleasant Programmer</a></h1>
  20. <nav id="menu" role="navigation">
  21. <ul>
  22. <li class="twitter">
  23. <a href="http://twitter.com/pleasantprog">@pleasantprog</a>
  24. </li>
  25. <li><a href="/pages/projects.html">projects</a></li>
  26. <li><a href="/posts.html">archives</a></li>
  27. <li><a href="/tags.html">tags</a></li>
  28. <li><a href="/rss.xml">rss</a></li>
  29. </ul>
  30. </nav>
  31. </header>
  32. <div id="container">
  33. <main id="content" role="main">
  34. <div class="postindex">
  35. <article class="h-entry post-text" itemscope itemtype="http://schema.org/Blog">
  36. <header>
  37. <h1 class="p-name entry-title" itemprop="headline">
  38. <a href="/posts/android-multisim.html" class="u-url">Android Multisim Pre-5.1</a>
  39. </h1>
  40. </header>
  41. <div class="e-content entry-content">
  42. <p><strong>NOTE</strong> if you&rsquo;re just looking for a library to use, there&rsquo;s <a href="https://github.com/UseHover/MultiSim">MultiSim</a>. I&rsquo;ve never used this so I can&rsquo;t guarantee anything about it. It also only supports SIM information and not SMS.</p>
  43. <p>Phones that can take multiple SIM cards are quite popular in the Philippines. The two major telecoms would have unlimited SMS packages for messages within their networks. It was quite common to have a SIM for each telco and use the appropriate one depending on who you were sending to.</p>
  44. <p>Android&rsquo;s API only officially supported multiple SIM cards in 5.1 (API level 22) but Android phones with dual-SIM (and even triple-SIM) capabilities were already available at least as far back as 2.3 (API level 10) when I first needed to support it. Since there was no official API for this, the manufacturers just invented their own and of course each one implemented it in a different way.</p>
  45. <h2 id="mediatek">Mediatek</h2>
  46. <p>The first phone we started working on was a <a href="https://www.gsmarena.com/lenovo_a60-4711.php">Lenovo A60</a> which used a Mediatek SOC. We somehow got a library from the manufacturer that let us use the dual-SIM functionality, but it was quite a pain to get working as there was limited documentation and we were quite new to Android development at the time.</p>
  47. <p>When we disassembled the library that they gave us, we noticed that the names they used for the additional functions were quite interesting. They were all the <code>TelephonyManager</code> and <code>SmsManager</code> methods with a <code>Gemini</code> suffix and they would take an additional <code>int</code> parameter in addition to the original.</p>
  48. <p>It turned out that these were available on the standard <code>TelephonyManager</code> instance and could be accessed via reflection. The <code>SmsManager</code> was a bit trickier but we ended up figuring out that there was a <code>android.telephony.gemini.GeminiSmsManager</code> class that had the functionality.</p>
  49. <p>In a different phone with a Mediatek SOC, this got renamed to <code>com.mediatek.telephony.gemini.SmsManager</code> for some reason and dropped the <code>Gemini</code> suffix only for the <code>SmsManager</code>.</p>
  50. <h2 id="intel">Intel</h2>
  51. <p>It was also around this time that Intel started making SOCs for smartphones. We had an <a href="https://www.gsmarena.com/asus_fonepad_7_%282014%29-6394.php">ASUS Fonepad 7</a>. Unlike with the Mediatek device, we didn&rsquo;t have a library to use here and had to use reflection to find the hidden classes / methods.</p>
  52. <p>What we found was that instead of having a single instance with every method taking a <code>sim</code> parameter, they instead had separate instances of <code>TelephonyManager</code> and <code>SmsManager</code> for each SIM. You would call <code>TelephonyManager.get2ndTm()</code> and <code>SmsManager.get2ndSmsManager()</code> to have access to the 2nd SIM.</p>
  53. <h2 id="qualcomm">Qualcomm</h2>
  54. <p>The last phone I looked at was a <a href="https://www.gsmarena.com/motorola_moto_g_dual_sim-5978.php">dual-SIM Moto G</a>. What&rsquo;s interesting about this one is that the API completely changed in the upgrade from 4.4 to 5.0.</p>
  55. <p>On Android 4.4, the API was pretty close to the Mediatek one. You had a single instance that could dispatch to other SIMs by having an extra parameter on all the methods. These were in <code>android.telephony.MSimTelephonyManager</code> and <code>android.telephony.MSimSmsManager</code>.</p>
  56. <p>On Android 5.0, the API was a weird mix of all the above and also the introduction of <code>android.telephony.SubscriptionManager</code> which was quite close but not exactly the same as what ended up in the official API. Instead of <code>getActiveSubscriptionInfoList</code> there was <code>getActiveSubIdList</code> which only returned <code>long[]</code>.</p>
  57. <p>For the information that would normally exist in <code>SubscriptionInfo</code>, you had to query the main <code>TelephonyManager</code> instance which had methods with an extra <code>long</code> parameter for the subscription id. The <code>SmsManager</code> was simpler with just <code>getSmsManagerForSubscriber</code>.</p>
  58. <p>With Android 5.1, I assume they just switched to using the official API so this phone would have gone through 3 different multi-SIM APIs over the course of it&rsquo;s life.</p>
  59. <h2 id="epilogue">Epilogue</h2>
  60. <p>Around the release of Android 5.1, we stopped work on the app so I never actually got to use the official API myself ironically. We also never really got a big deployment so while I saw quite the variety of multi-SIM implementations, that&rsquo;s probably not all that&rsquo;s been out in the wild.</p>
  61. </div>
  62. <small class="dateline">Posted: <time class="published dt-published" itemprop="datePublished" datetime="2021-09-12">2021-09-12</time></small>
  63. | <small class="commentline"><a href="/posts/android-multisim.html#isso-thread">Comments</a></small>
  64. </article>
  65. </article>
  66. <article class="h-entry post-text" itemscope itemtype="http://schema.org/Blog">
  67. <header>
  68. <h1 class="p-name entry-title" itemprop="headline">
  69. <a href="/posts/isp-issues.html" class="u-url">ISP Issues</a>
  70. </h1>
  71. </header>
  72. <div class="e-content entry-content">
  73. <p>At the first office I worked at, we had 2 different ISPs. This was supposed to be for reliability, as one was fast but spotty, and the other was slow but reliable. Since they weren&rsquo;t <em>too</em> expensive, we just went and got both.</p>
  74. <p>We have monitoring setup to watch our office IPs from the outside so we could see how often the connection goes down. The interesting thing we found was that the fast and spotty connection had perfect uptime. Even when there was clearly no internet from the office, it was still &ldquo;up&rdquo; according to our monitoring.</p>
  75. <p>So we tried pinging our office IP using the other connection and to our surprise it was indeed up. There was even a webserver running on it (we only have VPN exposed). Apparently, it was someone elses CCTV admin page. We could actually see a hallway with people walking by sometimes!</p>
  76. <p>Apparently someone else had our IP address and nothing good comes from an IP conflict. This was completely baffling as our internet line was supposed to be a &ldquo;business line&rdquo; and that came with a static IP address. So the only scenarios where this could happen is, the ISP mistakenly gave the same IP to 2 different lines or the ISP allows some clients to freely set their own IP.</p>
  77. <p>We complained to the ISP and eventually got it resolved. They just gave us an entirely new IP address, but they never explained what went wrong. We already had quite a negative opinion of that particular ISP though, and they somehow managed to outdo themselves.</p>
  78. </div>
  79. <small class="dateline">Posted: <time class="published dt-published" itemprop="datePublished" datetime="2018-08-16">2018-08-16</time></small>
  80. | <small class="commentline"><a href="/posts/isp-issues.html#isso-thread">Comments</a></small>
  81. </article>
  82. </article>
  83. <article class="h-entry post-text" itemscope itemtype="http://schema.org/Blog">
  84. <header>
  85. <h1 class="p-name entry-title" itemprop="headline">
  86. <a href="/posts/audventure.html" class="u-url">Audventure</a>
  87. </h1>
  88. </header>
  89. <div class="e-content entry-content">
  90. <p>Sometime around 2013 I wrote a clone of the GBA game <a href="https://www.nintendo.co.jp/n08/bit_g/">bit Generations
  91. SoundVoyager</a> called
  92. <a href="https://audventure.pleasantprogrammer.com">audventure</a>. SoundVoyager is
  93. actually a collection of mini-games where sound is the main focus. You can
  94. actually play the game blind, and at some point, that&rsquo;s pretty much what
  95. happens.</p>
  96. <h2 id="sound-catcher">sound catcher</h2>
  97. <p>The signature mini-game in SoundVoyager is sound catcher. In the mini-game, you
  98. can only move left and right at the bottom of the stage, while a &ldquo;sound&rdquo; falls
  99. from the top. Your goal is to catch the sound which is signified by a green dot.
  100. When you catch it, the sound or beat becomes part of the BGM and a new dot
  101. appears with a different sound.</p>
  102. <p>You can of course use your eyes and move accordingly, but if you put on
  103. earphones, you can actually hear where the dot is, either on your left or right,
  104. with it getting louder as it gets close to you. As you collect more sounds, the
  105. dot gets more and more transparent. Eventually (and this is where it gets fun),
  106. you won&rsquo;t be able to see the sounds anymore and will have to rely mostly on your
  107. ears.</p>
  108. <p>You can see what the original game looks like in <a href="https://www.youtube.com/watch?v=C12WRgfIOC8">this
  109. video</a> or you can play it under
  110. <em>sound safari</em> in <a href="https://audventure.pleasantprogrammer.com">audventure</a>.</p>
  111. <h2 id="webaudio-vs-flash">WebAudio vs Flash</h2>
  112. <p>At the time I wrote audventure, only Chrome supported WebAudio. Also, the API
  113. looked (and still looks) quite complicated. Flash on the other hand, was
  114. starting to die, but still well-supported so I went with that. For the most
  115. part, it worked okay though Chrome actually had timing issues when playing
  116. sounds. Now, it doesn&rsquo;t work in any browser. I tried to debug the issues but
  117. ultimately ended up just rewriting it to use WebAudio instead.</p>
  118. <p>For the game, I needed to simulate the source of the sound in 2D/3D space. Flash
  119. only really gives you stereo panning and volume control. With some maths, we can
  120. actually get an acceptable solution. Less importantly, I needed to be able to
  121. get frequency data of the currently playing &ldquo;sound&rdquo; to pulse the background. For
  122. this, I actually had to implement the feature in the Flash library I was using.</p>
  123. <p>With WebAudio, spatial audio is already built-in and you can simply give it the
  124. coordinates of the sounds and the listener. There are some other options to
  125. tweak, but for the most part, no complex math is needed. Getting frequency data
  126. for a sound is also actually built-in and didn&rsquo;t take too long to integrate.</p>
  127. <p>Overall, I was impressed by how much you can do with WebAudio out-of-the-box. I
  128. kind of understand why it&rsquo;s complicated, but there&rsquo;s some simple functionality
  129. that I wish was included. For example, there is no API to pause and then resume
  130. playing an audio buffer. You have to manually save the elapsed time and play
  131. from there.</p>
  132. <h2 id="other-mini-games">Other mini-games</h2>
  133. <p>So far I&rsquo;ve only actually implemented the sound catcher mini-game. There are
  134. around 4 different categories with slight variations in between.</p>
  135. <h3 id="sound-catcher--sound-slalom">sound catcher / sound slalom</h3>
  136. <p>I&rsquo;ve explained sound catcher a while ago; sound slalom is a minor variation on
  137. that. Instead of waiting for the &ldquo;sound&rdquo; to reach you, you now have to guide
  138. yourself in between 2 &ldquo;poles&rdquo; of sound, as in <a href="https://en.wikipedia.org/wiki/Slalom_skiing">slalom
  139. skiing</a>. But this time, you can
  140. also accelerate forward. The goal is to finish the course before the time runs
  141. out.</p>
  142. <h3 id="sound-drive--sound-chase">sound drive / sound chase</h3>
  143. <p>In sound drive, you&rsquo;re driving against the flow on a 5 lane road. You have to
  144. avoid oncoming cars, trucks and animals until you reach the end. You&rsquo;re allowed
  145. to change lanes and accelerate, and the game tracks your best time. Sound chase
  146. is pretty much the same, except you&rsquo;re trying to catch up to a &ldquo;sound&rdquo;.</p>
  147. <h3 id="sound-cannon">sound cannon</h3>
  148. <p>In sound cannon, you&rsquo;re immobile but can rotate within a 180 degree angle. Your
  149. goal is too shoot down &ldquo;sounds&rdquo; which are heading your way. If a sound reaches
  150. you, it&rsquo;s game over. You win when you kill all the sounds.</p>
  151. <h3 id="sound-picker--sound-cock">sound picker / sound cock</h3>
  152. <p>In sound picker, you can move in a giant square field where various sounds are
  153. scattered around. Your goal is to pick up all the sounds within the time limit.
  154. Sound cock is similar, except the sounds are chickens and you have to chase them
  155. around.</p>
  156. <h2 id="source-code">Source Code</h2>
  157. <p>If you want to see the source code, you can check it out
  158. <a href="https://git.pleasantprogrammer.com/games/audventure">here</a>. The sound files
  159. aren&rsquo;t in the repo though, since I&rsquo;m not quite sure about the licensing. If you
  160. want to contribute music or sound effects, I&rsquo;d gladly appreciate it.</p>
  161. </div>
  162. <small class="dateline">Posted: <time class="published dt-published" itemprop="datePublished" datetime="2017-11-19">2017-11-19</time></small>
  163. | <small class="commentline"><a href="/posts/audventure.html#isso-thread">Comments</a></small>
  164. </article>
  165. </article>
  166. <article class="h-entry post-text" itemscope itemtype="http://schema.org/Blog">
  167. <header>
  168. <h1 class="p-name entry-title" itemprop="headline">
  169. <a href="/posts/openpreppad.html" class="u-url">OpenPrepPad</a>
  170. </h1>
  171. </header>
  172. <div class="e-content entry-content">
  173. <p>Smart electronics and IoT (Internet of Things) are all the rage these days. You
  174. have a lot of companies sprout up trying to make the next big thing, which also
  175. leads to a lot of failures big and small. Pebble, the maker of my smartwatch,
  176. got bought out by Fitbit recently. This left watch owners without any official
  177. support, but thankfully, community members <a href="http://rebble.io/">stepped up</a> to continue
  178. maintaining it.</p>
  179. <p>Another casualty of the IoT boom was the <a href="http://theorangechef.com/">Orange Chef</a> <a href="https://www.amazon.com/Orange-Chef-Smart-Scale-Silver/dp/B00KFW8L90">Prep Pad</a>. It&rsquo;s a
  180. bluetooth connected weighing scale to make it easy to track your calories and
  181. carb/fat/protein intake. My dad bought it last year only to find out that the
  182. app was incredibly buggy. The search function doesn&rsquo;t work which makes the whole
  183. thing practically useless. I also found out later that you can&rsquo;t even download
  184. the app to use the scale anymore.</p>
  185. <p><strong>Note</strong> I just found out as I was writing this post that it <em>may</em> get supported
  186. by <a href="http://www.prnewswire.com/news-releases/perfect-company-acquires-orange-chefs-prep-pad-related-ip-continues-momentum-in-the-connected-kitchen-300383178.html">another company</a>.</p>
  187. <p>So the app is useless, but at least you can use it as a scale, right?</p>
  188. <p><img src="/galleries/openpreppad/preppad.jpg" alt="Prep Pad"></p>
  189. <p>Nope. The device has no display whatsoever. The only controls on it are the
  190. on/off button and a green LED that isn&rsquo;t even that useful at telling you whether
  191. it&rsquo;s on or not. At this point, it&rsquo;s just a giant paperweight.</p>
  192. <h2 id="reverse-engineering">Reverse Engineering</h2>
  193. <p>Since I essentially had nothing to lose, I tried poking at the thing to figure
  194. out how it works. I didn&rsquo;t really have experience with bluetooth besides trying
  195. to get my bluetooth mouse connected on Linux. The main thing I used then was
  196. <code>bluetoothctl</code> which is essentially a CLI for managing bluetooth devices so I
  197. started there.</p>
  198. <p>I started up <code>bluetoothctl</code> and turned on the Prep Pad. And it showed up!</p>
  199. <div class="highlight"><pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">[bluetooth]# power on
  200. [CHG] Controller ... Class: 0x00010c
  201. Changing power on succeeded
  202. [CHG] Controller ... Powered: yes
  203. [bluetooth]# scan on
  204. Discovery started
  205. [CHG] Device 1C:BA:8C:21:7C:BB RSSI: -51
  206. [CHG] Device 1C:BA:8C:21:7C:BB Name: CHSLEEV_00
  207. [CHG] Device 1C:BA:8C:21:7C:BB Alias: CHSLEEV_00
  208. </code></pre></div><p>I then connected to it, which was surprisingly easy.</p>
  209. <div class="highlight"><pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">[bluetooth]# connect 1C:BA:8C:21:7C:BB
  210. Attempting to connect to 1C:BA:8C:21:7C:BB
  211. [CHG] Device 1C:BA:8C:21:7C:BB Connected: yes
  212. [CHG] Device 1C:BA:8C:21:7C:BB Name: CH BTScale_00
  213. [CHG] Device 1C:BA:8C:21:7C:BB Alias: CH BTScale_00
  214. </code></pre></div><p>Now normally, when you turn the device on, the green light flashes occasionally.
  215. Once I connected to it, the green light stayed on permanently. Clearly, I was
  216. making progress. A lot of services were also discovered but I had no idea what
  217. those things were at that point.</p>
  218. <p>After a lot of poking around, I could check the general device information. You
  219. could get the hardware, software and firmware version. There&rsquo;s also the device
  220. serial number which was nowhere on the actual physical device.</p>
  221. <div class="highlight"><pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">[CHSLEEV_00]# select-attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017
  222. [CH BTScale_00:/service0010/char0017]# attribute-info
  223. Characteristic - Firmware Revision String
  224. UUID: 00002a26-0000-1000-8000-00805f9b34fb
  225. Service: /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010
  226. Value: 0x31
  227. Value: 0x2e
  228. Value: 0x31
  229. Value: 0x33
  230. Value: 0x41
  231. Value: 0x00
  232. Flags: read
  233. [CH BTScale_00:/service0010/char0017]# read
  234. Attempting to read /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017
  235. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017 Value: 0x31
  236. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017 Value: 0x2e
  237. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017 Value: 0x31
  238. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017 Value: 0x33
  239. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017 Value: 0x41
  240. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0010/char0017 Value: 0x00
  241. 31 2e 31 33 41 00 1.13A.
  242. [CH BTScale_00:/service0010/char0017]#
  243. </code></pre></div><p>There was also a service which contained Accel Enable, Accel Range, Accel
  244. X-Coordinate, Accel Y-Coordinate, and Accel Z-Coordinate. I guess it stands for
  245. accelerometer, which is probably what it uses to weigh things.</p>
  246. <div class="highlight"><pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">[CHSLEEV_00]# select-attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026
  247. [CH BTScale_00:/service0023/char0024/desc0026]# read
  248. Attempting to read /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026
  249. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x41
  250. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x63
  251. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x63
  252. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x65
  253. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x6c
  254. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x20
  255. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x45
  256. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x6e
  257. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x61
  258. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x62
  259. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x6c
  260. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024/desc0026 Value: 0x65
  261. 41 63 63 65 6c 20 45 6e 61 62 6c 65 Accel Enable
  262. </code></pre></div><p>I couldn&rsquo;t read from any of the Accel Coordinates. It kept saying permission
  263. denied. I could however, notify on them. But that didn&rsquo;t yield anything as well.
  264. What I <em>could</em> read was Accel Enable, which was set to 00. I guess that means it
  265. was off. After writing 01 to Accel Enable, I found I could get values out of
  266. Accel X-Coordinate! Also, the green LED which was permanently on turned off.</p>
  267. <div class="highlight"><pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text">[CHSLEEV_00]# select-attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024
  268. [CH BTScale_00:/service0023/char0024]# write 01
  269. Attempting to write /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char0024
  270. [CH BTScale_00:/service0023/char0024]# select-attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a
  271. [CH BTScale_00:/service0023/char002a]# notify on
  272. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Notifying: yes
  273. Notify started
  274. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x5b
  275. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0xa3
  276. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x02
  277. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x00
  278. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x55
  279. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0xa3
  280. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x02
  281. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x00
  282. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x59
  283. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0xa3
  284. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x02
  285. [CHG] Attribute /org/bluez/hci0/dev_1C_BA_8C_21_7C_BB/service0023/char002a Value: 0x00
  286. </code></pre></div><p>I tried pressing the scale down a few times, and the values changed accordingly.
  287. Now, I just had to figure out how to convert the values into grams. It looked
  288. like the values were 32-bit integers sent as 4 bytes. In the above example it
  289. would be <code>0x0002a35b</code>, <code>0x0002a355</code>, <code>0x0002a359</code> or 172891, 172855, 172899. The
  290. values also decrease as you exert more effort on the scale. So assuming you take
  291. the initial value as <em>tare</em>, you simply subtract any succeeding value from that
  292. <em>tare</em> and you get the &ldquo;weight&rdquo;.</p>
  293. <p>The values I got didn&rsquo;t seem to be in grams though. After weighing some things
  294. on an actual scale and comparing the values I got, I found I can just divide the
  295. values by 14 and get something in grams. That 14 is entirely a magic number
  296. though and I have no idea whether other Prep Pad&rsquo;s would have the same constant.</p>
  297. <h2 id="openpreppad">OpenPrepPad</h2>
  298. <p>With all that figured out, I went ahead and made a <a href="https://github.com/thatsmydoing/openpreppad">simple CLI application</a>
  299. to interface with the Prep Pad. Ironically, node was the simplest thing I found
  300. that had <a href="https://github.com/sandeepmistry/noble">nice bluetooth library support</a> so that&rsquo;s what I wrote it in. I
  301. also added most of the technical details in the README for that as well.</p>
  302. <p>While this is all well and cool, I doubt the intersection of Linux users and
  303. people who <!-- raw HTML omitted -->got ripped off<!-- raw HTML omitted --> bought the Prep Pad is anyone besides me. In
  304. light of that, I&rsquo;m in the process of making a React Native version of the app,
  305. but that&rsquo;s still a work in progress. Who knows, if the new owners of Prep Pad
  306. are good, I might not even need to finish it.</p>
  307. </div>
  308. <small class="dateline">Posted: <time class="published dt-published" itemprop="datePublished" datetime="2017-01-15">2017-01-15</time></small>
  309. | <small class="commentline"><a href="/posts/openpreppad.html#isso-thread">Comments</a></small>
  310. </article>
  311. </article>
  312. </div>
  313. <nav class="postindexpager">
  314. <ul class="pager clearfix">
  315. <li class="next">
  316. <a href="/page/2.html">Older posts &rarr;</a>
  317. </li>
  318. </ul>
  319. </nav>
  320. </main>
  321. <footer id="footer" role="contentinfo">
  322. <p>
  323. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">
  324. <img alt="CC-BY-SA" style="border-width:0" src="https://licensebuttons.net/l/by-sa/3.0/80x15.png">
  325. </a> &copy; 2020 Thomas Dy - Powered by <a href="http://gohugo.io">Hugo</a></p>
  326. </footer>
  327. </div>
  328. <script src="/assets/js/konami.js"></script>
  329. <script>
  330. var easter_egg = new Konami();
  331. easter_egg.code = function() {
  332. var el = document.getElementById('thomas');
  333. if(el.className == "whoa") {
  334. el.className = "";
  335. }
  336. else {
  337. el.className = "whoa";
  338. }
  339. document.body.scrollTop = document.documentElement.scrollTop = 0;
  340. }
  341. easter_egg.load();
  342. </script>
  343. <script
  344. data-isso="https://isso.pleasantprogrammer.com/"
  345. src="https://isso.pleasantprogrammer.com/js/count.min.js">
  346. </script>
  347. </body>
  348. </html>