Comments (4)
First please do not use screenshots of code, you may like the syntax highlighting but it makes it more difficult for others to read or comment on sections of the code.. Use the markers of
RETTURN key to get start of a new line
Three ~ characters
Paste section of code (preferably including function start) Line numbers maybe different for some folks
After code start another line with Three ~ characters
This will highlight the block of code as code to people.
Secondly if this is a style of putting shortest block of two first it does not matter, that is for each establishment's coding standards documents.
If however this is suspicion of a bug, please note your suggestion would mean that the code would not work without other changes more than moving the 'break;' statements. It would work the OPPOSITE way. Please be aware those buffers and functions have been operating correctly for many people over the years without modification, have you found a corner case or situation where it fails?
For those wanting to see one of the functions it is
uint8_t PS2KeyAdvanced::available()
{
int8_t i, idx;
uint16_t data;
// check output queue
i = _key_head - _key_tail;
if( i < 0 )
i += _KEY_BUFF_SIZE;
while( i < ( _KEY_BUFF_SIZE - 1 ) ) // process if not full
if( key_available() ) // not check for more keys to process
{
data = translate(); // get next translated key
if( data == 0 ) // unless in buffer is empty
break;
if( ( data & 0xFF ) != PS2_KEY_IGNORE
// Suggestion is to move break to here ...
&& ( data & 0xFF ) > 0 )
{
idx = _key_head + 1; // point to next space
if( idx >= _KEY_BUFF_SIZE ) // loop to front if necessary
idx = 0;
if( idx != _key_tail )
{
_key_buffer[ idx ] = data; // save the data to out buffer
_key_head = idx;
i++; // update count
}
}
else
// move the following line 'break' to above
break; // exit buffer full
Also to show code block highlighting
from ps2keyadvanced.
Thank you very much for check and reply. I'm sorry for my recklessness. I'm new here and I've learnt a lesson. And I failed to convey my idea because of my awkward screenshots. Here comes a clearer explanation.
if( ( data & 0xFF ) != PS2_KEY_IGNORE
&& ( data & 0xFF ) > 0 )
{
idx = _key_head + 1; // point to next space
if( idx >= _KEY_BUFF_SIZE ) // loop to front if necessary
idx = 0;
// I guess the following if is a check whether the _key_buffer is full
if( idx != _key_tail )
{
_key_buffer[ idx ] = data; // save the data to out buffer
_key_head = idx;
i++; // update count
}
// So I might hope to put a branch here to exit for buffer full, if a change needs to be made
else
break;
}
// the following branch is executed when data indicates a key-ignoring case or data shows illegal value
// So this break is necessary but is not for 'buffer full' according to my understanding
else
break; // exit buffer full
I'm not challenging the effectiveness of the code. I just wonder about the branches and why the break is annotated with 'exit buffer full'.
from ps2keyadvanced.
Actually neither the break you suggest adding or the original one are actually needed, nor the check for if full you commented before.
As the outer While loop processes if there is space in the OUTPUT buffer for one output key code at a time, then only when a key sequence is available does it try to translate one sequence if complete,, the checks are extra safety checks that are actually redundant, the break could move up a block or be removed.
So the while loop could becomes with extra comments
while( i < ( _KEY_BUFF_SIZE - 1 ) ) // process if OUTPUT buffer not full
if( key_available() ) // now check for more input keys to process
{
data = translate(); // get next translated key
if( data == 0 ) // unless input buffer is empty (incomplete sequence received)
break;
if( ( data & 0xFF ) != PS2_KEY_IGNORE // Check not changes in things we ignore
&& ( data & 0xFF ) > 0 )
{ // Valid data to store at this point
idx = _key_head + 1; // point to next space
if( idx >= _KEY_BUFF_SIZE ) // loop to front if necessary
idx = 0;
// if( idx != _key_tail )
// {
_key_buffer[ idx ] = data; // save the data to out buffer
_key_head = idx;
i++; // update count
// }
}
// else
// break; // exit buffer full
}
else
break; // exit nothing coming in
Which I will consider testing and updating when I get time
from ps2keyadvanced.
Tested the fixes and released updated version
from ps2keyadvanced.
Related Issues (20)
- Analog Input, is it possible? HOT 2
- Support for STM8S mcu (SDUINO) HOT 9
- Toggle typematic on/off entirely? HOT 2
- Acknowledging additional startup PS/2->Host messages HOT 4
- CODE AA error HOT 6
- Hold CAPS HOT 3
- Host-to-Device: Initial Clock low too short HOT 3
- increase buffer ?? HOT 3
- ESP32 garbage values HOT 9
- Arduino Nano Every ( MegaAVR board) Serial HOT 1
- My board does not work with this library
- ` and ~ keys and Keyboard . does not work HOT 1
- Send own bytes to keyboard HOT 3
- Pause key gives wrong code. setLock(.) doesn't work in setup() HOT 19
- 2 keyboards in 1 board HOT 3
- After pressing the NUMLOCK key, there is no response when any key is pressed. HOT 17
- weird mapping in some cases and no shift
- Missing release `V1.0.10`? HOT 2
- Keyboard almost working
- Parity in argument bytes sent from host
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ps2keyadvanced.