RENODE How press a button for 5s and invert the methods Press and Release to be compatible with button with pullup configuration - simulation

I want to simulate in RENODE my stm32f030 to pressing a button for 5 seconds. But I have some problems related to the time and also with the RENODE method to simulate a Press and a Release of the button
In my firmware I configured the pin that is connected to the button as pull-up, that is, the button without pressing it has Status=TRUE. When the button is pressed, it goes to GND and Status=FALSE.
I did a 'debug' in the RENODE methods, I simulate a Press and then with the Pressed method it returns the status, you can check that:
Press results in True status
Release results in False status
Is there a possibility to reverse this method? Or do I put it as an alias in the robot framework? I found very little documentation, any light on my problem is already welcome
About the problem with time, when I execute the Press method and then the Release method and wait for close to 20 seconds it executes the action which is to blink together the Red and Blue LEDs, see below. However in my firmware it is configured to occur an interruption in the timer after 5s.
I read a bit about this in the official documentation (https://renode.readthedocs.io/en/latest/advanced/time_framework.html) and I suspect it is related to this, but I haven't identified what I need to do to fix it.

Reversing the state of a button is quite easy.
As in the miv-board.repl file, you can do the following:
user_switch_0: Miscellaneous.Button # gpioInputs 0
invert: true <--- this is relevant here
-> gpioInputs#0
Regarding time flow, Renode operates in virtual time domain to ensure determinism of execution, regardless of the host machine. It can be similar to real time flow, but depends heavily on the type of application you run. If you poll a lot and not use interrupts to sleep - things will be slower.
To get information about current virtual time you can run emulation GetTimeSourceInfo and see the output like this:
(machine) emulation GetTimeSourceInfo
Elapsed Virtual Time: 00:00:00.304409 <--- you want this to be 5s
Elapsed Host Time: 00:00:00.831891
Current load: 2.5
Cumulative load: 2.73280684868056
State: WaitingForReportBack
Advance immediately: False
Quantum: 00:00:00.000100

Related

How to make a button trigger an event (Timer)?

I am working on a fire evacuation project and would like to trigger an event after clicking a button. Basically I want to begin the fire evacuation process manually using the button feature but would like to trigger a timer for about 60 seconds to give the pedestrians time to evacuate using the event feature.
I have tried to make pedestrians stop the evacuation process by manually clicking another button but would like to use an event trigger timer instead as this will be a better way to conduct my simulation. I cannot seem to trigger an event once the button is clicked. I've tried changing the trigger type but not sure where to go from there. Is there any code that is required or another step that is required?
Even though a dynamic event is fine in your application, you can also use a user control event:
And then in your button you can use the following code:
event.restart(60,SECOND); //you can choose any timeout here
or
event.restart(); // this will use the configuration, which in this case I set up to 60 seconds
The difference between a dynamic event and a user controlled event is that if you click the button again:
With the dynamic event, you will generate another instance of the event, meaning that if you click the button at t=0 seconds, and t=30 seconds, you will generate 2 events at t=60 seconds and t=90 seconds
With the user control event, you will restart the same event. if you click the button at t=0 seconds, and t=30 seconds, you will generate a unique event at t=90 seconds.
So depending on which one you prefer... you can choose. I would prefer the user control in case you click the button 2 times... or if you regret clicking it so fast... I don't know
Use the Dynamic Event for this.
Set it up by pulling it from the AnyLogic Agent Library to the Workspace and give it a name (here: MyDynamicEvent).
Add the code you want to have executed when the timer runs off in the Action field
Set one (or several) timed instance for this event by using the code create_MyDynamicEvent(60,SECOND);. Note: The syntax of this statement is always create_ followed by the actual name you gave your DynamicEvent type.

ItemClickListener kicking off while ItemLongClickListener happens

The best way I can describe this is the following. I have a poster gallery that has a bunch of images. The selected poster gets highlighted as the user moves back and forth through the gallery. I have the following code set on the poster gallery:
Gallery posterGallery = (Gallery) context.findViewById(R.id.moviePosterGallery);
posterGallery.setAdapter(new MoviePosterImageGalleryAdapter(context, key,
item.getCategory()));
posterGallery.setOnItemSelectedListener(
new MoviePosterOnItemSelectedListener(bgLayout, context));
posterGallery.setOnItemClickListener(new MoviePosterOnItemClickListener());
posterGallery.setOnItemLongClickListener(new MoviePosterOnItemLongClickListener());
What seems to happen is if you press the Remote on the vizio costar, both the Click and Long click events are being fired if you hold down the OK button. As in my case a dialog pops up when a Long click is received, but also the poster launches the video related to that to start playing which is part of the ItemClickListener code..
When testing the same code on a Nexus 7 tablet, only the long click is fired, not both. Is there a way to handle the long click correctly on Google TV. I'm using a vizio costar with Google TV 3 if that helps.
Also, if you move the mouse pointer over the item, and then hold down the - key on the front of the remote, only the long click event is triggered. It just seems to be related to the OK and how long that held down.
I looked at the following similar issue:
onListItemClick and onItemLongClick Google TV
but I already have the onItemLongClick returning true when it handles the event.
There is a quirk with the Vizio remotes. The OK button is not mapped to the right keycode. The Vizio remote sends KEYCODE_ENTER when OK is pressed when in fact it should be sending KEYCODE_DPAD_CENTER. This is what is causing your issue I think. If you try using AbleRemote as the input device you should be able to see it working as expected. Now to solve your issue you may have to go to a keycode listener if a keyboard is present and detect the key events on the posterGallery to fire off short and long clicks.

Reason for 5 sec delay to show an activity on pressing the home button?

I am facing delay of 5 sec to show an Activity after pressing the HOME key. I had gone through some post and found that after pressing the HOME button, android prevents services and broadcast-receivers from calling startActivity for 5 seconds.
Q1. Can anyone please let me know the reason to happening this delay ?
Q2. When I modified the ActivityManagerService::checkAppSwitchAllowedLocked() to always return true, it avoids checking lock and hence Activity gets shown without any delay. Would it be a good solution to avoid delay or it may cause any wrong effect in other ways ?
I know, it's probably too late (half year passed). However, here is the answer
You won't be able to get this permission on not rooted phone, unless your application is signed with the same keys as system. Android has some permissions like that.
Also, you may be interested to check this question. Starting an activity from a service after HOME button pressed without the 5 seconds delay

DispatcherTimer blocks the UI from being updated?

I have two Buttons in the View, one for recording some sound, one plays the recording when recording is done. When recording is done, I set the VM property of recording_done to 1, which is used for CanPlay(), which enables the Play button. Everything works fine so far.
I added a timer to auto stop the recording after two seconds. after some trials and errors, I settled with a DispatcherTimer. My problem is the UI (Play button) does not gets enabled until I clicked the WPF window (somewhere/anywhere on the windows). Clearly the debug msg says the recording_done is set to 1. That should trigger the UI update, but it does not, until I clicked on the windows.
I tried both ways, 1. Recording button bind to Command in ViewModel, there I start the timer and stop the timer. 2. put the recording button handler and timer code in the view's code behind. similar problems.
Any suggestion? Is this a threading/UI update issue? Thanks.
If your play button is bound to a command, and the CanExecute() of the command is bound indirectly to the recording_done property or field, it won't update until the CanExecuteChanged event on the ICommand is raised, or until WPF decided to requery the commands. I suspect this is the problem - you need to have the ICommand raise CanExecuteChanged.

Timed disabling of button in pygtk

I want to show a dialog box with an OK button that is disabled for a short period of time (perhaps 5 seconds). The other buttons would still need to be responsive during this time.
You need a GTK+ timeout for that. First let the button be disabled. The timeout will call a function to enable the button.
Please not that for usability reasons, it should be visible for the user that a timer is running. You can do this by counting down, like "OK (5)", "Ok (4)" etc. until you enable the button.
See here:
http://graphics.sci.ubu.ac.th/api/pygtk/tutorials/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html
The idea is to set the timeout to 1 second (1000 ms). Everytime the callback is called you change the button label and return TRUE. When your callback is called the 5th time, you enable it and return FALSE. This will remove the timeout.