Wednesday 5 October 2011

Metawatch phone based watch menus

So a common request is to add the ability to send a menu to the phone and have the phone draw it and send back the users selection. My first attempt at this is shown below.

To use it send a Message type "GeneralPurposeWatchMsg" with option set at 0x43. The length set to max and the first byte of the string is the Length of the original string in characters. The rest of the payload is a Huffman encoded space separated list of strings. These represents the menu items to display. The huffman encoding uses a fixed tree based on the frequency of characters in the English language. This allows us to send all the text in one message and hopefully keep latency to a minimum. I haven't got around to writing the java to encode the string but I have written a python script that generates the bye sequence needed for a given string which you can then place in a payload and send. For example to menu shown above (Ignore the bad layout that will be fixed!) the strings would be "toggle next back volup voldown". this string is 30 characters long so too long to fit in our payload but once encoded takes up just 20 characters.

On selection the watch sends back a GeneralPurposePhoneMsg with the type set to 0x43and the index of the menu item selected as the first byte of payload.

It's possible that menus with more items more like a list view would be required and up and down could be used to select items. This would be more useful for browsing music on the phone or other larger datasets.
I'll maybe have a go at this tomorrow.

Tuesday 4 October 2011

Metawatch Music Controls in Firmware

Metawatch kinda has music controls but they can be kinda flaky. With my menu system in my modified firmware it was very easy to add. First I needed to send music messages to the watch but as you can't define your own messages i chose to use "GeneralPurposePhoneMsg" with an option of 0x42. The first byte in the payload would be the action. I used the constants already defined in MediaControl class.

I then added a Music menu to my firmware which took all of 10 minutes. This has none of the problems with the phone defined shortcuts overriding items. I'm in the middle of a refactor of the firmware and plan to have multiple home screens like the android launcher with the music controls being one.




All this code can be seen in these two commits:-

https://github.com/garthy/MetaWatch-WDS11x-IAR/commit/acae64ff3b50c028415405f4a9faf54691400a5f
https://github.com/garthy/MWM-for-Android/commit/89574c66b9a231b8886b33a0d8a6f24d8834b27b

Thursday 29 September 2011

Metawatch Menus

The top menu

The Bluetooth Menu

and the clock settings menu

This change took 2 minutes. Not sure how long it would have taken with the old system.
I changed The code


MENU_START(menu1)
MENU_DYNAMIC_ICON_ACTION(bluetooth_get_discoverability_icon, bluetooth_toggle_discoverability, 0) // no update as the spp callback does the refresh
MENU_DYNAMIC_ICON_ACTION(LinkAlarmIcon, ToggleLinkAlarmEnable, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_DYNAMIC_ICON_ACTION(bluetooth_get_status_icon, bluetooth_toggle_bluetooth, 0) // no update as the spp callback does the refresh
MENU_END

MENU_START(menu2)
MENU_MSG_BUTTON(SoftwareResetMsg, NO_MSG_OPTIONS, pResetButtonIcon, BUTTON_STATE_PRESSED, MENU_FLAG_UPDATE)
MENU_DYNAMIC_ICON_ACTION(bluetooth_get_secure_smiple_pairing_icon, bluetooth_toggle_secure_smiple_pairing, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_STATIC_ICON_ACTION(pRstPinIcon, ToggleRstPin, MENU_FLAG_UPDATE)
MENU_END


MENU_START(menu3)
MENU_STATIC_ICON_ACTION(pNormalDisplayMenuIcon,ToggleIdleBufferInvert, MENU_FLAG_UPDATE)
MENU_DYNAMIC_ICON_ACTION(SecondsIcon, ToggleSecondsHandler, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_DYNAMIC_ICON_ACTION(TimeFormatIcon, ToggleTimeFormat, MENU_FLAG_UPDATE)
MENU_END



To


MENU_START(bluetooth)
MENU_DYNAMIC_ICON_ACTION(bluetooth_get_discoverability_icon, bluetooth_toggle_discoverability, 0) // no update as the spp callback does the refresh
MENU_DYNAMIC_ICON_ACTION(bluetooth_get_secure_smiple_pairing_icon, bluetooth_toggle_secure_smiple_pairing, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_DYNAMIC_ICON_ACTION(bluetooth_get_status_icon, bluetooth_toggle_bluetooth, 0) // no update as the spp callback does the refresh
MENU_END

MENU_START(clock)
MENU_DYNAMIC_ICON_ACTION(SecondsIcon, ToggleSecondsHandler, MENU_FLAG_UPDATE)
MENU_DYNAMIC_ICON_ACTION(DateFormatIcon, ToggleDateFormat, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_DYNAMIC_ICON_ACTION(TimeFormatIcon, ToggleTimeFormat, MENU_FLAG_UPDATE)
MENU_END

MENU_DEF(dev2)

MENU_START_WITH_NEXT(dev, dev2)
MENU_STATIC_ICON_ACTION(pNormalDisplayMenuIcon,ToggleIdleBufferInvert, MENU_FLAG_UPDATE)
MENU_MSG_BUTTON(SoftwareResetMsg, NO_MSG_OPTIONS, pResetButtonIcon, BUTTON_STATE_PRESSED, MENU_FLAG_UPDATE)
MENU_DYNAMIC_ICON_ACTION(LinkAlarmIcon, ToggleLinkAlarmEnable, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_END

MENU_START_WITH_NEXT(dev2, dev)
MENU_STATIC_ICON_ACTION(pNormalDisplayMenuIcon,ToggleIdleBufferInvert, MENU_FLAG_UPDATE)
MENU_FLAG_UPDATE)
MENU_DYNAMIC_ICON_ACTION(LinkAlarmIcon, ToggleLinkAlarmEnable, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_STATIC_ICON_ACTION(pRstPinIcon, ToggleRstPin, MENU_FLAG_UPDATE)
MENU_END


MENU_START(TopLevel)
MENU_SUB(bluetooth, pBluetooth, MENU_FLAG_UPDATE)
MENU_SUB(clock, pClockSettings, MENU_FLAG_UPDATE)
MENU_STATIC_ICON_ACTION(pLedIcon, 0, 0)
MENU_SUB(dev, pDevSettings, MENU_FLAG_UPDATE)
MENU_END

Metawatch Firmware Hacking

So I got a new watch.....

And I do what anyone does when they get a new piece of technology....

Improve it! First I fixed it so the date and time were shown in the correct format.
Then added a menu item to allow configuring of this.

Now adding this menu item was quite tricky. The code does lots of message passing and has a custom message for each item. I decided to rewrite the menuing system and made life alot easier(in my opinion)[1], I've since added items for the Day/Month ordering (Although why anyone would want to change this is beyond me ;-) ) and am currently trying out sub menu organisation. The new system makes it very easy to reorder the menus. I've stuck with the current menu design but may experiment with others and possibly add dynamic menus that can be added by applications on the phone (A common request)

Then of course I moved onto the next stage. Writing "Space invaders" for it. (Less encumbered than Xtris) This is the screen.

You can move left and right. But I need to rethink the design and how it fits with the watch architecture. I'd like to split out all the idle screens to separate pluggable entities from the code that handles the LCD. This would make it easer to swap functionality in and out. I'm having to think about how a app can take control from the watch safely and fast. All this source is available on git hub. https://github.com/garthy/MetaWatch-WDS11x-IAR/