Jump to content

Can I get help in changing the button handler routine in midibox64


Recommended Posts

I'm still a major newb, but wonder if I can accomplish this for the MB64 that I am trying to build, it's coming along, mainly thanks to everyone here.

I want to change the button handler routine to clear a LED shift register then set the LED to indicate the toggled button. Basically, to show only the last pressed button and cancel previous LEDs. I don't want this to happen with all shift registers, just the ones that require it.

I've studied the MB64_BUTTON_GP_NoSFB and MB64_BUTTON_OnOnly (the only situation I need it) and the MB64_BUTTON_Send and MB64_LED_Set routines, but I suspect the changes need to be made in MIOS. I don't want to mess with that as it's TK's work.

Does anyone know how to begin with this?

Keith

Link to comment
Share on other sites

I don't see a reason why a change has to be made in MIOS... there are many applications (like MBSID, MBSEQ) which provide such functions as well. They are not made for your usecase, of course ;)

MB64 groups the 64 LEDs into 8 bytes. Each bit represents a LED (8x8 = 64)

The first group is located in MB64_BUTTON_VALUES_SR0, the second in MB64_BUTTON_VALUES_SR0+1, the third in MB64_BUTTON_VALUES_SR0+2, etc...

Example: If you would clear all bits in MB64_BUTTON_VALUES_SR0, before setting the bit which corresponds with the LED, you would easily get a "radio button group" of for 8 LEDs/buttons

E.g., if you want to use it in conjunction with the "OnOnly" button function, just add:

[tt]

MB64_BUTTON_OnOnly

        ;; save status of button

        rcall   MB64_BUTTON_Hlp_SaveStat

        ;; when on: send button value defined in dump

        ;; when off: send nothing

        BRA_IFSET TMP1, 0, ACCESS, MB64_BUTTON_NotifyChangeEnd

       ;; new

       SET_BSR MB64_BUTTON_VALUES_SR0+0

       setf MB64_BUTTON_VALUES_SR0+0  ; turn off first 8 LEDs

        rgoto   MB64_BUTTON_Send

[/tt]

and it will work.

Wrong! See Keith's final solution below

Using more or less LEDs will require some understanding about masked bit operations. The appr. assembly instructions (like andwf) are documented in the PIC18F452 datasheet

Best Regards, Thorsten.

Link to comment
Share on other sites

Thanks so much Thorton,

Now that you explain it, it's quite clear. I did not find the MB64_BUTTON_VALUES_SR0 (+1,+2,+3 etc) locations. This will work perfectly.

Fortunately I have kept my buttons organised around the 8bit registers (also in banks of 8) so this will do well.

Many thanks again, Thorston.

Keith

Link to comment
Share on other sites

Thanks again Thorston for your help.

Well, I tried adding the line as suggested by Thorsten;

So I had this;

MB64_BUTTON_OnOnly

        ;; new

        clrf MB64_BUTTON_VALUES_SR0+3  ; clears fourth SR 8 LEDs

        ;; save status of button

        rcall  MB64_BUTTON_Hlp_SaveStat

        ;; when on: send button value defined in dump

        ;; when off: send nothing

        BRA_IFSET TMP1, 0, ACCESS, MB64_BUTTON_NotifyChangeEnd

        rgoto  MB64_BUTTON_Send

I re-assembling the App. and uploaded.

Something seems to be wrong.

First the OnOnly mode doesn't work. The buttons on SR3 act as if they are in OnOff mode and also the LCD jumps to Display page 1.

Oddly enough, the buttons on SR0 (D0-D3) do the same. I can't really tell about the menu buttons on SR0 (D4-D7).

In any case, without the changes to MB64 as above, in the OnOnly mode the LED goes off when the button is released. Is that supposed to happen?

I thought the;

        BRA_IFSET TMP1, 0, ACCESS, MB64_BUTTON_NotifyChangeEnd

is supposed to do nothing if TMP1 is set as in button released?

Any more suggestions?

Keith

Link to comment
Share on other sites

Thanks Thorsten,

I now have this;

MB64_BUTTON_OnOnly

    ;; new

    SET_BSR MB64_BUTTON_VALUES_SR0+3

    clrf MB64_BUTTON_VALUES_SR0+3, BANKED

    ;; save status of button

    rcall MB64_BUTTON_Hlp_SaveStat

    ;; when on: send button value defined in dump

    ;; when off: send nothing

    BRA_IFSET TMP1, 0, ACCESS, MB64_BUTTON_NotifyChangeEnd

    rgoto MB64_BUTTON_Send

This works a lot better, but it is inverted. i.e. All the LEDs are on Except for the one that is last released.

They don't go on until a first button is pressed, even from a different DIN SR (that seems expected).

Perhaps it's because the OnOnly doesn't seem to apply to the LEDs, as they go off with button release, same as OnOff mode? I'm not sure if that's supposed to be like that as this is my first Core.

If the OnOnly mode normally has an OnOff LED mode, then the best way is inverted like this. Maybe, Thorsten, you had thought of this arleady?

Just fyi, when in EDIT EVENTS, all the LEDs are cleared on every button press, and set appropriately on button release. Exiting EDIT EVENTS, clears all LEDs, which is probably normal.

Thanks again, Thorsten.

Keith

Link to comment
Share on other sites

Thanks Thorsten,

Actually that works, it is clearing, but as the OnOnly LED goes off when the button is released, it's pointless. The end result, visually with LEDs, is the same as before changes were made.

Hmmmmmm.

I guess my question now is how can I make the LEDs perform the same mode as OnOnly events?

thanks again

Keith

Link to comment
Share on other sites

Well, the last step is to prevent, that LEDs will be cleared again when you release the button.

Just move the "setf" instruction below the button state check as shown in the (modified) example above

Best Regards, Thorsten.

Link to comment
Share on other sites

Hi Thorsten,

That doesn't work, no LEDs light at all.

I'm wondering if my question caused some confusion.

First, the LEDs act like 'OnOff' mode, when the buttons are in OnOnly, i.e. they do not stay on in 'OnOnly' button mode.

Is this correct?

Your suggestion to use ;

MB64_BUTTON_OnOnly

    ;; new

    SET_BSR MB64_BUTTON_VALUES_SR0+3

    clrf MB64_BUTTON_VALUES_SR0+3, BANKED

 

actually works well, though inverted, except it is reflected in the LCD display by the buttons all being 'on' in that SR, which I would expect because BUTTON_VALUES are being altered, but it does not happen with the 'un-altered' App.

But it does inticate which button was pressed, by it's LED being off.

Because your suggestion, above, affects the display, is this a better method?

I could use this;

MB64_BUTTON_OnOnly

;; save status of button

rcall MB64_BUTTON_Hlp_SaveStat

;; my new lines to clear DOUT SR3

movlw 0

movwf MIOS_PARAMETER1

movlw 3

call  MIOS_DOUT_SRSet

;; restore MIOS_PARAMETER1 in case it's needed, I'm not sure yet?

movff TMP3, MIOS_PARAMETER1

;; when on: send button value defined in dump

;; when off: send nothing

BRA_IFSET TMP1, 0, ACCESS, MB64_BUTTON_NotifyChangeEnd

rgoto MB64_BUTTON_Send

This would not affect the display. But it is not inverted, and as the current button LED does not stay on in 'OnOnly' mode, I could invert the LEDS by changing to;

;; my new lines to set DOUT SR3

movlw 1

movwf MIOS_PARAMETER1

Then I would see the last pressed button as the one with the LED off?

But all this is because the LED does not follow the button mode 'OnOnly'.

I did not know this when I asked the first question, as I was still building the box, I just assumed. Now that the box is built and working just fine, (great job Thorsten and Smash), I do not know what the LED should do in 'OnOnly' mode. I thought that the LED would follow the button mode. Is there something wrong, or have I assumed wrong?

Perhaps you could help my confusion?

thanks again, and my first MB64 is working 1st time, no problems except this issue (which is minor, really), your time and effort is greatly appreciated.

Keith

Link to comment
Share on other sites

Before continuing with speculations, I think it's better to try out the code modification by myself. Just give me some days to find some time for getting into the firmware again.

Using MIOS_DOUT_SRSet directly is no solution, as the MB64 firmware takes control over LED values, and could always overwrite the shift register value (-> MB64_LED_Update) by values derived from MB64_BUTTON_VALUES_SR0, MB64_MBUTTON_VALUES_SR0, etc (depends on LED mapping specified in your midibox64.ini file)

If I understood you correctly, you are just searching for a "radio button" function. Is this correct? This is what I tried to program "blind", but as I see, there are too many details we haven't considered. (I programmed this firmware ca. 6 years ago... ;)). Such a usage model hasn't been considered at this time, therefore the implementation isn't straightforward

With the C wrapper, and an application built up from scratch, it would be much easier to get total control over buttons and LEDs.

What exactly are you planning to do with your MIDIbox?

Best Regards, Thorsten.

Link to comment
Share on other sites

Hi Thorsten,

Ok, I would like an LED to stay on when a button is in 'OnOnly' mode and previously pressed 'OnOnly' mode buttons to clear. Then I can use these buttons for program changes and see quickly which program is used.

best wishes

Keith

Link to comment
Share on other sites

  • 2 weeks later...

After scratching my head for days, I realised the solution is so simple. You were right Thorsten, we just forgot one thing. You set me on the right track, after working through pages of assembler, I realised the "rcall MB64_BUTTON_Hlp_SaveStat" line should be after the branch too.

Now, provided all required 'OnOnly' mode buttons are kept to SR groups, this works, perfectly. OnOnly mode button LEDs stay on, and clears when another is pressed. The LCD screen is properly updated to reflect the same.

MB64_BUTTON_OnOnly

    ;; when on: send button value defined in dump

    ;; when off: send nothing

    BRA_IFSET TMP1, 0, ACCESS, MB64_BUTTON_NotifyChangeEnd

    ;; turn off SR3 8 LEDs

    SET_BSR MB64_BUTTON_VALUES_SR0+3

    setf MB64_BUTTON_VALUES_SR0+3

    ;; save status of button  - now after the branch

    rcall MB64_BUTTON_Hlp_SaveStat

    rgoto MB64_BUTTON_Send

thanks again,

Keith

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...