• Detour: iPad 2

    Yaky11/04/2024 at 02:34 0 comments

    Another old device I had laying around was iPad 2 (WiFi version), so I thought I could try to make that into an in-car display, too. (I specifically wanted to upcycle something I already had) But that did not work out as well as I had hoped.

    The original plan

    1. Mount the iPad to the central console, (partially) covering the built-in display.
    2. Install navigation software that works.
    3. Automate the software to wake (or power on) and launch a navigation app when the car is turned on, and go to sleep (or power off) when the car is turned off.
    4. Feed the video from reverse camera into the iPad and display it somehow.

    Compared to the setup I originally planned with an Android phone and a display, there are some advantages:

    • Interactive - This would not be just projecting a screen, I could interact with the app(s).
    • Single device - no need for additional cables, converters, etc. for projecting the screen.
    • Larger screen.
    • Better battery life.


    1. Mount the iPad

    The iPad fits rather nicely onto the central console:

    But since the built-in screen is covered, there's the minor inconvenience of being unable to see the radio station, or configure A/C.

    2. Navigation Software

    This was quite an adventure into jailbreaking, downgrading, and sketchy tools. There are only a handful of navigation apps that still work on old iOS versions

    As of right now, the iPad runs iOS 6.1.3 and uses CoPilot GPS. This required jailbreaking and some fixes to make the App Store usable again. Ironically, right after I installed many of the apps I needed, Apple irreversibly shut down the App Store for iOS 6. Instead of being on the cutting edge of technology, it seems I am on the blunt back edge.

    2.1 GPS

    This caught me by surprise. Since my version of iPad 2 is WiFi-only, it does not have a GPS chip. While at home, it happily showed my correct location (derived from known WiFi access points), so I paid no attention since most other devices that I had were phones with built-in GPS chips. But when I tried the iPad out on the road, it was clear there is no GPS chip.

    I bought a cheap used bluetooth GPS module, hoping to use that. However, using bluetooth as a GPS source on iOS requires a jailbreak (which I already had), and BTStack GPS, an app from Cydia. However, this is a paid app, and Cydia's purchases have been broken for years. I tried looking for workarounds and "fixes" but did not find any.

    After some more searching, I found out about high-accuracy BadElf GPS modules, early models of which had a 30-pin "dock" connector for early iPhones and iPads. All of their plug-in devices have been discontinued, but by sheer luck, I found the one I need on eBay. Combined with their official app, the GPS location works pretty well.

    3. Automation

    The Activator app from Cydia is very flexible, allowing to map almost any action to an event. The only thing it is missing is automating gestures. What I set up:

    • On power connected (car turns on): wake, unlock the lock screen, launch BadElf app (to wake/enable the GPS module), then launch Copilot GPS app for navigation.
    • On power disconnected (car turns off): simulate pressing the power button, putting the iPad into sleep.
    • Swiping on the status bad increases or decreases the brightness.

    3.1 External Input

    iPad obviously does not have external GPIO or any intentional way to read external input (from another circuit for example), but I was able to hack together an external on/off trigger using the phone jack and Activator's events for connecting and disconnecting headphones. The way headphone detection works in this iPad is checking if two contacts on the opposite sides on the phone jack are closed (connected by a conducting material). Building a "plug" out of two parallel, non-connected wires allows me to short these two wires using an external circuit to trigger an event within the iPad.

    The intent is to use an external trigger (gear shifter in R position) to trigger the iPad to display the feed from the rear camera.

    4. Video Input

    Since I want to use the in-car device...

    Read more »

  • Map: Android device setup

    Yaky05/17/2024 at 01:49 0 comments

    To display maps, I need a device that has:

    • GNSS/GPS receiver
    • Offline maps
    • Video output

    My trusty and crusty old Samsung Galaxy S5 has all that functionality, even video output to HDMI via MHL.

    What I want the device to do is:

    • Boot as soon as I start the car (i.e. device is connected to power).
    • Launch a navigation app after booting.
    • Shut down if the car is off for some time (i.e. device is not connected to power but has some battery left)

    For the map/navigation application, I chose Organic Maps, as it is lightweight, has a great interface, and works offline. I have used it for many years now.
    Other options I considered:

    • OsmAnd - more customizable, the OG of OpenStreetMap navigation
    • Osmin - similar to Organic Maps, and works great on Linux (Raspberry Pi, PinePhone etc.)

    Boot on plug

    The recommended method is to enable this function through fastboot. This does not work on Samsung devices, though, but I will leave it here for reference.
    Boot to fastboot mode (aka download mode) on the device.
    Install fastboot on main machine and run:

    fastboot oem off-mode-charge 0
    

    Since my device is a Samsung, I rooted it with Magisk, and then downloaded and installed Magisk Autoboot module. Although their documentation states it works for Android 7, I could not get it to work with custom Lineage 14 (Android 7 equivalent) for some reason. On a clean Lineage 15, it works, and S5 takes about a minute to boot after connecting power.

    Launch app after boot

    I installed Termux and Termux:Boot via F-Droid, and ran Termux:Boot once to initialize it.

    Per instructions, I created a startup script:

    mkdir -p ~/.termux/boot
    nano ~/.termux/boot/start-maps.sh
    

     And set the script to start Organic Maps:

    #!/data/data/com.termux/files/usr/bin/sh
    am start app.organicmaps/.SplashActivity

    This should also be possible to implement using Tasker, but I have not tried this. Might be easier if you don't like the terminal.

    According to a StackExchange post:

    • Create a Profile Event / System / Device Boot
    • Create a Task with Action: App / Launch App / (select the app)
    • Tasker also recommends adding Task - Wait for around 5 seconds first before doing other tasks to ensure that the system is ready after booting.
    • Link the Profile to the Task

    Shutdown on condition

    I implemented this using Termux, Termux:API and crontab.
    This requires root, because shutdown is a system function.

    To check the battery status, I used Termux and Termux:API extension:

    termux-battery-status

    This returns JSON, which can be parsed using jq.

    pkg install jq

    Now I can extract the values I need, for example:

    batt_pct=`termux-battery-status | jq -r '.percentage'`
    batt_status=`termux-battery-status |jq -r '.status'`

    To shut down Android:

    su -c "reboot -p"     

    Note: There are multiple ways to shut down an Android device, and many of those commands work fine in user's Termux session, but are very slow and buggy when they are run through crontab.

    Putting it all together: (with an extra spoken message using another API)

    batt_pct=`termux-battery-status | jq -r '.percentage'`
    batt_status=`termux-battery-status |jq -r '.status'`
    if [ $batt_pct -lt 60 ] && [ "$batt_status" = 'DISCHARGING' ]
    then
        termux-tts-speak 'Low power. Shutting down.'
        su -c "reboot -p"
    fi
    

    I put this in a file at

    /data/data/com.termux/files/usr/bin/yaky-auto-shutdown

    This directory is in $PATH, so there is no need to specify the full path in the future.

    To automate this script, I used crontab:

    pkg install cronie
    crontab -e

    Added an entry to run the auto-shutdown script:

    * * * * * yaky-auto-shutdown

    To run the cron daemon, I added another script to execute at boot:

    nano ~/.termux/boot/start-cron.sh

    And the script is:

    #!/data/data/com.termux/files/usr/bin/sh
    termux-wake-lock
    crond
    

    This sets a wakelock (to prevent Android from killing the long-running crond process), and then launches crond.
    Every minute, cron runs the script, which checks the battery percentage and status, and shuts down the device if the specified conditions are met. Although shutdown command requires root, root privileges...

    Read more »