Skip to content

Feature/i2c routes#54

Draft
JoelHer wants to merge 10 commits intomainfrom
feature/i2c_routes
Draft

Feature/i2c routes#54
JoelHer wants to merge 10 commits intomainfrom
feature/i2c_routes

Conversation

@JoelHer
Copy link
Copy Markdown
Member

@JoelHer JoelHer commented Apr 16, 2026

This pull request adds a new /i2cinfo HTTP endpoint to expose detailed I2C bus and device information, and refactors the I2C device management to track and report both registered and detected I2C devices. It also introduces new data structures and APIs to support this functionality, and updates the frontend theme for improved UI consistency.

The new "Connected Devices" tab should be used for all kinds of peripherals in the future, not just I2C devices.

image

I2C Bus and Device Information Exposure:

  • Added a new VigilantI2cInfo struct and vigilant_get_i2cinfo API to collect and report I2C bus configuration, registered devices, and detected devices (vigilant.h, vigilant.c). [1] [2]
  • Implemented /i2cinfo HTTP GET endpoint that returns a JSON payload with I2C bus status, registered devices, and detected device addresses (http_server.c). [1] [2]

I2C Device Detection and Tracking:

  • Added device scanning, detection, and result caching in the I2C driver, with APIs to retrieve detected devices and keep the list up to date (i2c.c, i2c.h). [1] [2] [3] [4] [5] [6]
  • Refactored device registration logic to maintain a fixed-size registry of added devices and synchronize it with I2C operations (vigilant.c). [1] [2] [3] [4]

Frontend/UI Improvements:

  • Changed the default font family and improved layout sizing in the frontend theme for a more modern and consistent appearance (theme.css).

Other:

  • Removed an unnecessary call to remove the I2C device in the main application example (main.c).

This PR closes #8 #12 #48

@JoelHer JoelHer self-assigned this Apr 16, 2026
@JoelHer JoelHer added the enhancement New feature or request label Apr 16, 2026
@JoelHer JoelHer requested review from Kampfdackel5 and tillx4 April 16, 2026 10:22
@JoelHer
Copy link
Copy Markdown
Member Author

JoelHer commented Apr 16, 2026

@Kampfdackel5, @tillx4 Please Review

@JoelHer JoelHer marked this pull request as ready for review April 16, 2026 10:26
JoelHer added 2 commits April 16, 2026 12:36
Merge remote-tracking branch 'origin/main' into feature/i2c_routes
@JoelHer
Copy link
Copy Markdown
Member Author

JoelHer commented Apr 16, 2026

CIs are now passing.

Copy link
Copy Markdown
Contributor

@Kampfdackel5 Kampfdackel5 left a comment

Choose a reason for hiding this comment

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

Looks good so far, see my comments :)


httpd_resp_set_type(req, "application/json");
size_t payload_capacity = 256
+ ((size_t)info.added_device_count * 160)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe add some small comments in the code to not have magic numbers

(unsigned int)info.detected_device_count
);

if (written < 0 || written >= (int)(payload_capacity - offset)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we don't need the cast

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

payload_capacity is size_t so im not sure if it makes problems when we compare against an int

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So both ways aren't "safe" afaik haha

This is probably a discussion we should have in general anyway: how safe code has to be

(unsigned int)device->expected_whoami
);

if (written < 0 || written >= (int)(payload_capacity - offset)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if cast is removed above, also remove here

}

written = snprintf(payload + offset, payload_capacity - offset, "],\"detected_devices\":[");
if (written < 0 || written >= (int)(payload_capacity - offset)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again

(unsigned int)address
);

if (written < 0 || written >= (int)(payload_capacity - offset)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again

}

written = snprintf(payload + offset, payload_capacity - offset, "]}");
if (written < 0 || written >= (int)(payload_capacity - offset)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

again

Copy link
Copy Markdown
Member Author

@JoelHer JoelHer left a comment

Choose a reason for hiding this comment

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

added comments

@JoelHer JoelHer marked this pull request as draft April 21, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I2C Interface Integration

2 participants