Enableing Modules

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by jboer, Sep 26, 2012.

  1. jboer

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    Hey Guys,

    Have a bit of a logic question, I have the following logic in a module that gets enabled and disabled:

    Code:
    once (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Blues Button") = ON) then
    begin
    SetScene("Blue Lights On");
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "Works Button", OFF);
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "LockOut Button", ON);
    Delay("0:00:02");
    SetScene("Whites All Off");
    end;
    
    once (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Works Button") = ON) then
    begin
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "LockOut Button", OFF);
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "Blues Button", OFF);
    SetScene("Whites All On");
    Delay("0:00:02");
    SetScene("Blue Lights Off");
    end;
    
    My problem being is that if one of the 'Works Button' or 'Blues Button' groups is ON when the module gets enabled it will play that thread. What I would like is for it to have an OFF then an ON before it plays the thread. I tried not disabling the module and using an IF condition over the top but understandably this did the same thing.

    Would anyone know how I can get around this? Would keeping the module enabled and using if after the once statement be better? As in:

    Code:
    once (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Blues Button") = ON) then
    if (GetCBusState("SPR-03 Level B4", "Test", "Blues Enable") = ON) then
    begin
    SetScene("Blue Lights On");
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "Works Button", OFF);
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "LockOut Button", ON);
    Delay("0:00:02");
    SetScene("Whites All Off");
    end;
    
    once (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Works Button") = ON) then 
    if (GetCBusState("SPR-03 Level B4", "Test", "Works Enable") = ON) then
    begin
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "LockOut Button", OFF);
    SetCBusState("SPR-03 Level B4", "Lighting Panels", "Blues Button", OFF);
    SetScene("Whites All On");
    Delay("0:00:02");
    SetScene("Blue Lights Off");
    end;
    
    I would prefer if there was a way to do it with enabling and disabling the modules but if I can't that is ok.

    Thanks!!
     
    jboer, Sep 26, 2012
    #1
  2. jboer

    Goran C Forum Member

    Joined:
    Jun 7, 2012
    Messages:
    28
    Likes Received:
    0
    Location:
    Adelaide
    Have you referred to the PICED Logic Help file section on Logic Engine Language | Modules

    From your description it is not absolutely clear what you are trying to achieve?

    Are you trying to execute your code independant of whether your module is enabled/disabled? Are you expecting that when the user presses the Blues Button to ON that it execute that logic code regardless of the module state or only when it is enabled? Also if Blues Button is already ON and module is enabled to turn the Blues Button OFF and then ON would turn off your Blues Lights OFF and then back ON again. Are you sure you want to do that?

    Are you checking whether the module is enabled or disabled and handling the logic slightly differently?
     
    Goran C, Sep 26, 2012
    #2
  3. jboer

    Mark

    Joined:
    Oct 28, 2004
    Messages:
    196
    Likes Received:
    1
    Location:
    Grenoble, France
    Use your own variable

    The behaviour you want isn't totally clear and I'm too lazy to write pascal, but it sounds like you just need to maintain your own boolean along the lines of:

    Code:
    [B]Init:[/B]
    my_boolean = false
    
    [B]Module:[/B]
    once (Group == Off)
    {
      my_boolean = true;
    }
    
    if (Group == On) AND (my_boolean == true)
    {
      my_boolean = false;
      do stuff...
    }
    Hope that helps,
    M
     
    Mark, Sep 26, 2012
    #3
  4. jboer

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    I am unsure on what you are describing here either :) But yes I have read the Logic manual and couldn't really find what I was needing.

    The logic statement Once will only run the actions only once when it sees a change in the state of Blues Button to the requested state, It then will want to see an Off and On before running them again, correct?

    What I need is for this to happen when I enable the module, as in GA(Blues Button) is ON when the module gets enabled, and for my once command to wait till it has seen an Off and On before it runs any actions.

    @Mark: I am not sure that will work because after the first toggle of the GA the flag is stuck high so if the module is then enabled you will have the same problem?


    If you want to know why I am even enabling/disabling modules then I can describe my whole project if you like.
     
    jboer, Sep 26, 2012
    #4
  5. jboer

    Goran C Forum Member

    Joined:
    Jun 7, 2012
    Messages:
    28
    Likes Received:
    0
    Location:
    Adelaide
    You are correct regarding the once statement

    if ModuleEnabled("Your Module") then
    begin
    once (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Blues Button") = ON) then
    begin
    statements
    end
    end;

    would run your statements once upon the module becoming enabled if the condition was met
    as compared to the following which would run your statements every time through the program loop assuming its similar to the PICED Logic Help Modules example.

    if ModuleEnabled("Your Module") then
    begin
    if (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Blues Button") = ON) then
    begin
    {your statements}
    end;
    end;

    As per the case you mentioned. When the Module is enabled and the Blues Button is ON it will satisfy the once condition immediately and run your statements once. The next time through the program loop if the module is still enabled it will not run your statements again. NOTE: Because the condition is already satisfied on the initial loop there is no delay.

    In the case that Blues Button is OFF it wont execute your code and will loop again and again waiting until the condition ModuleEnabled and Once Blues Button is ON conditional statement is met to execute your code once.
    Your statements would not be executed again until you switched Blues Button to OFF then ON again to allow the once conditional statement to be executed again.

    What are you trying to really achieve by turning the button OFF and ON? is it really a delay or for it to reset the once condition?
     
    Goran C, Sep 26, 2012
    #5
  6. jboer

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    Ok thanks, I am not sure what you are asking here though. The 2 sections in this piece of logic basically are interlocked and toggle 2 different states. So if you press your work lights button the work lights go on and the blue lights go off, it also sets the Blue Lights button to off ready for when someone needs to reverse the procedure.

    The reason I am using only On commands is to keep my indication correct on the pushbuttons.

    The section in bold is my current question, I was wondering if there was another condition or way that I could use to stop it from doing this. Senario: The Blues Button in another separate module is playing a different scene. I press a pushbutton that I have set to disable that module and enable this module. What then happens is that it is playing the scenes in this module immediately, as you say and so it changes all my outputs. However I need it so that only after you turn the Blues Button off and then back on will it play the scene in this module. Does that make more sense?

    Although I think I may have just solved it by using the GA that originally I had enabling and disabling the modules in after the if command:

    once (GetCBusState("SPR-03 Level B4", "Lighting Panels", "Works Button") = ON) then
    if (GetCBusState("SPR-03 Level B4", "Test", "Module Enable") = ON) then
    begin
    Statements;
    end;

    And I do not enable and disable the modules at all.
     
    Last edited by a moderator: Sep 26, 2012
    jboer, Sep 26, 2012
    #6
  7. jboer

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    The critical point here is that the once condition is compared with what it was when last evaluated to determine whether to execute the statement.

    For example: if the module is enabled and the condition is false, then the module is disabled and then at some later time is re-enabled, and at that time the condition is now true, then the once statement will be executed. In this case, the condition is now true and was previously (some time ago) false so the once statement gets executed.
     
    Darren, Sep 27, 2012
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.