Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add New Function GetReleased #55

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Add New Function GetReleased #55

wants to merge 11 commits into from

Conversation

Frenchy62620
Copy link

Hi Anders, sorry ist the first time i am using github, that seems a good tool for sharing project..!!
i am not expert in C# but i have unsderstood some tips from your program.. and so i propose an addon

maybe its more clever to have only one class in strategy folder (fusion with GetPressed and getrelease strategy file and create one class with 2 method isPressed and isReleased)

like the function Getpressed

state before: key is Down and State current: key is UP = Key is Released

state before: key is UP and State current: key is DOWN = Key is Pressed

so the Python script is functional:
if keyboard.getPressed(Key.S):
diagnostics.debug("key pressed")

if keyboard.getReleased(Key.S):
diagnostics.debug("key released")

if joystick[1].getPressed(0):
diagnostics.debug("joy button pressed")

if joystick[1].getReleased(0):
diagnostics.debug("joy button released")

if mouse.getPressed(0):
diagnostics.debug("mouse button pressed")

if mouse.getReleased(0):
diagnostics.debug("mouse button released")

Adding new functionality for Released key like the GetPressed key
Update for GetReleased
Update for GetReleased
@AndersMalmgren
Copy link
Owner

Should I not take a look at this code?

@Frenchy62620
Copy link
Author

HI Anders,

i am loacket at home after a broken leg so i take time to understand FreePie and C#!!
very good tool!!

i have closed the pullrequest but i have reopened it

  1. i have read your code about keypress

so a problem exist because you are using dict to save last state key, stickbutton ...

but during the same frame

if you do 2 tests of getPressed

if Keyboard.getPressed(Key.S):
diagnostic.debug("press S 1")
if Keyboard.getPressed(Key.S):
diagnostic.debug("press S2")

when the first test is ok,
the second test is always false because the state of laststate key was modified in the dict of the first test

so if we are using variable to stock state there is no problem

maybe it will be better to use OldBuffer to stock laststate and Buffer to stock current state

m_KeyboardStateLast = m_KeyboardStateCurrent;
m_KeyboardStateCurrent = m_Keyboard.GetCurrentState();

ans same for stick and mouse

but that needs some change in source code..

i have reanimed the pull if you want to see..

another modification is arriving
more functions

getHeldDown(key, lapse): true when key down during lapse
getPressedHeldDown(key, lapse): true only one when laspe is touched

and a list of functions
to test povU1 to U4, povR1 to R4, povD1 to D4 and povL1 to L4 for test pov UP RIGHT DOWN and LEFT

Regards
Thierry

----- Mail original -----

De: "Anders Malmgren" [email protected]
À: "AndersMalmgren/FreePIE" [email protected]
Cc: "Frenchy62620" [email protected]
Envoyé: Samedi 6 Juin 2015 21:05:43
Objet: Re: [FreePIE] Add New Function GetReleased (#55)

Should I not take a look at this code?

Reply to this email directly or view it on GitHub .

@Frenchy62620 Frenchy62620 reopened this Jun 7, 2015
@AndersMalmgren
Copy link
Owner

Yes I know, I'm not the orginal author of the code, and I have not had time to rewrite it. What it should do is to check state only once per iteration of the script. This could be done similar to the SetPressedStretegy, having a method that triggers each iteration and clears the state

https://github.com/AndersMalmgren/FreePIE/blob/master/FreePIE.Core.Plugins/Strategies/SetPressedStrategy.cs#L21

@Frenchy62620
Copy link
Author

Its okay, i have time to rewrite the code and fix that

thierry

----- Mail original -----

De: "Anders Malmgren" [email protected]
À: "AndersMalmgren/FreePIE" [email protected]
Cc: "Frenchy62620" [email protected]
Envoyé: Dimanche 7 Juin 2015 12:16:28
Objet: Re: [FreePIE] Add New Function GetReleased (#55)

Yes I know, I'm not the orginal author of the code, and I have not had time to rewrite it. What it should do is to check state only once per iteration of the script. This could be done similar to the SetPressedStretegy, haveing a method that triggers each iteration and cleares the state
https://github.com/AndersMalmgren/FreePIE/blob/master/FreePIE.Core.Plugins/Strategies/SetPressedStrategy.cs#L21

Reply to this email directly or view it on GitHub .

@AndersMalmgren
Copy link
Owner

Ouch, not nice with broken leg, but nice to learn C# :D

I'm looking at fixing so that you can inject a IScriptContext and listen to when the script loop is updating. That way you do not need to forward the state from the plugin etc

@AndersMalmgren
Copy link
Owner

btw, held down could be achived by doing

if filters.stopWatch(keyboard.getKeyDown(Key.A), 5000):
    diagnostics.debug("Key pressedn for 5 seconds")

@Frenchy62620
Copy link
Author

ist okay but

my helddown function will be slighty different

it accepts to test more timer different for same key or button

if filters. stopWatch (keyboard. getKeyDown (Key.D), 2000 ):
diagnostics. debug ( "Key pressedn for 2 seconds" )

if filters. stopWatch (keyboard. getKeyDown (Key.D), 4000 ):
diagnostics. debug ( "Key pressedn for 4 seconds" )

so this coding is not functional with that! i know, in French we say "i am looking after the small beast"

but no problem..
other info
i have found a good coding to fix getPressed with 2 tests and avoid to use strategy class

----- Mail original -----

De: "Anders Malmgren" [email protected]
À: "AndersMalmgren/FreePIE" [email protected]
Cc: "Frenchy62620" [email protected]
Envoyé: Dimanche 7 Juin 2015 20:18:06
Objet: Re: [FreePIE] Add New Function GetReleased (#55)

btw, held down could be achived by doing
if filters.stopWatch(keyboard.getKeyDown(Key.A), 5000 ):
diagnostics.debug( " Key pressedn for 5 seconds " )

Reply to this email directly or view it on GitHub .

@AndersMalmgren
Copy link
Owner

Hmm, the NeedIndexer part uses the whole argument as indexer, so it should work, whats the outcome?

https://github.com/AndersMalmgren/FreePIE/blob/master/FreePIE.Core/ScriptEngine/Globals/ScriptHelpers/FilterHelper.cs#L121

Btw, the NeedIndexer part of FreePIE is not 100% bulletproof too, I got a thread going about it here

http://stackoverflow.com/questions/30682752/iterate-the-ast

edit: I tried this script

if filters.stopWatch(keyboard.getKeyDown(Key.D), 2000):
    diagnostics.debug("Key pressedn for 2 seconds")

if filters.stopWatch(keyboard.getKeyDown(Key.D), 4000):
    diagnostics.debug("Key pressedn for 4 seconds")

And it correctly fires the two at correct times

@Frenchy62620
Copy link
Author

Hi,

3 questions please

for stick which have poor number of button

its interesting to have multiple configuration

so the code (nevermind of the function)

If (released(key C held during 2sec) then conf=1
If (released(key C held during 4sec) then conf=2
if (released(Key D) then conf = 0
and following the value of conf, we could have 3 config..

but it s interesting to have a signal to valid the new conf

Beep(Frequency, timelapse) is interesting

If (released(key C held during 2sec) then conf=1 ; Beep(500, 500)
If (released(key C held during 4sec) then conf=2; Beep(1000, 500)

so we have diff tonality following the conf.

the problem is : the fonction beep (from import winsound)

so Beep(500, 2000) make a bi during 2 second and the program is stopped during this lapse.

the solution: is it possible to use thread possibility to launch BeepFunction in another thread C# when this function is called from python script (example FreePie.Bip function) ?

in C++ i know to do that but i dont know how to implement this in C#

is it possible to have global variable FreePie.FrameCount, FreePie.FrameRate, or FreePie.Interval to modify the FrameRate of the program
from the script python
i dunno if exist in FreePie

  1. is there a global counter which gives the tickcount for example?

----- Mail original -----

De: "Anders Malmgren" [email protected]
À: "AndersMalmgren/FreePIE" [email protected]
Cc: "Frenchy62620" [email protected]
Envoyé: Lundi 8 Juin 2015 09:17:44
Objet: Re: [FreePIE] Add New Function GetReleased (#55)

ah, thats an easy fix though. the code need to include the milliseconds in the indexer
https://github.com/AndersMalmgren/FreePIE/blob/master/FreePIE.Core/ScriptEngine/Globals/ScriptHelpers/FilterHelper.cs#L122
[NeedIndexer] public bool stopWatch( bool state, int milliseconds, string indexer)
{
indexer = indexer + milliseconds.ToString();

        ...
    } 


Reply to this email directly or view it on GitHub .

@AndersMalmgren
Copy link
Owner

  1. Today FreePIE only have speech.say that can give you feedback using sounds
  2. FreePIE has a mechanism for settings the timing of the script
if starting:
    system.setThreadTiming(TimingTypes.HighresSystemTimer)
    system.threadExecutionInterval = 2

This will select the HIghres system timer stategy and set the sleep between script iterations to 2 ms
The default is TimingTypes.SystemTimer which has a minimum of 16 ms sleep between iterations of script

  1. Not built in no, but you can just do
if starting:
    ticks = 0

ticks += 1

@Frenchy62620
Copy link
Author

Hi Anders,

New file Added: FreePIE.Core.Plugins\Strategies\GetHeldDownStrategy.cs

contains all functions needed for getHeldDown and getPressedHeldDown

The file FreePIE.Core.Plugins\Strategies\GetPressedStrategy.cs is now just used by WiiMote, Keyboard, joystick and mouse dont use it now

Files about devices modified
FreePIE.Core.Plugins\KeyboardPlugin.cs
FreePIE.Core.Plugins\MousePlugin.cs
FreePIE.Core.Plugins\joystickPlugin.cs

New functions: getHeldDown, getPressedHeldDown far all devices (excepted wiimote)
all functions are okay with this sequence (sample code) and give same result during same frame:
(one exception is getPressedHeldDown and getHeldDown with same key/button and same duration, just use one time in a test or take the value in variable if it is necessary)

    # the same key/button could have more different timer
    if joystick[0].getPressedHeldDown(POV0.Down, 2000):
            diagnostics.debug("pov0Down Heldpressed after 2 sec")
            speech.beep(200,300)
    if joystick[0].getPressedHeldDown(POV0.Down, 4000):
            diagnostics.debug("pov0Down Heldpressed after 4 sec")   
            speech.beep(500,300)
    if keyboard.getPressed(Key.C, 2000):
            diagnostics.debug("C pressed 1")
    if keyboard.getPressed(Key.C, 2000):
            diagnostics.debug("C pressed 2")


    For joystick, all functions about the gestion of POV has been rewritten/added
    now we could test POV0 to POV3 if Up,Left,Down,Right (and intermediary if stick accept)
    All functions could be used with all button of all pov

File modified
FreePIE.Core.Plugins\SpeechPlugin.cs

New function: speech.beep(frequency, duration)
this function doesnt stop the script, the Beep function is executed in another thread
dunno if its the right place for this function, but really easier to implement here.

@Frenchy62620 Frenchy62620 reopened this Jun 8, 2015
@AndersMalmgren
Copy link
Owner

Sorry I cant pull this code, it breakes too many code conventions that we have. But I will see what i can take and what not. Thanks

@Frenchy62620
Copy link
Author

No problem Anders, i understand that..

i am not expert in dev and i understand you have some rules to respect
i have just the skill to learn quickly...and the program is good for me to learn
regards
Thierry

----- Mail original -----

De: "Anders Malmgren" [email protected]
À: "AndersMalmgren/FreePIE" [email protected]
Cc: "Frenchy62620" [email protected]
Envoyé: Mardi 9 Juin 2015 08:59:52
Objet: Re: [FreePIE] Add New Function GetReleased (#55)

Sorry I cant pull this code, it breakes too many code conventions that we have. But I will see what i can take and what not. Thanks

Reply to this email directly or view it on GitHub .

@AndersMalmgren
Copy link
Owner

I'm working on a new mechanis for script state, it can be used like this, sorry I screwed up tab/space somehow, will have to fix that

https://github.com/AndersMalmgren/FreePIE/blob/MoveToStructureMap/FreePIE.Core.Plugins/Strategies/GetPressedStrategy.cs

@jmriego
Copy link

jmriego commented Jan 8, 2019

I'm trying to understand a bit more the code for GetPressedStrategy. What is the purpose of it and why not having the getPressed function directly in the plugins? I'm trying to figure out the best way to add the functionality that this pull request is trying to add

@Frenchy62620
Copy link
Author

Frenchy62620 commented Jan 8, 2019 via email

@jmriego
Copy link

jmriego commented Jan 8, 2019

That makes sense. Good luck with the project and thanks a lot for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants