Switch-on, switch-off in a time range. Please help...

Former Member
Former Member

Hello.

I try to do a function for my dial that turns off, for example, seconds in a given time range.

I want it to be possible to set it in APP (in xml format). I have everything ready, but the problem is that the function does not work correctly for me yet.

I'm just getting started with MonkeyC programming and I'd appreciate it if someone could help me with my code. All I need is this function and the dial is done.

Here I attach the code


Thank you very much

The error I'm getting in the SIM...

Error: Symbol Not Found Error
Details: Could not find symbol 'today'

Thank you very much

I will give VoteUP for professional help with this feature.

 

  • Former Member
    Former Member in reply to Dresbo

    Hi David, so I played Slight smile a bit . In the attachment I send what I did.

    They only need to fix THIS:

    If ON is set to 23:00 hours and OFF is set to 6:00 hours, it does not work properly.

    I don't know how to fix it.

    Thank you

    6170.Example 2.0.zip

  • Glad you made progress.  I think you might need to tweak your logic a little to find the most recent desired state:

    var isOn =false;
    if(ON < OFF){
    	isOn = (clockTime > ON && clockTime < OFF); //between ON and OFF
    }else if(OFF < ON){
        isOn = (clockTime > ON || clockTime < OFF); //after On or before OFF
    }
    
    if(isOn){
      drawText(....);
    }

    This is untested, but should be about correct.

  • I've tested the code above and it works (slight change of > to >= ). Please see the version integrated in to your file attached. Please look at it and try to understand how I integrated it and why it works, otherwise you won't make much progress without lots of help

    3036.Example 2.0.zip

  • Former Member
    Former Member in reply to Dresbo

    Thanks, I already did. I really appreciate your help and the time you gave me.

    And my last question (I didn't find it anywhere) is that I can somehow delegate it using the drawables class (sleep function) to another file?

    eg if(SleepMode){;

    I want to use this function for other functions as well, and I don't want to break it down into code.

    This is just a delegation to me:

    Drawable.initialize ({: identifier => "SleepMode"});

    Thank you

  • Create a public function called sleepMode() in another class in a module and call it. See developer.garmin.com/.../

    If(MyModule.sleepMode()){......

    }

  • Former Member
    Former Member in reply to Dresbo

    Well, an example or a practice source code would help me more, but I understand that you can't spend more time with me. Thank you, I've learned more again.

  • There are plenty of examples of modules in the example apps bundled with the sdk. Have you looked at them? Search for the word 'module' in the codebase. (Ctrl+h in eclipse).

  • Former Member
    Former Member in reply to Dresbo

    Hi, i did it as follows:

    List of functions

    List of functions.zip

    I put it in an attachment so as not to overwhelm the forum.

    The function works properly, but I don't know how to call it in the if condition?

    If sleep mode is on, only text should appear instead of seconds
    
    Thank you

  • Well done for giving it a go. It's important that you're trying.  You need a module, not a class. See below.

    Ps. you changed the logic I wrote to "time <=OFF". This has the effect at turning off the clock at the end of the hour (6:59 if off is set to 6) is that the intention?

    OnUpdate method in the view:

    function onUpdate(dc as Dc) as Void {

    View.onUpdate(dc);

    dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
    var clock = System.getClockTime();
    var timeSecString = Lang.format("$1$", [clock.sec.format("%.2d")]);

    var isSleeping = Common.isSleeping(clock);
    if(isSleeping){
    dc.drawText(100, 100, Graphics.FONT_LARGE, timeSecString, Graphics.TEXT_JUSTIFY_LEFT);
    } else {

    var is24Hour = System.getDeviceSettings().is24Hour;
    var hours = clock.hour;
    hours = !is24Hour && hours > 12 ? hours - 12 : hours;
    var time = Lang.format("$1$:$2$", [hours, clock.min.format("%02d")]);

    dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT);
    dc.drawText(130, 100, Graphics.FONT_NUMBER_HOT, time, Graphics.TEXT_JUSTIFY_CENTER);
    }
    }

    -------------------------

    new file Common.mc

    ----------------------

    using Toybox.System;
    using Toybox.Time;
    using Toybox.Application;

    module Common {

    public function isSleeping(clockTime) {

    var ON = Application.getApp().getProperty("SleepModeON");
    var OFF = Application.getApp().getProperty("SleepModeOFF");
    var isOn =false;

    if(ON < OFF){
    isOn = (clockTime.hour < OFF && clockTime.hour >= ON); //between ON and OFF
    }else if(OFF < ON){
    isOn = (clockTime.hour < OFF || clockTime.hour >= ON); //after On or before OFF
    }

    return !isOn;
    }
    }

  • Former Member
    Former Member in reply to Dresbo

    As for the logic for the ON / OFF function, I had to do it this way, because it didn't work that when the on time was PM 23:00 and the off time AM 6:00, it didn't work that way.

    Even now, it doesn't work properly and it shuts down an hour later, which means that when the shutdown time is set to AM 6:00, it won't turn off until AM 7:00. I can't fix it exactly on time.

    Can I ask you to send me the module in the TestView file?

    It's faster and easier for me ... I don't have to copy it then.

    Thank you