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

Connect two SIMHUB devices using I2C. #43

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

Conversation

wapophis
Copy link

@wapophis wapophis commented Mar 17, 2024

The underlying idea is to extend the digital or analog inputs and outputs to connect more devices together and make them compatible with the serial protocol used by SimHub. To achieve this, we connect two devices (for now, only two) using I2C, so that the Master sends its information via I2C to the Slave, which decodes and forwards this byte stream through the configured transport layer.

Features:

  1. Config simhub device as I2C Master. ✓
  2. Config simhub device as I2C Slave. 🚧
  3. Clear config in address. ✓
  4. Segregated transport layer. ✓
  5. Decode serial protocol when Simhub I2C slave must react ( like GAMEPAD MODE ) to serial input via I2C port.
  • [ ✓] 🚧 (Buttons Working)
  • [ X] 🚧 (Encoders Working)
  • [ X] 🚧 (Other working)
    - [TBD] Bypass analog readings from master -> slave with custom serial protocol.
  1. Bypass I2C Input on slave to transport layer configured WIFI/SERIAL. ✓

wapophis added 2 commits March 17, 2024 20:49
@ecoreng
Copy link
Contributor

ecoreng commented Mar 17, 2024

is this replacing serial with i2c?

src/ArqSerial.h Outdated
}

void I2CustomPacketStart(byte packetType, uint8_t length) {
Wire.write(0x09);
Copy link
Contributor

Choose a reason for hiding this comment

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

the whole point of StreamWrite is to be able to replace it with whatever you need (in this case Wire.write), so that you don't have to add much custom code here :)

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

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

Fix at b1ef413

@wapophis wapophis changed the title Added main byppass to serial function, As example only buttonStatusChangedEvents are resended to IC2 with the same serial protocol. Connect two SIMHUB devices using I2C. Mar 20, 2024
@wapophis
Copy link
Author

wapophis commented Mar 20, 2024

is this replacing serial with i2c?

Only if the device is configured as I2C Master.

@ecoreng
Copy link
Contributor

ecoreng commented Mar 20, 2024

This is very interesting, thanks for adding the description. I was wondering what the approach was going to be on the other side.
Didn't you originally use an arduino board originally as "slave"? does this firmware work on that board too?

@wapophis
Copy link
Author

wapophis commented Mar 20, 2024

This is very interesting, thanks for adding the description. I was wondering what the approach was going to be on the other side. Didn't you originally use an arduino board originally as "slave"? does this firmware work on that board too?

I'm using the original Arduino in the other Side with Joystick support enabled. But thats impl isn't complete yet, with buttons is working in the other side fine. I'm planning to add the serial protocol decoder/bypasser to Joystick support in this repo. The next commit is preparing the files for this approach. Off course slave in arduino needs updates too to work properly with this approach, beause the decode phase and slave config must be implemented. This works is in progress, i hope to send it to SimHub's developer if he has a repo to include in his codebase.

---- HOW TO INTEGRATE THE SLAVE INTO THE SIMHUB AVR PROJECT ----

You can checkout the slave logic, in the 99a49f8 commit, this logic is attached to the original arduino simhub project in the DisplayClientV2.ino after ading de SimHubProtocolDecoder.h to the project. Later you make an instance in the ino about de EventCallBackManager and setup de callback functions defined in the ino like the "buttonStatusChanged" via the setter for the event.

Finally you must configrate de I2C channel with the correct address and attach the callback function for the I2C request in the setup() section. The I2C callback function is now this, can be directy a call to decodeBuffer contained in the SimHubProtocolDecoder.h

void receiveSerialProtocolViaI2c(int howMany){ #if IC2_SERIAL_BYPASS_DEBUG Serial.print("Received data via I2C with"); Serial.print(howMany); Serial.print(" Bytes"); Serial.flush(); #endif decodeBuffer(&callbacker,&Wire); }

wapophis added 5 commits March 21, 2024 02:33
… impl on the slave, working with arduino AVR impl.
…ro will be overriden later. The default behaviour about stream, is read all the stream an send to StreamWrite(buffer,buffersize) method, seems that stream.write(buf,size) is stream compliant and must be implemented in all the stream transport layer that maybe used to comunicate with SIMHUB.
@wapophis wapophis marked this pull request as draft March 21, 2024 10:02
@wapophis
Copy link
Author

I2C_SIMHUB_EXTENSION_CHAINING

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.

2 participants