Class Watchdog

java.lang.Object
com.codename1.hardware.Watchdog

public final class Watchdog extends Object

The hardware watchdog, opened through Hardware.openWatchdog(int).

Once open, the device resets unless kick() is called within the timeout. Kick it from a timer that only runs while the application is healthy, so a hung event dispatch thread causes a reset:

try {
    final Watchdog wd = Hardware.getInstance().openWatchdog(15);
    UITimer.timer(5000, true, Display.getInstance().getCurrent(), () -> wd.kickQuietly());
} catch (HardwareException e) {
    Log.e(e);
}
  • Method Details

    • kick

      public void kick() throws HardwareException

      Restarts the countdown.

      Throws
      • HardwareException: when the watchdog is closed or the kick fails
      Throws:
      HardwareException
    • kickQuietly

      public void kickQuietly()
      kick(), ignoring failures, for use from a timer.
    • close

      public void close(boolean disarm)
      Closes the watchdog. With disarm the timer stops where the driver allows it; without, the device resets when the timeout runs out, which is the right choice on the way down after an unrecoverable error.