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

[WIP] initial bluetooth support between split keyboards #18

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

funkycode
Copy link

In general that adds basic support for one half to connect to other one via bluetooth using same logic uart keyboard have
Not sure if it is ready to be merged, but it can be used as reference, in general it works, but:

  1. there is small delay sometimes (not sure if bluetooth issue or problem with code)
  2. you need to turn right half after first one in order for it to connect (not sure if should be done on keyboard side or lib side)

Opening PR for reference and some feedback, if it is okay (if not you can close it till it would be ready)

it can be tested with wireless corne on repo https://github.com/funkycode/tinygo-corne (works with pinout of typeractive.xyz version, as well with niceview)

@funkycode funkycode marked this pull request as draft October 30, 2023 20:06
Copy link
Owner

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
I think many sections are good.

However, I think we need to be careful not to cause overwriting in Get().
I tried a few myself.
I think the following code will almost eliminate the problem.
If it looks OK, I suggest you merge it into funkycode:main.
fcbe49d

Comment on lines +239 to +242
d.buf[0] = value[0]
d.buf[1] = value[1]
d.buf[2] = value[2]
d.changed = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part may be overwritten before it is processed by Loop().
Perhaps you need to use RingBuffer or something similar, as in the following source.
This is the same as kbuart.go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding ringbuffer as briefly read it, does it mean we can get the bytes out of order and need to handle it?

In general i suggest to add RemoteKeyboard that will have buffer and method to pass info to it and read from it.
that way we can implement both ble and uart keyboard as same type where the difference would be how we save and read from. WDYT?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I created RingBuffer is to address the following issues.

  1. WriteEvent() : Here d.buf is set.
  2. WriteEvent() : Here, d.buf is set again. At this time, the data received in the first WriteEvent() is overwritten.

RingBuffer can be used to suppress overwriting.

RemoteKeyboard is a good approach.
I think the UpDowner interface is the way to go at the moment, but there may be a better way.

blekeyboard.go Show resolved Hide resolved
@sago35
Copy link
Owner

sago35 commented Oct 31, 2023

Since the current Loop() is a little too slow, it would be better to run the loop with a 1ms wait as shown below. It will be a little more responsive.

err = d.Init()
if err != nil {
return err
}
cont := true
for cont {
err := d.Tick()
if err != nil {
return err
}
time.Sleep(1 * time.Millisecond)
}
return nil

Co-authored-by: sago35 <sago35@gmail.com>
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.

None yet

2 participants