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

    No, when i removed time gregorian, it still shows this error:

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

    Did you look at the new file I uploaded?

  • Former Member
    Former Member in reply to Former Member

    Hi,

    to put it in perspective. They need to customize the feature provided to me by: Shent-Aurkhan (SHN)

    I am sending his part of the code here:

    var T=Time.today().value();
    var S=UP.getProfile().sleepTime.value()+T;
    var E=UP.getProfile().wakeTime.value()+T;
    
    var P = true;
    T=Time.now().value();
    if(S>E&&(T>S||T<E)){P=false;}
    if(S<E&&T>S&&T<E){P=flase;}
    
    where P can be use like if(P){ balblabla display seconds }

    I need to link it to this XML object:

    var ON = Application.getApp (). getProperty ("SleepModeON") + T;
    var OFF = Application.getApp (). getProperty ("SleepModeOFF") + T;


    Into which the values ​​are entered.

    My point is that the function responds to time - clock and range which is ON / OFF

    Outside the time range of the function eg seconds run on the desktop normally.

    Thank you

  • The file that you sent me has the same problem that I pointed out right at the start. On line 34 you redefine "Time" as a variable:

    var Time = System.getClockTime();

    and at the top:

    using Toybox.Time;

    These are the same name (Time) for different things and it can't work out which is which.

    You reference Time.today() lower down, which, because you have defined "var Time" on line 34,  is trying to call System.getClockTime().today(), which doesn't exist.

    If what I'm telling you doesn't make sense, please tell me that directly because I sense that you're not understanding the cause of the problem. 

    I have corrected that error, but you still have issues on lines 44 and 45 because

    var ON = sleepTime.value().Application.getApp().getProperty("SleepModeON")+T;

    doesn't make any sense as a line of code and I don't know what sleepTime and wakeTime are, or are meant to be.

    If you haven't done much programming before you may want to try some JavaScript to learn the basics. Monkey c isn't very forgiving or user-friendly for learning those and there aren't that many tutorials etc, to follow that could teach you.

  • Former Member
    Former Member in reply to Dresbo

    Hi David,

    I really don't understand now, but I'll try to explain. Lines 32 through 35 are seconds for the seconds themselves that run smoothly and I only have it for testing purposes.

    On lines 42 to 51, the function that should turn on begins - to hide the given time value, which can be set in XML, for seconds.

    I got this from a user from this forum.

    Please note that on lines 50 and 51 there are conditions for dc.draw that show the seconds.

    It will be easier for me if you modify the function I sent you from Shent-Aurkhan (SHN) so that I do not see the error "today". I can use this function for others and it does not have to be, for example, seconds, but the display of the icon also in the given time range from XML.

    Thank you

  • Former Member
    Former Member in reply to Dresbo

    Simply put, try inserting the SHN Code into a new project and you'll see what I'm talking about. I do not deal with the seconds in the area of ​​line 51. Even if there was a dc.DrawText, I still get the error today ...

  • The file I attached to my last post no longer has the error that you were orignally asking to be fixed. I'm afraid I don't have the time to write the rest of it for you.

    The reason you see the error in the modified version of Shent-Aurkhans (SHN) code is because "var Time" is conflicting with "import Toybox.Time". I cannot put this any more simply. I have corrected this error by renaming the variable to clockTime.

    The function he posted doesn't have this problem (so I cannot modifiy it to correct it) because he is not defining a variable called Time.

    Have you run the code I sent back to you? You'll see that error has gone away.

  • Former Member
    Former Member in reply to Dresbo

    Yes after importing the fix into my main code i don't see the error, now i will test if the ON / OFF values ​​work for me according to the time.

    Thank you

  • Former Member
    Former Member in reply to Former Member

    I can't set the values.

    They need the condition to work as follows:

    ON value less than OFF value

    in the range ON and OFF does not want to have displayed eg seconds...

    if(ON < OFF && (T < ON || T >= OFF)){P=false;}
    if(ON > OFF && T < ON && T >= OFF){P=dc.drawText(x, y, $.fontSeconds, timeSecString, Graphics.TEXT_JUSTIFY_LEFT);}

    Thank

  • What's the question?

    That code is very muddled. What is P for? In one line it's set to false, another it's the result of drawText() (which does't return a value)

    You need to lay out the requirements clearly:

    1) If ON < OFF then...(this should be enforced rather than checked)

    2) if Time > ON and Time < OFF.....display text?

    3) Else display nothing?

  • Former Member
    Former Member in reply to Dresbo

    The whole function should be adapted as follows:

    ON value is the hour when the Sleep mode is to be switched on (eg 22:00) OFF value is the hour when the mode is to be switched off (eg 23:00).

    In the time range of values, I mean whole hours.

    Seconds or text should not be displayed, just what I enter there.

    EDIT:

    Outside the duration, the dc.draw object must be displayed ...