FC7 Mouse click simulation interupt

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times
Contact:

FC7 Mouse click simulation interupt

Post by streammaster »

Hi Guys,

I'm really struggling with FC documentation. I just can not find the answer how to use FC 'advanced' features.

I watched the video example showing how to change component property by mouse click. There is stated that for mouse we need a Macro created which will be called when the Event is activated. This macro has to have proper 'framework'. In case of the mouse, the macro will receive some mouse returns specific parameters as well which can be used to define the mouse position (like variables).

I created the example. However, i do not want to change the property of the specific component (not really need parameters), but instead, I want to detect that user clicked on the panel, and then I want to activate particular simulation code. In example, if the macro is activated it will overwrite the LCD message ('initialized')
In the video, it is clearly stated that the Macro will be executed when the mouse is clicked (in my case released), but my example shows that nothing is happening.

What I'm doing wrong?
Attachments
Mouse release interupt.fcfx
(9.78 KiB) Downloaded 222 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by Benj »

Hello,

You hadn't assigned the macro to the event in the events tab of the project explorer window.

Here is a working version. Please note that the switch component consumes mouse clicks/releases to function so I have added a generic primitive object you can click on to trigger the event.
Mouse release interupt.fcfx
(11.23 KiB) Downloaded 223 times
Also please note that we recently found and fixed a problem where primitives were not working with mouse events. This has been fixed as part of the updated files available here. viewtopic.php?f=63&t=18760

Delays don't work inside event macros, so if you need delays you will need to use a timer event. I can help with this if needed. We use timer events for things like moving the robot around on the panel. Some details on how this works is available here. https://www.matrixtsl.com/wikiv7/index. ... eled_robot

streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by streammaster »

Hi Ben,

It is strange that the macro was not attached to the mouse as it was created from there. Perhaps I removed to return to function and become 'not compatible'? Anyway, I'm learning this and this is my first attempt to create my own simulation.

I loaded your version, but still, nothing is happening. I removed the timer in the macro (it was green shaded) but still display would not update anything as instructed in the macro. Is display working when you simulate the project? Perhaps there is some global setting which prevents my simulation?

What I'm actually trying to do is a new component. In the panel simulation, I need to update the component panel and all variables when anything is pushed (or update specific part when is pushed). In case of the 'basic_sim_switch' if the user changes status I need to update the variables (on release) how I do this?

Regards,

Igor

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by Benj »

Hello Igor,

Have you applied the fixes here. There was a bug with mouse events on primitives which is included in the latest updates.
viewtopic.php?f=63&t=18760

Also note that my example you click on the primitive shape and not the switch as that consumes the mouse release event.

Other then that the program was working well for me and changing the text on the LCD and should allow you to build up more functionality to set variable values etc.

Here is another example to play with, this should change the colour of the object when clicked and should move the object when dragged.
MouseEventDemo.fcfx
(11.32 KiB) Downloaded 209 times
If this is not working for you then check you have applied / extracted the fix files to the correct place. For most users they will have to extract the contents of the archive into the "C:\Program Files (x86)\Flowcode 7\" folder.

streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by streammaster »

Hi Ben,

Both examples are working on my work computer. It may be that on my home PC I haven't update FC with fixes. I will check it tonight.
However, I still have a problem building my simulation:
What would be a work around so I can generate interrupt on the push button simulation component (or any other component which 'consumes' the interrupt)? Is there some low-level control for this?
What I need is when the simulation switch button is pushed (and the state is changed) on the panel, so I can update immediately the variable associated with the latest status I need to read the button status and create an appropriate value and update the text on the panel and update variable register.
Can I create my own simulation component which will become a sub component? Can component create an interrupt or perhaps an event which will appear in 'EV'?
If you could push me in the correct direction I'm happy to explore it.

All of this I need to create UI for my component. The component is a peripheral chip simulation which is connected to MCU by simulated pins, and I need to be able to change the configuration of the internal registers when user change value on the panel (in my case by setting the simulation push switch). I need to update the value during the simulation as the real chip will work.

Regards,

Igor

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by Benj »

Hello Igor,

The simulated switch already takes and processed the mouse events so they are not available to you without edits to the component to forward on the event.

I would instead use primitive objects and then as shown you can use the click / release / drag events to do different things. You can then build these into a component if you like. Or a component inside a component... etc.

Here is another example for you to play with which should hopefully help with what you want.
MouseDemo2.fcfx
(15.79 KiB) Downloaded 219 times

streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by streammaster »

Hi Ben,

I think i find another bug.
I made a prototype for my buttons, and in principle it is working but not relay completely OK.

Once the color property of the object is set by mouse click on the object it stops to response on some other simulation event trying to set the different color value.
I made the prototype with 8 'Buttons' which are Hemisphere Shape component. In Ev_Click macro i'm changing (toggling) the color of the object which is clicked on from red to green AND after this event i'm setting the color of the B2 to black. So when the mouse is clicked to any of the buttons the B2 should be set to black every time.

I created two versions. In first version in the main loop i'm switching color of the B2. And the system works as expected.
In second version i'm changing the color of the B1 and B2 is set only by events in Ev_click. You will notice that as long as you do not click on B2 it works ok (you can test this only once as B0 goes to black and stay's there. But if you click on B2 it will change the color to red or green and will never become black.
If you stoop at this point simulation and inspect the Property of the B2 you will see that the Color is set to black, but the panel shows red color. It looks that something is going wrong with panel refresh. The panel will also not reinitialize on restart of the simulation. For components which where changed by mouse click and If you change color property manually this will not reflect any changes on simulation start. You need to restart the FC application to recover.

Regards,
Igor
Attachments
Second_version_color_update.fcfx
(25.68 KiB) Downloaded 208 times
First_version_color_update.fcfx
(25.67 KiB) Downloaded 198 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by Benj »

Hi Igor,

I think I can see what's going wrong and yes it does appear to be a bug. Hopefully we can work around the problem for now.

The primitive object is wrapped inside a component so the tree of the shape looks like this.
Untitled.jpg
Untitled.jpg (20.56 KiB) Viewed 6090 times
B2 is the component and the shape1 is the child primitive shape that appears on the panel.

Inside the Ev_Click macro we set the colour of B2 to black which fires a Property event for component B2 which then copies the new colour to the primitive shape1.

When we click on B2 it sets the colour of B2 which fires the property change and sets it to red/green however when we set it to black at the end of the macro the property change event is not firing a second time. So the property value gets changed but the colour is never copied to the primitive object.

Subsequent writes to set B2 to black are ignored because the B2 colour property is already set to black, it's the inside primitive object that is not.

So how do we work around this.

1) We could create a macro that writes the colour to the root object and all child objects, similar to my example above which scans for clicks on root and child objects.

2) We only write one colour to any single object inside the Ev_Click macro. so we only set B2 to black if it is not B2 that has been clicked.

I hope this helps and I'm making a note for us to investigate.

I could add simulation timers to each primitive component to force colour copying on a regular basis but I think this will have an impact when there are a lot of primitive objects present on the panel and it''s only this corner case where you write the colour twice inside an event that causes it to break.

streammaster
Posts: 78
Joined: Mon Jul 31, 2017 11:14 am
Has thanked: 7 times
Been thanked: 13 times
Contact:

Re: FC7 Mouse click simulation interupt

Post by streammaster »

Hi Ben,

Unfortunately because of this component bug, i can not find the method to work around. I have my buttons collection and i changing colors inside ev_click as you sugested. I managed to get the object selection by manually adjusting the offset in the code, so this is now working.

However i need to create another macro which inspects the color of the sphere and return value in order to get the state of the buttons in to the register. This unfortunately is not returning the color of the object from the screen.

This problem is in the simulation as well when we stop the simulation. Bellow you can see the problem: The B4 on the panel is green, but the B4 property is showing Red. When i try to do Component.Proprty.GetValue(B4,"Color") i get return string "255" Which is red. For green i expect "65280".
object wrong color.PNG
(73.87 KiB) Downloaded 3306 times
What i can do to get this working? I need to write 1 when is red and 0 when is green.
I need to do this at start up, once user starts to push the buttons on the panel the register is updated from ev_click.

Regards,
Igor

Post Reply