Thursday, June 06, 2019

Declarative UI - SwiftUI

I’ve been super impressed with the new SwiftUI framework, with the admirable aims of:
  • Declarative, meaning that we say what we want rather than how we get there.
  • Automatic, meaning that it takes care of many things we had to do by hand previously.
  • Compositional, meaning that we build small things and combine them together into larger things.
  • Consistent, meaning that we don’t see strange fault lines between Swift and Objective-C like we did previously, or very old APIs mixed up with very new ones.

For example, here’s some SwiftUI from the examples:

I can’t help but think back to some other UI declarative tools I’ve used in the past … for example, using Dialog Tag Language (DTL) back in the day (ok, in the '80s):

which produces the screen like this:

I know that SwiftUI takes the declaration to a sophisticated, modern level, but it's good to see good ideas come back into use.

Thursday, January 01, 2015

Merging Garmin Heart Rate data with Activities

I was lucky enough to receive a Garmin Vivofit recently and am really happy with it so far.

It does a good job for what it's meant to do. My primary use is for Heart Rate monitoring when exercising, but I'm also interested in the step counts and goals.

I haven't used the Garmin Connect website in a while - and it's latest incarnation has quite a pleasing design.

One thing I quickly realised though is that there is still no way to combine the data from my  Garmin Edge 200, and my HR data - either from my Vivofit or Garmin FR60.

You can synchronise each activity fine, but not combine them - well, at least I couldn't see an easy way to do this. Please correct me if I'm wrong.

A little googling showed that this is quite a common problem, and naturally enough there were a number of solutions as well.

Essentially it provided a simple XSL transform to merge the two files. There was also a subsequent little java app which embedded the transform and provided a simple little GUI.

The results for me did not work however. Not sure if it was just me, or that the schema had since changed.

I was keen to get the HR data on the same display though, so spent an afternoon tinkering.

The process I used to get started was:
  1. Synchronise the clocks from the Garmin Edge 200, and that of the FR60. You need to use the Edge 200 as the source - since it is based on the GPS clock, and hence you can't change this one.
  2. Went for a ride, starting the activities at more or less the same time
  3. Synchronise each device with the Garmin Connect
  4. Retrieve each activity as a TCX file
I now had some data to work with.

The raw Cycle file looked like this:

You can easily see the straight forward capture of each tracking point.

The HR data is very similar:
Again, very straight forward. 

I took a very standard approach to tinkering ... manipulate the file - manually at first - until you get a format that's acceptable to the Garmin Connect uploader.

At first, I tried the simplest thing - of copying in all track points containing HR data - after the cycle ones. Which didn't work.

Next try was to adjust every Cycle tracepoint to include a HR data point - which was just a constant. To validate this, a simple all change via Sublime Text did the trick. I also manually added the HR summary data to the Lap header information - and ... success.

So now I knew what the format should be - and it was just a simple matter of programming to write an app to do that.

I dusted off some old familiar tools:
  • Eclipse
  • Java
  • JDOM for xml handling
The main thing I wanted do was to drive the process from the Cycle data - after all, we simply wanted to annotate each cycle track point with the most appropriate HR data point.

The high level view is to:
  • read the Cycle data
  • read the HR data
  • for each cycle track point
    • find the appropriate HR track point
      • if the HR data hadn't started yet - simply use the first one
      • or, if there is an exact match, use it
      • or, use the latest HR track point which is earlier than the cycle track point
      • or, if the HR data has ended prematurely - just use the last HR track point
    • add the HR element to the cycle element
  • extract the HR summary data and add it to the Lap header
Simple really.

The result is something like this:

The last remaining steps were to:
  • remove the Cycle activity from Garmin Connect
  • upload the newly combined activity - which has the same internal activity ID
And then - Garmin Connect displays the data as I wanted to:

As an added bonus, you can click on the dual arrows to the right of each chart - to then select a larger zoomed display - and overlay the other data:

I hope to tidy up the code soon, and post it to see if others would like to use it.

Saturday, November 30, 2013

iOS 7 - User Interface Quirks

I'm liking the new interface with iOS 7 ... but am still amazed by the lack of consistency.

It's even worse when Apple itself slips up. 

For example: my auto update setting updated the iBooks app recently, to version 3.2. In general, a cleaner, simpler look. But, I was surprised when I hit the Store button, and saw the icons along the tab bar at the bottom:

For some strange reason, the current tab has a glow effect - in addition to the blue highlighting. Strange.

What makes it even stranger is the lack of glow in other apps. For example, here's the App Store - showing the version history for iBooks itself ... 

Strange indeed.

For reference, the Apple design guidelines for tab bar icons are here.

Friday, January 04, 2013

Irrigation Repair 101

Third in my series of home repair items ... the rain sensor for my irrigation system. The function of the sensor is to detect rain - and then inhibit the operation of the irrigation system for a period of time, so that the system is not on unnecessarily.

It had needed to be relocated from it's old position - and as part of reconnecting it, I though I'd test it as well.

Unfortunately, it didn't want to work in the new location. Rather than buy a new one, I thought I'd open it up and see what the problem could be.

They are quite simple devices ...

  • a sensor, which consists of a number of fabric type discs stacked on a rod
  • when the discs are exposed to water they expand
  • which in turn presses a micro switch
I disassembled the unit - and tested the micro switch - which was all ok. This particular one has the three leads: 
  • one common
  • one for a normally open circuit
  • one for a normally closed circuit
This picture shows the bottom of the pole protruding into the chamber which houses the micro switch.
The discs themselves also seemed fine. I gave everything a clean, and reassembled.

And here finally is the result - the irrigation controller showing the rain symbol.
I can only guess that the process of relocating the sensor disrupted it in someway. But, a working sensor makes for a happy gardener.

Sunday, October 07, 2012

Door Chime Repair 101

Following on my theme of repair, rather than throw away and replace ... my attention turned to my door chime - which had not been working properly for a while.

It's a simple model - an Arlec DC371 - $35 retail. After changing batteries in the receiver and transmitter, it was still not cooperating. But, in looking around inside the transmitter, I inadvertently pushed the button to select the tunes - and it sprang in to life.

So, I knew we had some basic functionality. I returned to the circuit board, and inspected the main micro-switch for the pushbutton. It had two leads protruding from the other side of the circuit board - so I shorted the switch output with a screw driver, and hey presto - it worked.

The cuplrit was the micro-switch. And they don't call them micro for nothing.

It looked a little daunting. The top plastic retainer was fixed by 4 little plastic lugs. I sliced those off, and underneath was a small plastic button, sitting on top of a flexible metal disc - which was slightly convex, so that it clicked when depressed.

Under the disc were 3 contacts - two at the sides, and one in the middle. When the disc was pressed, it closed the circuit between these contacts. I removed the disc, and tried shorting the contacts with a screw driver but this didn't seem to work.

I gave the contacts and the disc a good scrape with a sharp knife, and a clean with some vinegar. And this seemed to be enough to allow the contacts to work. Result.

The tricky part was re-assembling the switch, since I'd cut off the tops of the lugs. I turned to my trusty super glue - but the first attempt failed - since it seemed to find it's way in to the mechanism.

I broke it down again, cleaned the parts, and tried again. This time was successful.

So, it's now back in operation. No more complaints from family and friends that the door bell isn't working.

I know I could have bought a new one ... but it's the principle, right?

Thursday, June 28, 2012

Helvetica and Italics - at Central Station

Ok, so I've been meaning to put this up for a while. As a follow on from this post: commuting-with-helvetica ... I've realized that the station I'm at every day - Central - is a prime culprit of the Helvetica / Italics phenomenon.

I would love to know why:

  • people do this
  • how Queensland Rail can roll out a rebranding exercise, and not have consistent signage.
To recap - here's the original picture from Graceville station:

Monday, June 04, 2012

Toaster Repair 101

Dualit Combi
This is the story of one of my favorite kitchen appliances ... my Dualit toaster.

It's a Combi 2+1 model, and has given almost 20 years of faithful service - until the other day when the centre element shorted and died. Needless to say, it caused a bit of a calamity in our household. I've had it since the early nineties, when it was received as a gift from a wonderful friend in London.

Fortunately, I’ve long known that the simplicity of it’s design is one of it’s virtues. No electronic circuits. No fancy lights or displays. Just a simple mechanical timer. And most importantly, nearly all of the internal parts are user serviceable. I turned to Google in the first instance but was surprised to find no local distributor of parts in Australia.

But I did find what seemed to be a fairly reputable distributor with quite a shop front on EBay in the United Kingdom. I downloaded the instruction manual as a PDF document - which illustrated how to access the slots which hold the toaster elements. And how to replace the elements as well. This also showed the simple coding scheme which allowed me to match up my broken part with the appropriate replacement. I placed the order (which was around 20 dollars) and received it about 7 days later.

Inside - showing slots

I needed to wait until the weekend to find the time to devote to the replacement process - which is ok, since that’s when our major toasting happens.

I'm pleased to say that the operation went without a hitch.  The only issue is that the centre element is more efficient than the sides, leading to a slightly less even toasting result - perhaps I should have ordered replacements for all of the elements at the same time.

But, it does make you think. The fact that this and many other parts could be replaced didn’t happen by accident - it was designed in.

It also reminds me of an article in the New York times I’ve read recently, which highlighted a concept of ”Repair Cafes” in Amsterdam. The article is here:

These are places where members of the public can bring broken appliances and a team of volunteers attempt to fix them. What a great idea.

Imagine what could happen if we had products which are designed to be repaired - and communities to help support them.