Announcement

Collapse
No announcement yet.

Problem reading the button status

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SylvainLAURENT
    replied
    Originally posted by sherwin4D View Post
    Hello Sylvain,

    Could you please post your project file here so we can a better look? Are the UserButtons set to Momentary = Yes?

    Thanks and regards,
    Sherwin
    Hi Sherwan,

    In this form, I've 24 up/down user buttons (blue arrow).
    At the first time, I've made 24 EventCodes, but it's not a satisfaction for me !

    Click image for larger version

Name:	Annotation 2020-04-23 111733.png
Views:	44
Size:	89.0 KB
ID:	71879

    So, I searched to do a single EventCode for the entire 24 UserButtons.
    To do that, I changed "Momentary" to No, otherwise it doesn't work with momentary = Yes.
    And after I develop only 1 EventCode :

    Code:
    func MagicEvent1(var newval)
    var lNew_BtGain := 0; var lNew_BtOff := 0; var lXor; for(i := 1; i <= 12; i++)
    lNew_BtGain |= MyGetUserButtonStatus(i)<<(i-1); lNew_BtOff |= MyGetUserButtonStatus(i+12)<<(i-1);
    next if(Old_BtGain != lNew_BtGain)
    lXor := lNew_BtGain ^ Old_BtGain; Old_BtGain := lNew_BtGain; switch(lXor)
    case 0x01:
    Aff_UpGain(GainAdc1, 0); break;
    case 0x02:
    Aff_DownGain(GainAdc1, 0); break;
    case 0x04:
    Aff_UpGain(GainAdc2, 2); break;
    case 0x08:
    Aff_DownGain(GainAdc2, 2); break;
    case 0x10:
    Aff_UpGain(GainAdc3, 4); break;
    case 0x20:
    Aff_DownGain(GainAdc3, 4); break;
    case 0x40:
    Aff_UpGain(GainAdc4, 8); break;
    case 0x80:
    Aff_DownGain(GainAdc4, 8); break;
    case 0x100:
    Aff_UpGain(GainDac1, 7); break;
    case 0x200:
    Aff_DownGain(GainDac1, 7); break;
    case 0x400:
    Aff_UpGain(GainDac2, 6); break;
    case 0x800:
    Aff_DownGain(GainDac2, 6); break;
    default: break;
    endswitch
    endif if(Old_BtOff != lNew_BtOff)
    lXor := lNew_BtOff ^ Old_BtOff; Old_BtOff := lNew_BtOff; switch(lXor)
    case 0x01:
    Aff_UpOff(OffAdc1, 1, 0); break;
    case 0x02:
    Aff_DownOff(OffAdc1, 1, 0); break;
    case 0x04:
    Aff_UpOff(OffAdc2, 3, 1); break;
    case 0x08:
    Aff_DownOff(OffAdc2, 3, 1); break;
    case 0x10:
    Aff_UpOff(OffAdc3, 5, 2); break;
    case 0x20:
    Aff_DownOff(OffAdc3, 5, 2); break;
    case 0x40:
    Aff_UpOff(OffAdc4, 11, 5); break;
    case 0x80:
    Aff_DownOff(OffAdc4, 11, 5); break;
    case 0x100:
    Aff_UpOff(OffDac1, 10, 4); break;
    case 0x200:
    Aff_DownOff(OffDac1, 10, 4); break;
    case 0x400:
    Aff_UpOff(OffDac2, 9, 3); break;
    case 0x800:
    Aff_DownOff(OffDac2, 9, 3); break;
    default: break;
    endswitch
    endif
    endfunc

    ‚Äč
    Attached Files

    Leave a comment:


  • sherwin4D
    replied
    Hello Sylvain,

    Could you please post your project file here so we can a better look? Are the UserButtons set to Momentary = Yes?

    Thanks and regards,
    Sherwin

    Leave a comment:


  • SylvainLAURENT
    replied
    Hi everyone,

    I'm trying this function in my code and the result is always 0, and I don't know why ?

    Code:
    func MyGetUserButtonStatus(var ObjectIdx)
    var j, k, Objects ;
    Objects := *(oObjects+tUserButton) ; j := 2 + (ObjectIdx&0x00FF) * 2 + Objects ; k := img_GetWord(hndl, *j, IMAGE_INDEX); return k/2;
    endfunc
    I've declare 4 user buttons on my form and then I try this.
    The results are always 0 for all user buttons.

    Code:
    func MagicEvent1(var newval)
    print("\n\nBt 1 :",MyGetUserButtonStatus(1)); print("\nBt 2 :",MyGetUserButtonStatus(2)); print("\nBt 9 :",MyGetUserButtonStatus(9));
    print("\nBt 10 :",MyGetUserButtonStatus(10))
    endfunc
    Regards
    Sylvain.

    Leave a comment:


  • kayven@4d
    replied
    Hi Pietro,

    Thank you for sharing the code.
    This may help others.


    The other way around is to create an user-defined function.

    Right now, I try to check your code.


    Best regards,
    Kayven

    Leave a comment:


  • pitdibi
    replied
    Hi,
    Thank you for reply. In the application note that you have suggested, it isn't explained how you can read the button status from GenieCode.
    Moreover, If you use WriteObject function, to change the button state it doesn't work for states more then 1.
    So, I've done the functions that I need by myself. Here the code:

    Code:
    func MyGetUserButtonStatus(var ObjectIdx)
        var j, k, Objects ;
        Objects := *(oObjects+tUserButton) ;
        j := 2 + (ObjectIdx&0x00FF) * 2 + Objects ;
        k := img_GetWord(hndl, *j, IMAGE_INDEX);
        return k/2;
    endfunc
    
    
    func MyWriteObject(var ObjectTypeAndIndex, var NewVal)
        var i, j, k, Objects, ObjectType,ObjectIdx ;
        ObjectType := (0x3f&(ObjectTypeAndIndex>>8)) ;
        ObjectIdx := ObjectTypeAndIndex&0x00FF;
            if (ObjectType == tForm)
            ActivateForm(ObjectIdx) ;
        else
            Objects := *(oObjects+ObjectType)+ObjectIdx*2+2 ;
            i := *(Objects) ;
            switch (ObjectType)
                case tUserButton :
                    j := InputControls[oUserButtons[ObjectIdx+1]] ;
                    break ;
                default : j := -1 ;
            endswitch
            if (j != -1)
                k := img_GetWord(hndl, i , IMAGE_INDEX) ;
                NewVal := NewVal << 1 ;
            endif
                img_SetWord(hndl, i , IMAGE_INDEX, NewVal); // where state is 0 to 2
                img_Show(hndl, i) ; // will only display if form is current
        endif
    endfunc
    MyGetUserButtonStatus gets %GenieIndex% and returns the button state,
    MyWriteObject gets%GenieIndex% and the button status that you want, to change the showed icon.
    Let me know if you think it's a good solution.

    Regards
    Pietro

    Leave a comment:


  • kayven@4d
    replied
    Hi,

    Thank you for posting your concern here.

    Did you see the application note found here:

    ViSi-Genie Blocked Users


    and please use GTX tool to set the block index for you to see how it operates.

    It is applicable for your purpose.



    Please let me know if it solves your concern.

    Best regards,
    Kayven

    Leave a comment:


  • pitdibi
    started a topic Problem reading the button status

    Problem reading the button status

    Hi!
    I'm using visi genie pro.
    I've created a UserButton with 8 images. I've made that because I need a button that can have more the two stable state.
    Now, let me show the question.
    I receive some message from spi that change the button state.
    When someone push the button, I have to do different operation for different states of the button.
    For example, the operation that I have to do when button is on state 2 is different from the operation for the state 3.
    But if I use the ReadObject function to see the button status, it return always one or zero. Also the new value, getted from a magic event linked to the button, is always zero o one.
    There is not possibility to know if the button is in state 3 or 4?
Working...
X