<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paul Contre on Medium]]></title>
        <description><![CDATA[Stories by Paul Contre on Medium]]></description>
        <link>https://medium.com/@paulcontre?source=rss-d8ded1af5630------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_AeU_Whp01x64393SAOO4A.jpeg</url>
            <title>Stories by Paul Contre on Medium</title>
            <link>https://medium.com/@paulcontre?source=rss-d8ded1af5630------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:09:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paulcontre/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I built Observe: a system monitor for your terminal]]></title>
            <link>https://medium.com/@paulcontre/i-built-observe-a-system-monitor-for-your-terminal-3d561215be58?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d561215be58</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[telemetry]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Mon, 13 Jul 2026 09:57:17 GMT</pubDate>
            <atom:updated>2026-07-13T09:57:17.585Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>A live terminal monitoring cockpit for CPU, memory, disk, network, ports, and busy processes.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*hIYUTxMCvj7hG19B.gif" /></figure><p>When something slows down on my machine, I usually open several commands to check CPU, memory, disk usage, network activity, ports, and running processes.</p><p>I wanted a simpler way to see everything in one place, so I built <strong>Observe</strong>.</p><p>Observe is an open-source terminal dashboard that shows what your machine is doing in real time.</p><p>It includes:</p><ul><li>CPU, memory, disk, and network usage</li><li>Processes using the most resources</li><li>Listening ports</li><li>Disk I/O and swap pressure</li><li>Docker container activity</li><li>Simple warnings for possible bottlenecks</li></ul><p>There is no account, database, agent, or initial configuration. Everything runs locally, and your system metrics are not uploaded anywhere.</p><h3>Install</h3><p>Using Homebrew:</p><pre>brew install pol-cova/homebrew-tap/observe</pre><p>Or using Go:</p><pre>go install github.com/pol-cova/observe@latest</pre><p>Then run:</p><pre>observe</pre><p>You can also monitor a remote machine over SSH:</p><pre>observe --ssh user@host</pre><p>Or save a diagnostic snapshot:</p><pre>observe snapshot --output diagnostics.json</pre><p>Observe is written in Go and released under the MIT license.</p><p>You can find the source code here: <a href="https://github.com/pol-cova/observe">https://github.com/pol-cova/observe</a></p><p>Feedback, issues, and contributions are welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d561215be58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Redesigned StrictBlock to Make Focus Feel Easier]]></title>
            <link>https://medium.com/@paulcontre/why-i-redesigned-strictblock-to-make-focus-feel-easier-7eaab0a1cea0?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eaab0a1cea0</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Sun, 21 Jun 2026 06:47:22 GMT</pubDate>
            <atom:updated>2026-06-21T06:47:22.227Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0jAXUn527r4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0jAXUn527r4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0jAXUn527r4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba2cb6a3cb1614fd1ae442390f2cdd6e/href">https://medium.com/media/ba2cb6a3cb1614fd1ae442390f2cdd6e/href</a></iframe><p>I redesigned StrictBlock because I wanted it to feel less like <strong>another productivity app</strong> and more like a<strong><em> real focus system.</em></strong></p><p><strong>StrictBlock</strong> is a strict iPhone app and website blocker built for people who struggle with procrastination, deep work, study focus, or spending too much time on distracting apps.</p><p>The first version worked, but I felt the experience could be much better. Blocking distractions is already a strong action, so the app needed to feel clear, calm, and intentional.</p><p>For the new version, I focused on making the user experience better from start to finish. Create a focus profile, choose what to block, start a session, and stay accountable while your distractions are out of reach.</p><p>The relaunch includes a complete redesign, Pomodoro sessions, weekly reports, streaks, trophies, widgets, a session journal, and stronger accountability around ending sessions early.</p><p>The biggest lesson from the redesign was simple: people do not need more productivity noise. They need fewer excuses between intention and action.</p><p>StrictBlock is my attempt to build that boundary.</p><p>Try the redesigned version here: <a href="https://apps.apple.com/app/apple-store/id6749779711?pt=127882070&amp;ct=peerlist&amp;mt=8">https://apps.apple.com/app/apple-store/id6749779711?pt=127882070&amp;ct=peerlist&amp;mt=8</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOgQ9hoxLvwulC6FGgSCqA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eaab0a1cea0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Button Remapping: Knowing When to Stop Reverse-Engineering]]></title>
            <link>https://medium.com/@paulcontre/button-remapping-knowing-when-to-stop-reverse-engineering-6e5757352c1c?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e5757352c1c</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Sun, 14 Jun 2026 10:22:17 GMT</pubDate>
            <atom:updated>2026-06-14T10:22:17.783Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part 5 of a series on building a native Razer mouse controller for macOS.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjrbuuBTUdwzhYCdgpeDVQ.png" /></figure><p>Last feature: remap the two side buttons. Make the forward one a left click, or copy, or whatever. Synapse does it, so the mouse can do it, so I just need the command. Right?</p><p>This is the part where I spent an evening getting the device to say yes and do nothing, then threw the whole approach away and solved it in a completely different place. I think the second half is the more useful lesson.</p><h3>The Firmware Hunt</h3><p>There’s no public table for “remap a DeathAdder V2 button.” So I built a probe tool: send an arbitrary class/id with arbitrary args, print the full response. Then I swept ranges of commands looking for anything that responded 0x02 (OK) and looked button-shaped.</p><p>I found the profile system. Class 0x05 and 0x06 commands all answered. There&#39;s a per-button read at 0x05 / 0x8A that echoes back which button you asked about. There&#39;s a write at 0x05 / 0x0A. Driver mode, profile slots, the works. It all looked exactly like where button bindings would live.</p><p>So I tried the obvious write: button 4, action type mouse, parameter left-click. Sent it.</p><pre>status: OK</pre><p>Pressed the button. Nothing changed. Read it back. Unchanged.</p><p>Tried it in driver mode first. OK. Nothing. Tried selecting the profile slot before writing. OK. Nothing. Tried five different argument layouts. Every single one came back 0x02. Every single one did nothing.</p><p>If you read part 3, you know exactly what this is. 0x02means the packet was well-formed and understood as <em>a</em>command. It does not mean it did what I wanted. I was writing into a void the firmware was politely accepting.</p><p>It got worse. One of my “reset to default” attempts used action type 0x00, which I assumed meant &quot;firmware default.&quot; It actually means <strong>disabled</strong>. I turned my own side button off and didn&#39;t realize for a minute why pressing it did nothing at all. (Fix: clear the profile slot entirely and let the firmware take back over. Or just unplug and replug.)</p><p>After an evening of this I had a pile of commands that all returned OK and a mouse whose buttons were exactly as unremapped as when I started. The firmware path was a wall. Without capturing real Synapse USB traffic on Windows to see the exact bytes, I was guessing, and the device’s “OK” gave me no signal to guess better.</p><h3>The Pivot</h3><p>Here’s the reframe that fixed it. I don’t actually need the <em>mouse</em> to remap the button. I need the button press to <em>do something different on my Mac.</em> Those aren’t the same problem, and the second one doesn’t involve Razer at all.</p><p>macOS lets you intercept input events with a CGEventTap. You watch for mouse button events, and when the one you care about fires, you swallow it and post a different event instead. This is how the commercial Mac mouse utilities do it. None of them reprogram firmware. They all sit in the event stream.</p><p>First I just needed to know which button number the OS sees for each side button. A listen-only tap that logs:</p><pre>let n = event.getIntegerValueField(.mouseEventButtonNumber)<br>print(&quot;otherMouseDown buttonNumber=\(n)&quot;)</pre><p>Pressed both side buttons. The forward one (near the wheel) is #4, the back one is #3. Now I can target them.</p><h3>Actually Remapping</h3><p>To <em>change</em> an event, not just watch it, the tap has to be active (.defaultTap), and that needs Accessibility permission, not Input Monitoring. Different permission, different System Settings pane. Worth knowing up front: a listen-only tap needs Input Monitoring, a tap that modifies or drops events needs Accessibility.</p><p>The handler: if it’s a button I manage and it’s mapped to something, swallow the original and synthesize the replacement.</p><pre>nonisolated private func handle(type: CGEventType, event: CGEvent) -&gt; Unmanaged&lt;CGEvent&gt;? {<br>    let button = Int(event.getIntegerValueField(.mouseEventButtonNumber))<br>    let action: MouseAction<br>    switch button {<br>    case 4: action = forwardAction<br>    case 3: action = backAction<br>    default: return Unmanaged.passUnretained(event)  // not ours<br>    }<br>    guard action != .passthrough else { return Unmanaged.passUnretained(event) }</pre><pre>    if type == .otherMouseDown { perform(action, at: event.location) }<br>    return nil   // swallow the original<br>}</pre><p>perform posts whatever you mapped to: a left click is a synthesized leftMouseDown/leftMouseUp, copy is ⌘C as a key event, and so on. Press the side button, the click happens where your cursor is. It just works, immediately, the first time, with no guessing about byte layouts.</p><h3>The Tradeoff, Honestly</h3><p>Software remapping isn’t strictly better than firmware remapping. The differences are real:</p><ul><li>It only works while my app is running. Firmware remapping would persist on the mouse, even on another computer or in a BIOS screen.</li><li>It’s Mac-only. The mouse’s own memory doesn’t know anything changed.</li></ul><p>For a menu bar app that launches at login, “only while the app runs” is basically always, so the tradeoff barely bites. And the firmware version had one fatal flaw the software version doesn’t: it didn’t work.</p><p>That’s the actual lesson from this whole feature. I spent an evening determined to solve the problem at the layer I’d decided it lived at. The device kept telling me OK and doing nothing, and I kept reading that as “almost there.” The fix wasn’t a better byte sequence. It was stepping up one layer to where the problem was tractable and the feedback was honest: press button, thing happens, or it doesn’t.</p><p>Reverse-engineering is fun right up until the point where it’s just you and a device that says yes to everything. Knowing when to stop is part of the skill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*Q5-jnhDnV2re2q03vLKsTQ.png" /><figcaption>the ui of the app</figcaption></figure><h3>Where This Lands</h3><p>Five parts in, the app does what Synapse does for the things I care about: DPI with presets, static and animated lighting, side button remapping, all from a menu bar icon, no Razer account, no background service phoning home. The protocol work was the interesting half. The honest half was admitting one feature didn’t belong in the protocol at all.</p><p>The full code is at <a href="https://github.com/pol-cova/RazerControl">github.com/pol-cova/RazerControl</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e5757352c1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wrapping It in a Menu Bar App (and Three Things That Broke)]]></title>
            <link>https://medium.com/@paulcontre/wrapping-it-in-a-menu-bar-app-and-three-things-that-broke-6e903efe36b4?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e903efe36b4</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[hardware]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Wed, 10 Jun 2026 07:18:03 GMT</pubDate>
            <atom:updated>2026-06-10T07:18:03.141Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part 4 of a series on building a native Razer mouse controller for macOS.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNxHGOm4o0MXIYZ8sqL-WQ.png" /></figure><p>The protocol works from a command line tool. Now I want it living in the menu bar: a little mouse icon, click it, set DPI and color, no Terminal. SwiftUI has MenuBarExtrafor exactly this, so it should be quick.</p><p>It was not quick. Three separate things broke, none of them about the mouse. This is the part where the OS fights you.</p><h3>The Crash Before Anything Renders</h3><p>The starting point. An accessory app (menu bar only, no Dock icon) usually sets that with:</p><pre>@main<br>struct RazerControlApp: App {<br>    init() {<br>        NSApp.setActivationPolicy(.accessory)<br>    }<br>    var body: some Scene { ... }<br>}</pre><p>Launched it. Instant crash:</p><pre>Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value<br>RazerControlApp.swift:15</pre><p>NSApp is NSApplication!, an implicitly unwrapped optional. It&#39;s nil this early. The app object&#39;s init() runs before the shared application is set up, so NSApp is still nothing and the force-unwrap explodes.</p><p>This bites harder on newer projects because the default actor isolation is MainActor, and the timing of init()lands before NSApp exists. You can fight the lifecycle, or you can not use code for this at all.</p><p>The fix is a plist key. LSUIElement = YES (in build settings, INFOPLIST_KEY_LSUIElement). It&#39;s read by the launch machinery before your App struct is ever created, so there&#39;s no race and no NSApp to unwrap. Delete the init()entirely.</p><pre>INFOPLIST_KEY_LSUIElement = YES</pre><p>No code, no crash, no Dock icon. The thing I was writing code to do was a setting the whole time.</p><h3>macOS Won’t Let the App Touch the Mouse</h3><p>App launches now. Connects to the device. Immediately:</p><pre>TCC deny IOHIDDeviceOpen<br>RazerControl: device not found</pre><p>IOHIDDeviceOpen on a mouse needs Input Monitoring permission. The command line tool worked the whole time because it ran from Terminal, and Terminal already had Input Monitoring. A fresh signed .app has nothing.</p><p>macOS won’t pop the permission dialog on its own. You have to ask, explicitly, with the right call:</p><pre>let access = IOHIDCheckAccess(kIOHIDRequestTypeListenEvent)<br>if access == kIOHIDAccessTypeUnknown {<br>    IOHIDRequestAccess(kIOHIDRequestTypeListenEvent)<br>} else if access == kIOHIDAccessTypeDenied {<br>    // user said no earlier — send them to System Settings<br>}</pre><p>kIOHIDRequestTypeListenEvent is imported as a plain constant, not a Swift enum case, so it&#39;s kIOHIDRequestTypeListenEventand not .listenEvent. That cost me a compile error and a confused minute.</p><p>First launch now shows the system prompt. If the user denied it before, the prompt won’t come back, so the app needs to detect that case and point them at System Settings rather than silently failing.</p><h3>MenuBarExtra Has Two Personalities</h3><p>The popover opened, but the layout was wrong. Everything stacked vertically like a dropdown menu. My HStack of buttons rendered as separate rows. The color picker wouldn&#39;t open. Frame widths were ignored.</p><p>MenuBarExtra has two render styles. The default is .menu, which puts your content inside a real NSMenu, so every view becomes a menu item and normal layout doesn&#39;t apply. The other is .window, which renders your SwiftUI in an actual floating panel where layout works like everywhere else.</p><pre>MenuBarExtra(&quot;RazerControl&quot;, systemImage: &quot;computermouse.fill&quot;) {<br>    MenuBarView()<br>}<br>.menuBarExtraStyle(.window)</pre><p>One modifier. Suddenly HStacks are horizontal, widths apply, the popover looks like a popover. If your menu bar layout is behaving strangely, this is almost certainly why.</p><h3>The Color Picker That Wouldn’t Open</h3><p>Last one. SwiftUI’s ColorPicker renders a little well; click it and the system color panel opens. Except in my app, clicking did nothing.</p><p>ColorPicker relies on NSColorPanel. An accessory app (the LSUIElement thing from earlier) can&#39;t reliably bring up that panel, because it isn&#39;t allowed to become active the normal way, and the menu bar window dismisses the moment focus moves. So the panel either opens behind everything or never shows. The &quot;selection&quot; never happens, so the color never changes. One root cause, two symptoms.</p><p>I could have fought the activation policy. Instead I asked what a menu bar RGB control actually needs, and the answer is not a full color wheel. It’s a handful of good colors, one tap.</p><p>So I replaced the picker with a row of preset swatches:</p><pre>private let palette: [Color] = [<br>    .red, .orange, .yellow, .green, .cyan, .blue, .purple, .pink, .white<br>]<br>// tap a swatch -&gt; apply immediately, ring the selected one</pre><p>No NSColorPanel, no activation problem, and honestly better for a quick menu. Tap red, the logo&#39;s red. Done. The &quot;fix&quot; was less code and a nicer interaction than the thing that was broken.</p><h3>What’s Next</h3><p>Part 5 is the button remapping, which is the part I was most sure would be easy and turned out to be the hardest. I spent an evening trying to reverse-engineer the firmware command for it, got the device to accept my writes, and watched nothing happen. Then I gave up on the firmware entirely and solved it a different way. That story is its own post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e903efe36b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DPI, Color, and Why “OK” Doesn’t Mean It Worked]]></title>
            <link>https://medium.com/@paulcontre/dpi-color-and-why-ok-doesnt-mean-it-worked-35f0e08e5fce?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/35f0e08e5fce</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 22:57:03 GMT</pubDate>
            <atom:updated>2026-06-08T22:57:03.113Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part 3 of a series on building a native Razer mouse controller for macOS.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FByYUP3xwCkRgcDNPghuOQ.png" /></figure><p>We have the envelope from part 2. Now the commands that actually do something: DPI and lighting. The DPI one is easy. The color one taught me the most useful lesson in this whole project, which is that the device telling you 0x02 (OK) is not the device telling you it did what you wanted.</p><h3>Setting DPI</h3><p>Command class 0x04, id 0x05, data_size 0x07.</p><p>The value is the raw DPI, not divided by anything. 800 DPI is 0x0320, split into a high byte and a low byte. The mouse stores X and Y sensitivity separately, so you send the pair twice.</p><pre>func dpiReport(_ dpi: Int) -&gt; [UInt8] {<br>    let v = UInt16(dpi)<br>    var r = [UInt8](repeating: 0, count: 90)<br>    r[1]  = 0x3F<br>    r[5]  = 0x07<br>    r[6]  = 0x04          // class: DPI<br>    r[7]  = 0x05          // id: set DPI<br>    r[8]  = 0x00          // stage<br>    r[9]  = UInt8(v &gt;&gt; 8)   // X high<br>    r[10] = UInt8(v &amp; 0xFF) // X low<br>    r[11] = UInt8(v &gt;&gt; 8)   // Y high<br>    r[12] = UInt8(v &amp; 0xFF) // Y low<br>    r[88] = r[2...87].reduce(0, ^)<br>    return r<br>}</pre><p>This one is fire-and-forget. You don’t need to read a response. Set it, feel the cursor speed change.</p><h3>Reading DPI Back</h3><p>There’s a matching read command, class 0x04, id 0x85. Same idea, the id just has the high bit set, which is the convention for &quot;get&quot; versions of Razer commands.</p><p>I didn’t think I needed this until the GUI app shipped and immediately created a bug: every time you opened the app it reset your DPI to 800. The app had a default of 800 and pushed it on connect, stomping whatever you’d actually set.</p><p>The fix was to read the device’s real DPI on connect instead of forcing a default:</p><pre>func getDPI() -&gt; Int {<br>    // send class 0x04 id 0x85, read response<br>    let resp = request(...)<br>    return (Int(resp[9]) &lt;&lt; 8) | Int(resp[10])<br>}</pre><p>The DPI sits in the same byte positions in the response as you’d send it. Read first, then the UI reflects reality instead of overwriting it. Obvious in hindsight. Most of these bugs are.</p><h3>The Color Command That Lied to Me</h3><p>This is the part worth reading.</p><p>I wanted to set the logo and scroll wheel to a static color. I found a command that looked right, class 0x03, id 0x03, packed in the zone and an RGB triple, sent it. Got 0x02 back. OK. Accepted.</p><p>Nothing happened. The LED didn’t change.</p><p>I checked the CRC. Fine. Checked the transaction ID. Fine. Checked the bytes ten times. The device kept saying 0x02. Accepted, accepted, accepted, and the logo stayed the color it already was.</p><p>The problem: 0x03 / 0x03 is not &quot;set color.&quot; It&#39;s &quot;set LED brightness.&quot; I was setting the brightness to a value, the device was happily setting the brightness to that value, and reporting success. It just wasn&#39;t a color command at all. I&#39;d been sending a perfectly valid command for the wrong thing.</p><p>The real static color command for this device lives in a different family. Class 0x0F, id 0x02, the &quot;extended matrix effect&quot; commands. The layout:</p><pre>data_size = 0x09<br>args[0] = 0x01        // varstore<br>args[1] = led_id      // scroll = 0x01, logo = 0x04<br>args[2] = 0x01        // effect: static<br>args[3] = 0x00<br>args[4] = 0x00<br>args[5] = 0x01<br>args[6] = r<br>args[7] = g<br>args[8] = b</pre><p>Sent that. Logo turned green. First time the lighting actually moved.</p><p>The lesson stuck with me: a status of 0x02 only tells you the packet was well-formed and the device understood it as <em>a</em> command. It says nothing about whether it was the command you meant. A valid brightness-set and a valid color-set both return 0x02. If you&#39;re debugging by status code alone, you can burn an hour sending textbook-correct commands that do the wrong job.</p><h3>Effects Come for Free</h3><p>Once you’re in the 0x0F / 0x02 family, the other lighting effects are just a different effect byte at args[2]:</p><p>Effectargs[2]data_sizeOff0x006Static0x019 (+ rgb)Breathing0x029 (+ rgb)Spectrum0x036</p><p>Spectrum is the rainbow cycle. You set it once and the mouse firmware animates it on its own, no polling from your app. Breathing pulses a single color. Off goes dark. Same envelope, one byte different. After the static color fight, adding three more effects took about ten minutes.</p><h3>What’s Next</h3><p>Part 4 leaves the protocol behind and wraps all this in a SwiftUI menu bar app. That sounds like the easy part. It was not. There’s a crash that only happens because of a build setting, a permission macOS won’t grant without being asked in a specific way, and a color picker that refuses to open. The protocol was more honest than the UI framework.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35f0e08e5fce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Packet Format: 90 Bytes and One Cursed Byte]]></title>
            <link>https://medium.com/@paulcontre/the-packet-format-90-bytes-and-one-cursed-byte-4aaac583593a?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aaac583593a</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Sun, 07 Jun 2026 07:00:33 GMT</pubDate>
            <atom:updated>2026-06-07T07:00:33.657Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1kpjGIFaWZPnOkl1rLEdeA.png" /></figure><p><em>Part 2 of a series on building a native Razer mouse controller for macOS.</em></p><p>In part 1 we found the right HID interface and learned how to push a feature report at it. The report was just 90 zero bytes, which does nothing. This part is about what actually goes in those 90 bytes.</p><p>Every Razer config command uses the same fixed layout. Once you have the layout, every feature (DPI, lighting, polling rate) is just different values in the same envelope.</p><h3>The Layout</h3><pre>[0]      status<br>[1]      transaction_id<br>[2-3]    remaining_packets<br>[4]      protocol_type<br>[5]      data_size<br>[6]      command_class<br>[7]      command_id<br>[8-87]   arguments (80 bytes)<br>[88]     CRC<br>[89]     reserved</pre><p>When you send a command, byte [0] (status) is 0. When the device replies, it writes a status code back into byte [0]. Same buffer shape both ways.</p><p>The two bytes that pick what the command does are command_class ([6]) and command_id ([7]). Think of class as the subsystem (DPI, lighting, profiles) and id as the specific action inside it. Everything from byte 8 onward is arguments, and what they mean depends entirely on the class/id pair.</p><p>data_size ([5]) is how many of the argument bytes are meaningful. If your command uses 3 argument bytes, data_size is 3. Get this wrong and the device usually ignores you.</p><h3>The CRC</h3><p>Byte [88] is a checksum. It&#39;s an XOR of every byte from index 2 through 87, inclusive.</p><pre>report[88] = report[2...87].reduce(0, ^)</pre><p>That’s the whole thing. No polynomial, no lookup table, just XOR. If the CRC is wrong the device rejects the packet, and you’ll get a status that isn’t 0x02 or no response at all.</p><p>The range matters. It’s 2...87, not 0...89. The status and transaction ID at the front are excluded, and so are the CRC and reserved bytes at the end. I got this wrong the first time by including byte 1 and spent a while convinced my command bytes were the problem.</p><h3>The Transaction ID</h3><p>Byte [1] is the transaction ID, and it is the single most annoying byte in the whole format.</p><p>It’s not part of the command. It doesn’t change behavior. It’s a tag the device firmware checks before it will even look at the rest of the packet. If it’s wrong, the device acts like you said nothing.</p><p>The catch: the correct value is different across Razer devices, and nobody documents it per model. For the DeathAdder V2 it’s 0x3F. Other devices use 0xFF or 0x1F. There&#39;s no command to ask the device what its transaction ID is. You either know it or you guess.</p><pre>report[1] = 0x3F   // DeathAdder V2</pre><p>If you’re porting this to another Razer mouse and nothing works even though your command bytes look right, this is the first thing to change. Try 0xFF, then 0x1F, then 0x3F. One of them will start returning 0x02.</p><p>I hardcoded it. There’s no reason to make it configurable in the app, because a wrong value just means a dead command.</p><h3>A Real Command</h3><p>Here’s the firmware version request, which is the simplest useful command and a good first target because it returns data you can sanity-check:</p><pre>var report = [UInt8](repeating: 0, count: 90)<br>report[1]  = 0x3F   // transaction id<br>report[5]  = 0x02   // data_size<br>report[6]  = 0x00   // command_class: standard<br>report[7]  = 0x81   // command_id: get firmware<br>report[88] = report[2...87].reduce(0, ^)</pre><p>Send it, wait 300ms, read the response. If the stack is working, byte [0] of the response comes back 0x02, and the firmware version sits in bytes [9] and [10]:</p><pre>print(&quot;firmware: \(response[9]).\(response[10])&quot;)<br>// firmware: 2.0</pre><p>Seeing 2.0 print instead of 0.0 is the moment you know the whole chain works: right interface, right transaction ID, right CRC, right delay. Everything after this is just changing class, id, and arguments.</p><h3>What’s Next</h3><p>Part 3 builds the real commands on top of this envelope: setting DPI, reading it back, and the static color command that I got wrong twice before it worked. There’s a good lesson buried in that one about why “command accepted” doesn’t mean “command did anything.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aaac583593a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[USB HID on macOS: Talking to Devices with IOKit]]></title>
            <link>https://medium.com/@paulcontre/usb-hid-on-macos-talking-to-devices-with-iokit-0c51eafe05bd?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c51eafe05bd</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Mon, 01 Jun 2026 07:45:51 GMT</pubDate>
            <atom:updated>2026-06-01T07:45:51.159Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lo2heDlAHwGk7IPKR7xAtg.png" /></figure><p>USB HID (Human Interface Device) is the protocol your mouse, keyboard, and gamepad use to talk to the OS. Most of the time it’s invisible; The OS handles it and your app gets abstracted events.<br> <br>But HID also has<strong> feature reports</strong>: raw byte arrays you can send directly to a device outside of normal input events. Manufacturers use these for configuration. That’s how Razer Synapse sets DPI and RGB — and it’s what we need to replace it.<br> <br>On macOS, the API for this is<strong><em> IOHIDManager</em></strong> inside <strong>IOKit</strong>. No kernel extension required.</p><h4>Setup</h4><p>Command Line Tool target in Xcode, macOS, Swift. No sandbox add <strong>App Sandbox </strong>to entitlements and immediately remove it, or just confirm it’s not there. IOKit feature reports fail silently with sandbox on.<br> <br>Link <strong>IOKit.framework</strong> under <em>target → General → Frameworks</em> and Libraries.</p><pre>import IOKit<br>import IOKit.hid<br>import Foundation</pre><h4>Finding a Device</h4><p><strong>IOHIDManager </strong>takes a matching dictionary. At minimum, vendor ID and product ID.</p><pre>let manager = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))<br> <br>IOHIDManagerSetDeviceMatching(manager, [<br>    kIOHIDVendorIDKey:  0x1532,<br>    kIOHIDProductIDKey: 0x0084<br>] as CFDictionary)<br> <br>guard IOHIDManagerOpen(manager, IOOptionBits(kIOHIDOptionsTypeNone)) == kIOReturnSuccess else {<br>    print(&quot;failed to open manager&quot;)<br>    exit(1)<br>}<br> <br>guard let devices = IOHIDManagerCopyDevices(manager) as? Set&lt;IOHIDDevice&gt;,<br>      !devices.isEmpty else {<br>    print(&quot;device not found&quot;)<br>    exit(1)<br>}</pre><p>If you don’t know your device’s PID yet, filter by vendor ID only and print everything:</p><pre>IOHIDManagerSetDeviceMatching(manager, [kIOHIDVendorIDKey: 0x1532] as CFDictionary)<br>// ... open manager ...<br>for d in devices {<br>    let name = IOHIDDeviceGetProperty(d, kIOHIDProductKey as CFString) as? String ?? &quot;?&quot;<br>    let pid  = IOHIDDeviceGetProperty(d, kIOHIDProductIDKey as CFString) as? Int ?? 0<br>    print(&quot;\(name): 0x\(String(pid, radix: 16))&quot;)<br>}</pre><h4>The Multiple Interfaces Problem</h4><p>One physical USB device often enumerates as multiple HID interfaces. A Razer DeathAdder V2 shows up as four:</p><pre>page: 0x1 | usage: 0x6 | maxFeatureReport: 1<br>page: 0x1 | usage: 0x6 | maxFeatureReport: 0<br>page: 0x59 | usage: 0x1 | maxFeatureReport: 64<br>page: 0x1 | usage: 0x2 | maxFeatureReport: 90</pre><p>IOHIDManagerCopyDevices returns a Set. devices.first is non-deterministic you have a 1-in-4 chance of hitting the right interface. The wrong interfaces accept your data and do nothing with it. The send call returns 0 (success) and the device response is all zeros.</p><p>Print all interfaces first:</p><pre>for d in devices {<br>    let usagePage  = IOHIDDeviceGetProperty(d, kIOHIDPrimaryUsagePageKey as CFString) as? Int ?? 0<br>    let usage      = IOHIDDeviceGetProperty(d, kIOHIDPrimaryUsageKey as CFString) as? Int ?? 0<br>    let maxFeature = IOHIDDeviceGetProperty(d, kIOHIDMaxFeatureReportSizeKey as CFString) as? Int ?? 0<br>    print(&quot;page: 0x\(String(usagePage, radix: 16)) | usage: 0x\(String(usage, radix: 16)) | maxFeatureReport: \(maxFeature)&quot;)<br>}</pre><p>The interface you want for Razer configuration commands is the one with maxFeatureReport: 90 — that matches the 90-byte packet format Razer uses. Filter on it explicitly:</p><pre>guard let device = devices.first(where: { d in<br>    (IOHIDDeviceGetProperty(d, kIOHIDMaxFeatureReportSizeKey as CFString) as? Int ?? 0) == 90<br>}) else {<br>    print(&quot;control interface not found&quot;)<br>    exit(1)<br>}</pre><p>For other devices, the right interface depends on the protocol. maxFeatureReport size is usually the clearest signal.</p><h4>Opening and Sending</h4><p>After filtering, open the specific interface and send a feature report:</p><pre>guard IOHIDDeviceOpen(device, IOOptionBits(kIOHIDOptionsTypeNone)) == kIOReturnSuccess else {<br>    print(&quot;could not open device&quot;)<br>    exit(1)<br>}<br><br>var report = [UInt8](repeating: 0, count: 90)<br>// ... fill report bytes ...<br><br>let result = IOHIDDeviceSetReport(device, kIOHIDReportTypeFeature, 0, &amp;report, report.count)</pre><p>Two things that caused me problems here:</p><p><strong>Buffer size.</strong> IOHIDDeviceSetReport takes the report ID as a separate parameter (the 0 above). Do not prepend it to the buffer. If maxFeatureReport is 90, your buffer should be exactly 90 bytes. I was sending 91 and getting error -536850432 (0xE0005000) back from IOKit with no further explanation.</p><p><strong>Reading the response.</strong> The response comes back in a separate IOHIDDeviceGetReport call. The device needs a small delay between send and read — the amount varies, but 200–300ms works reliably:</p><pre>Thread.sleep(forTimeInterval: 0.3)<br><br>var response = [UInt8](repeating: 0, count: 90)<br>var responseLen = CFIndex(90)<br>IOHIDDeviceGetReport(device, kIOHIDReportTypeFeature, 0, &amp;response, &amp;responseLen)</pre><p>Use a fresh buffer for the response so you can tell whether the device wrote anything into it.</p><h3>Interpreting the Response</h3><p>For Razer devices, byte [0] of the response is a status code:</p><pre>| Value | Meaning |<br>|-------|---------|<br>| `0x00` | No response / read stale data |<br>| `0x01` | Device busy |<br>| `0x02` | Command accepted |<br>| `0x05` | Command not understood |</pre><p>0x02 means the full stack is working. 0x05 usually means wrong command bytes or wrong transaction ID for the device family.</p><p>If you get all zeros back, you either read too fast, hit the wrong interface, or the buffer size was wrong.</p><h4>What’s Next</h4><p>Part 2 covers the actual Razer packet format what goes in those 90 bytes, how the CRC is computed, and what the transaction ID is and why it matters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c51eafe05bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 5 MB Homework Limit That Turned Me Into an App-Builder]]></title>
            <link>https://medium.com/@paulcontre/the-5-mb-homework-limit-that-turned-me-into-an-app-builder-7fe8e988e6d3?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fe8e988e6d3</guid>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[building]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Fri, 01 Aug 2025 22:13:24 GMT</pubDate>
            <atom:updated>2025-08-01T22:13:24.526Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYuEx2pLVx10PISV8Xu-CA.png" /></figure><p>This semester I snapped a neat, high-res photo of my handwritten math assignment and went to upload it to my university platform.</p><p>Error: <strong>“File must be under 5 MB.”</strong><br>I tried again with a different angle — same error. Then the portal complained about the HEIC format my iPhone uses by default.</p><p><strong>What I tried next<br></strong>- Google results sent me to web compressors that wanted my personal photos on their servers (nope).<br>- The first “free” iOS app threw three ads at me before I could pick a file.<br>- A second app asked for $4.99 per month, just to shrink a picture!</p><p>I ended up opening Preview on my Mac, exporting, tweaking quality sliders, re-sending to my phone, and finally hitting “Submit” with seconds to spare. The whole thing took longer than writing the homework.</p><p>That night I wrote Crunch, an offline photo compressor that fixes the exact pain I felt.</p><p><strong>What Crunch does now<br></strong>- Shrinks JPEG, HEIC, PNG images by up to 70 %, totally on-device (no uploads)<br>- Converts formats so HEIC becomes JPG or PDF in one tap<br>- Cleans out location + EXIF data before you share a file<br>- Free: 10 photos a day. Pro: one-time $3.99 — no subscriptions, ever</p><p><strong>Try Crunch for iOS now:</strong> <a href="https://apps.apple.com/app/id6748700457">Crunch on AppStore</a></p><p>Follow me on x where I’m sharing progress, mistakes, your feedback will shape the next update — features, pricing, UX, anything.<br><a href="https://x.com/3nginuity">@3nginuity</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fe8e988e6d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Simple Password Generator with FastHTML]]></title>
            <link>https://medium.com/@paulcontre/building-a-simple-password-generator-with-fasthtml-81e8c842393b?source=rss-d8ded1af5630------2</link>
            <guid isPermaLink="false">https://medium.com/p/81e8c842393b</guid>
            <category><![CDATA[fasthtml]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[htmx]]></category>
            <dc:creator><![CDATA[Paul Contre]]></dc:creator>
            <pubDate>Sat, 24 Aug 2024 01:17:04 GMT</pubDate>
            <atom:updated>2024-08-24T01:21:34.358Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you looking to build a lightweight web application that’s both functional and stylish? In this tutorial, we’ll walk through creating a simple password generator using FastHTML — a minimalist Python-based HTML templating engine — and Tailwind CSS for sleek and responsive design.</p><h4><strong>🚀 What You’ll Build</strong></h4><p>We’ll create a web application that allows users to input the desired length of a password and generate a strong, random password on the fly. This tutorial is perfect for developers who want to explore FastHTML and HTMX, combined with the power of Tailwind CSS for simple front-end styling.</p><h4>👨‍💻 Prerequisites</h4><p>Before we dive in, make sure you have Python installed on your machine. We’ll be using the following libraries:</p><ul><li><strong>FastHTML:</strong> For our application.</li></ul><p>You can install the required library with:</p><pre>pip install python-fasthtml</pre><h4>🛠️ Step 1: Setting Up Your FastHTML App</h4><p>Let’s start by setting up our FastHTML application. FastHTML is a lightweight HTML templating engine that allows you to create HTML elements directly in Python, making your code clean and easy to manage.</p><pre># Importing libraries<br>from fasthtml.common import *<br>import string<br>import secrets<br><br># Defining the FastHTML app<br>app = FastHTML(<br>    hdrs=(<br>        # Add Tailwind CSS<br>        Script(src=&quot;https://cdn.tailwindcss.com&quot;),<br>    )<br>)</pre><p>Here, we import the necessary libraries and initialize our FastHTML app, embedding Tailwind CSS directly via CDN for rapid styling.</p><h4>🎨 Step 2: Creating the User Interface</h4><p>Next, we’ll design a simple form where users can input the desired password length. Tailwind CSS will make our form both functional and visually appealing.</p><pre>@app.route(&#39;/&#39;)<br>def home():<br>    title = &quot;Password Generator - With FastHTML&quot;<br>    form = Form(<br>        Input(id=&quot;length_input&quot;, type=&quot;number&quot;, placeholder=&quot;Enter the length&quot;,<br>              cls=&quot;border-2 border-gray-400 rounded-md p-2&quot;),<br>        Button(&quot;Generate&quot;, cls=&quot;bg-slate-900 text-white p-2 rounded-md mt-2&quot;),<br>        cls=&quot;flex flex-col items-center mt-10&quot;,<br>        hx_post=&quot;/generate&quot;,<br>        target_id=&quot;result&quot;,<br>        hx_swap=&quot;innerHTML&quot;<br>    )<br>    result = Div(id=&quot;result&quot;, cls=&quot;text-center mt-10&quot;)<br><br>    return Title(title), Main(H1(title, cls=&quot;text-3xl text-center mt-10&quot;), form, result)<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*GvflVreo7DLngcOt_21kSA.png" /><figcaption>Simple User Interface</figcaption></figure><p>This function renders our homepage, which includes a form for password generation. The form leverages HTMX to send the input data to the server and dynamically update the result without a full page reload. This makes the user experience seamless and responsive.</p><h4>🔒 Step 3: Implementing the Password Generator Logic</h4><p>Now, let’s implement the logic to generate a secure password based on the user’s input.</p><pre>alph = string.ascii_letters + string.digits + string.punctuation<br><br><br>@app.route(&quot;/generate&quot;)<br>def post(length_input: int):<br>    length = length_input<br>    if length &lt; 8:<br>        return &quot;Password length should be greater than 8 characters&quot;<br>    password = &#39;&#39;.join(secrets.choice(alph) for i in range(length))<br>    return password</pre><p>In this snippet, we define the character set for our password and implement the generator logic. We ensure the password length is secure (minimum of 8 characters) and then generate a random password using Python’s secrets module, which is designed for cryptographic applications.</p><h4>▶️ Step 4: Running Your Application</h4><p>To get your app up and running, simply run the following command:</p><pre>if &#39;__main__&#39; == __name__:<br>    serve()</pre><p>Now, visit http://127.0.0.1:5001 in your browser, and you&#39;ll be greeted with your new password generator!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*hSSKVKzwzg6treKI4sR0QA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*WKb6k3rcHb-WtDojTumdiQ.gif" /><figcaption>Final Result</figcaption></figure><h4>🎉 Conclusion</h4><p>Congratulations! You’ve just built a fully functional password generator using FastHTML and Tailwind CSS. This project is a fantastic way to get acquainted with Python-based web development, HTMX for dynamic content, and Tailwind CSS for modern, responsive design.</p><h4>💾 Check Out the Full Source Code</h4><p>Want to dive deeper into the code or contribute to the project? The full source code is available on GitHub. Feel free to clone, fork, or star the repository:</p><p><a href="https://github.com/pol-cova/password-generator-fasthtml/">GitHub - pol-cova/password-generator-fasthtml: Simple password generator using FastHTML</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81e8c842393b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>