3hr Time delay between a button press - iphone

I would like to create a daily event, that is activated with a button press. So i would like to create a 3hr timers that disables the button once it has been pressed for 3hrs.
Im assuming i would use a NSDate code, but I'm unsure how the coding would go..
thanks.

This is how I would accomplish such a task:
1st button press - run event, capture current linux time. Example : 1332823536
add 10800 (which is 3 hours) which would make our example: 1332834336
save this number as an integer to NSUserDefaults
when the app starts back up check current time, turn it into an integer and make sure the current time is equal to or greater than the time you last saved (when the button was pushed)
if its NOT greater, disable the button - if it IS greater, enable the button.

Related

How to set remainder countdown by getting values from database in flutter

In this screen I am creating ride, and taking all these information include (Date and Time of ride) from the driver. After creating a ride I am saving all the data into firestore and getting data into next screen. I am also pasting the screenshot of next screen below
I want to show the countdown according to the date & time and when the countdown end, the start button will enable. how can we do it ? Kindly help me
First of all you have to get difference of time. Start countdown timer with that time. Once you get zero you can enable start button based on that condition. You can see this solution.

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

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

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.

How can I create a countdown timer that stops at zero on iOS?

The app description would be something like this:
There are:
3 buttons: start, reset and click here (the last one isn't enabled when the app starts)
2 labels: timer and mainTimer
When you click on start button, the timer goes from 3 seconds to 0 seconds, when it reaches 0, it stops, the click here button gets enabled and the mainTimer gets active, it goes from 60 seconds to 0 seconds. Finally, when mainTimer reaches 0, the start button gets disabled again, the mainTimer stops, and an alert shows up saying: time's up!
When the alert disappears everything gets the same state as in the beginning by clicking the reset button, and you are able to repeat the process.
My main problems are stoping the timers on 0, becoming enabled and disabled the click here button and to make the reset button putting everything as they were in the beginning.
Thanks a lot!!
Please take a look at the NSTimer class reference. Your feature may be implemented with a property for the countdown, a property with the NSTimer and putting the pieces together :)
NSTimer

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.