Hi, how to begin the start of a datafield with pressing the Enter button?
I want to start at the same time the recording will start,
(e.g. the function compute(info)).
Hopefully this explanation was clear.
Thanks
but info.timerTime only starts when FIT data is simulated.
Yes. On a device it will be non-null after the user starts their activity, and it will stop increasing when the activity is paused.
You can check info.timerTime. If it is null, the recording session has not been started. You can also monitor that field to tell if the session is paused.
if ( TTSec == TTSec2 && TTSec > 0) {
if ( flag == 0) {
var dateInfo = Time.Gregorian.info( Time.now(), 0);
Sys.println(dateInfo.year + "-" + dateInfo.month + "-");
flag = 1;
}
} else {
TTSec2 = TTSec;
flag = 0;
}
}
There apparently are holes in this process esp if I do some heavy CPU math calculations (I want to detect when the activity is stopped as I want to write out a LOG file) then the watch starts to skip seconds.. 1,3,5,7, etc.. and this causes a log to be written and then complicates things again.
if ( TTSec == TTSec2 && TTSec > 0) {
if ( flag == 0) {
var dateInfo = Time.Gregorian.info( Time.now(), 0);
Sys.println(dateInfo.year + "-" + dateInfo.month + "-");
flag = 1;
}
} else {
TTSec2 = TTSec;
flag = 0;
}
class MyDataField extends Ui.SimpleDataField {
var mPreviousTimer;
function initialize() {
SimpleDataField.initialize();
}
function compute(info) {
var text = null;
// timer has not yet started or session has ended
var currentTimer = info.timerTime;
if (currentTimer == null) {
if (mPreviousTimer == null) {
text = "Not Started";
}
else {
text = "Last Tick";
}
}
// timer has started
else {
// this is the first tick of the timer in this activity session
if (mPreviousTimer == null) {
text = "First Tick";
}
// timer is ticking
else if (mPreviousTimer != currentTimer) {
text = "Ticking";
}
// timer is not ticking
else {
text = "Paused";
}
}
mPreviousTimer = currentTimer;
return text;
}
}
- When an activity is active, you're seeing the timer skip every other second.
- You log some data in the application. This is slow, so you don't want to do it all of the time.
- You do some math in the application. This is slow, but you do want to do this all of the time.
- You've tried to detect when an activity session is active and this doesn't work.
- You've tried to do logging once every 10 seconds, but this doesn't work either.
if ( TIMER != PTIMER ) {
DFields(dc,info);
} else {
DFinSess(dc,info);
if ( flag == 0 ) {
var DI = Time.Gregorian.info( Time.now(), 0);
Sys.println(DI.year + "-" +
DI.month + "-" +
DI.day + "," +
OF(DI.hour) + ":" + OF(DI.min) + ":" + OF(DI.sec) +
",Timer," + TTMin +":" + TTSec1 +
",ASPD," + AvgSpd + ",Dist," + Dist +
",NP," + NP + ",AP," + AP + ",RT," + VI
);
flag = 1;
}
}
if (TIMER >= 1) { PTIMER = TIMER; }
}
onTimerLap 8389751
onTimerPause 8389749
onTimerReset 8389752
onTimerResume 8389750
onTimerStart 8389747
onTimerStop 8389748