Hug Remote specifications

I created the app in Android Studio. In general, the app works like this:

  • When starting the app, an initialization message is sent to the Hug WiFi module via WiFi. Status of the app: connecting
  • When it receives an acknowledgement message, the app status will change to Connected.
  • When changing time and intensity settings while there is no session active on the Hug, a configuration message is sent to the Hug.
  • When the start button is pressed, the last known configuration of the Hug will start.
  • When changing the intensity of the front and or rear heaters, an update message is sent to the Hug (this is different from a configuration messsage)
  • A configuration message starts with the header C2 and contains the following data:
    • Min and max setting of front heater intensity
    • Front heater intensity setting
    • min and max setting of front heater timer
    • Front heater timer setting
    • Power on fade in time
    • All of the above for the rear heater
  • An update message starts with the header L2 and only contains intensity settings of the front and rear heater
  • Each message ends with a CRC / Checksum byte
  • A start message reads: B2-FF-FF-42
  • A stop message reads: B2-00-00-44
  • When the app sends a message to the Hug, the Hug will either:
    • respond with an acknowledgement message that is structured as follows: O2-checksum byte of received message – checksum byte of this message
    • respond with an error message: E2 –¬†checksum byte of received message – checksum byte of this message
  • When a session is active, the Hug will send a status update message every second that starts with S207. When a stop message has been received or the session of the Hug ends by itself, the status update message header will be S201 or S203. The status message contains the same information as a configuration message, added with two countdown timers in seconds.

App design layout

Three different layouts are used to enable the use of the app on low and high DPI screens.

App life time

send init message

send configuration message

send update message

send start or stop message

read Hug status messages

read Hug acknowledgement and error messages

change timer and intensity sliders and value settings

App code structure

  • import all necessary libararies
  • set values
  • define text boxes
  • define image placeholders
  • define seekbars
  • set preset time and intensity settings
  • set several booleans to keep track on Hug and app status
  • enable media player, vibration and networking
  • set up a broadcastreceiver

Service and Broadcastreceiver

A dedicated server is part of the app to deal with sending and receiving UDP messages. This way, the app will keep sending update messages when a preset is active, even when the Hug Remote app is not on the foreground. When a message is received by the app, the contents are broadcast. Therefore the MainActivity contains a broadcastreceiver to receive the contents of these messages.

A broadcast receiver needs to be registered in the androidmanifest file. It also needs to be combined with an intent filter (I need to look up exactly how I set this up again, I remembered it was quite a hassle)

Starting and binding to the service is part of the onCreate routine of the app.

When the HugCommunicationServiceBound service is started, it will automatically send the init message. Then it will create a thread that continuously waits for a message from the Hug. When a message is sent from this service, the first time it will create a socket, and then send the message.

Intensity slider conversion

The slider value range of the intensity slider is 0 – 100. The Hug expects values within the same range. However, the IR heaters will only start heating from intensity setting 35. Therefore, I have created two functions that map between these ranges so that a setting of zero on the slider will map to an actual setting of 35.

Settings service

A service is created for the settings page that has the sole purpose of editing the IP address of the Hug.

Heater icon setting

The heater icons have 2×4 possible settings. When a heater is selected, the icon’s color is red. Then based on the intensity setting, one, two, three or all four bars next to the icon are colored red. When a heater is not selected, the icon’s color is white, but the bars are still colored red, based on the current setting.

Following presets

When a preset is active, the app will send intensity updates to the Hug based on the elapsed time. The predefined settings will dictate when it will jump to a specific setting or gradually increase or decrease the intensity to arrive at the desired intensity at the right time.

Parsing received messages

When a message is received within the communication service and broadcast and then received by the mainactivity, it is forwarded to a message parser. This function first checks the header of the message to decide what it needs to to with the message. Then the important parts of the hex coded message are converted to decimals (power settings, time settings). From this function, the slider settings are updated as well.