I have something feeding commands into a nodejs program through noble (its talking to a BLE device that has a serial service), and I'd like to write a bit of a debounce / smooth. So for example:
"If [x-command] comes in more than 2 times in under [x-mills] set a flag to true."
What would be some ways to do this? ie: use an array for samples? write a timeout? etc.
I think the simple way is: store time of last call for each command in global array and compare stored time and current on new command.
Also you can don't override stored time if bounce is detect.
Related
You know that you can generate sound put in frequency (Hertz), but how do you create a sound where it will play a set amount of time in random Hertz? Like, you want to play 750Hz in 4 seconds. Is it possible to do that in Lua?
I was thinking about os.execute("echo \7") but that just creates a random beeping. I want to control the sound I create in a set amount of time and a set amount of frequency.
os.execute runs shell commands. Lua on its own cannot create sounds or set frequencies.
So you're actually asking how to beep from your shell for a given amount of time.
This could be achieved by powershell "[console]::beep(<frequency>, <duration_ms>)"
so os.execute('powershell "[console]::beep(4000, 1000)"'
should play a 4kHz sound for 1s.
Alternatively find a Lua library that play configurable tones.
It is possible in LuaJIT
local ffi = require'ffi'
ffi.cdef "int Beep(int Frequency_Hz, int Duration_Milliseconds)"
ffi.C.Beep(750, 4000)
I'm writing a driver for a pda with a goal of converting UART received key numbers to keystrokes.
The way i currently have this system set up is that when a key number is received, i can exec a program. In a config it is defined what command is executed if a certain number is received by my driver. It does this by fork()ing and exec()ing. It runs at boot and immediately parses these key numbers, so i intend to use this instead of a real keyboard.
Is there any program then, with which i could simply do something like
programname KEY_SPACE 1 to press KEY_SPACE
and
programname KEY_SPACE 0 to release KEY_SPACE?
Such a program must work without, as well as with X. I'd also prefer this to be able to do mouse events as well, however if there is a different program to do that, that's fine by me. It can be run as root as well, if need be.
What you need is to use uinput, it allows to emulate input device from userspace. You have documentation here: https://www.kernel.org/doc/html/v5.11/input/uinput.html
It has an example showing how to send a KEY_SPACE press event and then a KEY_SPACE release event.
I am writing a command line application in Swift that will run on Linux. I want to know what keys the user is touching in real time so I can show a value associated with each key.
Is there a a non blocking way of capturing user keystroke events in real time one key at a time?
I know of the readLine() function but that captures whole words and is blocking.
Anybody knows of a working solution?
If you know which input device (for example a USB keyboard) you want to read the real time keystrokes from, then you could use something like: https://github.com/Dev1an/InputEvents
It does not use standard command line input streams but reads the events directly from /dev/input/... devices instead.
I build a small game controller for the Z1.
I have a process reading values from a Joystick sensor. It works fine.
Then, I added a second process, reading the value of the battery sensor every 5 minutes. But it makes the Joystick stop working: the value does not update anymore!
I found a workaround: when I have to read the value of the battery, I deactivate the phidget_sensor, activate the battery_sensor, read the value and then deactivate the battery_sensor and reactivate the phidget_sensor.
But I would like to know why I can not have both sensors activated at the same time ?
Thanks
Comes from Here.
The ADC is the "analogue to digital converter", basically is the component that provides you the voltage signal levels of an analogue sensor, so then it can later be used to translate to a meaningful value.
What happens is the battery sensor driver and the phidget driver each when starts configures the ADC on its own, thus overwriting the ADC configuration.
The expected use of both of these components is actually how you are actually using: enable, measure, then disable. This way you ensure at all times the ADC is configured the way your application expects. If you want to have this done in a single operation then I'm afraid you will need to modify probably the phidget driver and include this.
I hope this is the answer you expected, as you are asking why does this happens.
I'm writing a little text mode application using curses on Linux.
For keyboard input I use the curses functions. Key auto-repeats work, e.g. if I hold a key down I get multiple key events until I release the key again.
Is it also possible to distinguish between real key events and those generated by the key repeat logic?
Background: The application is a little data-entry front-end where the user can modify integer numbers of certain parameters. In the long run the application will work without a standard keyboard. I will only have four buttons for data-entry: 'increase', 'decrease', 'ok' and 'cancel'.
Since the number ranges are large I'd like to know if the user holds down a key. If he does so I can scan faster through my numeric range by not incrementing my number by one but by 10 or maybe 100. If the user otoh taps the key the input method should be precise again and just increase/decrease the numbers by one.
Is this possible with the keyboard input functions of curses?
No - curses just receives keys from the terminal. If you really need it you could try to find out if the key repeats are automated or not by looking at the delay between each keypress. However, especially over remote connections, this might not be a good solution as the delay will be affected by network latency.
The best solution might be using UP/DOWN for small steps and PAGEUP/PAGEDOWN for large steps.