Commit 4e8a4c1b authored by Alexis Lecanu's avatar Alexis Lecanu

Merge branch 'release/1.2.0'

parents f82ebefa 70cdf3ce
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="TimerApp" id="9f349141d98a423dbb8575420d96c50d" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="1.2.0" name="@Strings.AppName" type="watch-app" version="1.1.1">
<iq:application entry="TimerApp" id="9f349141d98a423dbb8575420d96c50d" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="1.2.0" name="@Strings.AppName" type="watch-app" version="1.2.0">
<iq:products>
<iq:product id="d2bravo"/>
<iq:product id="d2bravo_titanium"/>
......
......@@ -9,6 +9,7 @@
<string id="Bip5s">Son 5'</string>
<string id="Vibrate">Vibration</string>
<string id="Alarms">Alarmes</string>
<string id="AutoRestart">Redémarrer</string>
<string id="Enable">Activé</string>
<string id="Disable">Désactivé</string>
<string id="Timer">Cpte. à Reb.</string>
......
......@@ -9,6 +9,7 @@
<string id="Bip5s">Sound 5'</string>
<string id="Vibrate">Vibrate</string>
<string id="Alarms">Alarms</string>
<string id="AutoRestart">Restart</string>
<string id="Enable">Enable</string>
<string id="Disable">Disable</string>
<string id="Timer">Timer</string>
......
using Toybox.Timer;
using Toybox.Lang;
// utility class to wrap Toybox.Timer so that
// we can register and run timers but avoid "too many timers" errors.
var _cron;
static class Cron {
static const CHECK_LOOP_INTERVAL_MS = 100;
protected var t;
protected var jobs;
static function getInstance() {
if (_cron == null) {
_cron = new Cron();
}
return _cron;
}
function initialize() {
self.jobs = {};
self.t = new Timer.Timer();
self.t.start(self.method(:checkTimersLoop), CHECK_LOOP_INTERVAL_MS, true);
}
function register(timerName, everyMs, callback, repeat) {
if (self.jobs.hasKey(timerName)) {
System.println(Lang.format("timer already registered with name $1$", [timerName]));
return;
} else if (everyMs < CHECK_LOOP_INTERVAL_MS) {
System.println(Lang.format("timer loop must be at least $1$ milliseconds", CHECK_LOOP_INTERVAL_MS));
return;
} else if (!(callback instanceof Lang.Method)) {
System.println("callback must be an invokeable method instance");
return;
}
if (everyMs % CHECK_LOOP_INTERVAL_MS != 0) {
System.println(Lang.format("Job repeat time $1$ doesn't schedule roundly with cron loop; check config for job=$2$", [everyMs, timerName]));
}
self.jobs.put(timerName, {
:enabled => true,
:every => everyMs,
:sinceLast => 0,
:callback => callback,
:repeat => repeat
});
}
function isRegistered(timerName) {
return self.jobs.hasKey(timerName);
}
function isEnabled(timerName) {
return self.isRegistered(timerName) && self.jobs.get(timerName)[:enabled];
}
function enable(timerName) {
if (!self.jobs.hasKey(timerName)) {
System.println(Lang.format("no such timer found with name $1$", [name]));
return;
}
self.jobs[timerName][:enabled] = true;
}
function disable(timerName) {
if (!self.jobs.hasKey(timerName)) {
System.println(Lang.format("no such timer found with name $1$", [name]));
return;
}
self.jobs[timerName][:enabled] = false;
}
function unregister(timerName) {
self.jobs.remove(timerName);
}
function checkTimersLoop() {
var jobNames = self.jobs.keys();
for (var i = 0; i < jobNames.size(); i++) {
var jobName = jobNames[i];
var job = self.jobs[jobName];
job[:sinceLast] += CHECK_LOOP_INTERVAL_MS;
if (!job[:enabled] || job[:sinceLast] < job[:every]) {
continue;
}
job[:callback].invoke();
job[:sinceLast] = 0;
if (job[:repeat]) {
continue;
}
self.unregister(jobName);
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ class Element {
var position;
var name;
var time;
var autoRestart;
var beep;
var beep5s;
var vibrate;
......@@ -18,6 +19,7 @@ class Element {
self.beep = !extractValue("beep",json).equals("false")?true:false;
self.beep5s = !extractValue("beep5s",json).equals("false")?true:false;
self.vibrate = !extractValue("vibrate",json).equals("false")?true:false;
self.autoRestart = extractValue("autoRestart",json).equals("true")?true:false;
}
function setPosition(position){
......@@ -49,12 +51,14 @@ class Element {
return beep5s;
}else if(property.equals("vibrate")){
return vibrate;
}else if(property.equals("autoRestart")){
return autoRestart;
}else{
return null;
}
}
function toJson(){
return "{\"name\":\""+name+"\",\"time\":\""+time+"\",\"beep\":\""+beep+"\",\"beep5s\":\""+beep5s+"\",\"vibrate\":\""+vibrate+"\"}";
return "{\"name\":\""+name+"\",\"time\":\""+time+"\",\"beep\":\""+beep+"\",\"beep5s\":\""+beep5s+"\",\"vibrate\":\""+vibrate+"\",\"autoRestart\":\""+autoRestart+"\"}";
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ class TimerApp extends App.AppBase {
function onStart(state) {
extract(App.getApp().getProperty("elements"));
//extract("[{\"name\":\"A\",\"time\":\"15\",\"beep\":\"true\",\"beep5s\":\"true\",\"vibrate\":\"true\"},{\"name\":\"B\",\"time\":\"60\",\"beep\":\"true\",\"beep5s\":\"true\",\"vibrate\":\"true\"},{\"name\":\"C\",\"time\":\"60\",\"beep\":\"true\",\"beep5s\":\"true\",\"vibrate\":\"true\"},{\"name\":\"D\",\"time\":\"60\",\"beep\":\"true\",\"beep5s\":\"true\",\"vibrate\":\"true\"}]");
}
function onStop(state) {
......
......@@ -11,8 +11,6 @@ class TimerModel{
var counter;
var status=:Wait;
var data;
hidden var refreshTimer = new Timer.Timer();
hidden var displayTimer = new Timer.Timer();
var viewVisible=true;
function initialize(data){
......@@ -22,9 +20,8 @@ class TimerModel{
function startTimer(){
counter = data.time;
status=:Work;
refreshTimer.stop();
displayTimer.stop();
refreshTimer.start(method(:refresh), 1000, true);
Cron.getInstance().unregister(data.name);
Cron.getInstance().register(data.name, 1000, method(:refresh), true);
startBuzz();
Ui.requestUpdate();
}
......@@ -36,15 +33,13 @@ class TimerModel{
stopBuzz();
}
}
refreshTimer.stop();
displayTimer.stop();
Cron.getInstance().unregister(data.name);
Ui.requestUpdate();
}
function resetTimer() {
status=:Reset;
refreshTimer.stop();
displayTimer.stop();
Cron.getInstance().unregister(data.name);
Ui.requestUpdate();
}
......@@ -72,6 +67,9 @@ class TimerModel{
function end(){
stopTimer(false);
endBuzz();
if(data.autoRestart){
startTimer();
}
}
function startBuzz() {
......
......@@ -35,6 +35,10 @@ class MenuItem
}
function onUpdate (dc){
}
function draw (dc, y, highlight) {
if (highlight) {
setHighlightColor (dc);
......@@ -169,6 +173,10 @@ class Menu extends Ui.View {
}
function onUpdate (dc) {
for (var idx = 0; idx < menuArray.size (); idx++) {
menuArray[idx].onUpdate(dc);
}
var width = dc.getWidth ();
var height = dc.getHeight ();
......
......@@ -6,6 +6,7 @@ class ElementMenu extends Menu {
hidden var data;
hidden var start;
hidden var reset;
hidden var autoRestart;
hidden var continu;
hidden var alarms;
hidden var remove;
......@@ -18,6 +19,7 @@ class ElementMenu extends Menu {
continu = Ui.loadResource(Rez.Strings.Continu);
start = Ui.loadResource(Rez.Strings.Start);
reset = Ui.loadResource(Rez.Strings.Reset);
autoRestart = Ui.loadResource(Rez.Strings.AutoRestart);
alarms = Ui.loadResource(Rez.Strings.Alarms);
remove = Ui.loadResource(Rez.Strings.Remove);
rename = Ui.loadResource(Rez.Strings.Rename);
......@@ -34,6 +36,7 @@ class ElementMenu extends Menu {
function defaultMenu(){
var menuItems = new [0];
menuItems.add(new TimeMenuItem (:Timer,data));
menuItems.add(new StateMenuItem (:AutoRestart,autoRestart,data,"autoRestart"));
menuItems.add(new DataMenuItem (:Alarms,alarms,data));
menuItems.add(new DataMenuItem (:Remove,remove,data));
menuItems.add(new DataMenuItem (:Up,up,data));
......
......@@ -72,6 +72,8 @@ class ElementMenuDelegate extends MenuDelegate {
elements.addAll(temps);
}
Ui.popView (Ui.SLIDE_LEFT);
}else if(item.id ==:AutoRestart){
item.data.autoRestart=!item.data.autoRestart;
}
}
}
\ No newline at end of file
......@@ -6,8 +6,12 @@ class ElementMenuItem extends DataMenuItem{
function initialize (id, data) {
DataMenuItem.initialize(id, data.name,data);
}
function onShow () {
DataMenuItem.setValue(Utils.timeToString(data.time));
function onUpdate (dc) {
if(models.hasKey(data.name) && models.get(data.name).status == :Work){
DataMenuItem.setValue(Utils.timeToString(models.get(data.name).counter));
}else{
DataMenuItem.setValue(Utils.timeToString(data.time));
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment