-
Notifications
You must be signed in to change notification settings - Fork 2
Add onewire #38
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
Open
Frederikwag
wants to merge
5
commits into
main
Choose a base branch
from
add_onewire
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add onewire #38
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f7f164
src/corelibs/onewire: Added the test_onewire_sensor.cpp, updated Make…
Frederikwag dffb64b
src: Updated Makefile to newest version.
Frederikwag 6aed117
src: Updated test_main.ino.
Frederikwag a062649
src/corelibs/spi: Reduced println returns.
Frederikwag 83fecb1
src/corelibs/onewire: Reduced amount of println returns.
Frederikwag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* test_onewire_sensor.cpp | ||
* | ||
* This test verifies if the OneWire sensor (e.g. in this case: DS18B20) is responding and providing valid data. | ||
* It includes tests for device presence, chip description, and data retrieval. | ||
*/ | ||
|
||
// std includes | ||
#include <OneWire.h> | ||
#include "test_common_includes.h" | ||
|
||
// OneWire instance and variables | ||
static OneWire oneWire(5); // Pin 5 is used for the OneWire bus | ||
static uint8_t addr[8]; | ||
static uint8_t data[12]; | ||
|
||
// Test group definition | ||
TEST_GROUP(onewire_sensor); | ||
|
||
TEST_SETUP(onewire_sensor) { | ||
// Reset the OneWire bus | ||
oneWire.reset_search(); | ||
} | ||
|
||
TEST_TEAR_DOWN(onewire_sensor) { | ||
// Cleanup if necessary | ||
} | ||
|
||
// Test case: Verify if a device is present on the OneWire bus | ||
TEST(onewire_sensor, test_device_presence) { | ||
bool deviceFound = oneWire.search(addr); | ||
|
||
// Print result and pass/fail message | ||
if (deviceFound) { | ||
// Serial.println(" - Device Found"); | ||
} else { | ||
TEST_FAIL_MESSAGE(" - No device found on the OneWire bus."); | ||
} | ||
|
||
// Verify the CRC of the device address | ||
TEST_ASSERT_TRUE_MESSAGE(OneWire::crc8(addr, 7) == addr[7], " - Invalid CRC for device address"); | ||
} | ||
|
||
// Test case: Verify if a chip description is returned | ||
TEST(onewire_sensor, test_device_description) { | ||
bool deviceFound = oneWire.search(addr); | ||
TEST_ASSERT_TRUE_MESSAGE(deviceFound, " - No device found on the OneWire bus"); | ||
|
||
// Check if the first byte of the address corresponds to a known chip family | ||
if (addr[0] == 0x10 || addr[0] == 0x28 || addr[0] == 0x22) { | ||
// Serial.println(" - Chip description found."); | ||
} else { | ||
TEST_FAIL_MESSAGE(" - No valid chip description found."); | ||
} | ||
} | ||
|
||
// Test case: Verify if data was returned (basic functionality) | ||
TEST(onewire_sensor, test_data_returned) { | ||
bool deviceFound = oneWire.search(addr); | ||
TEST_ASSERT_TRUE_MESSAGE(deviceFound, " - No device found on the OneWire bus"); | ||
|
||
// Start temperature conversion | ||
oneWire.reset(); | ||
oneWire.select(addr); | ||
oneWire.write(0x44, 1); // Start conversion with parasite power on | ||
|
||
// Wait for conversion to complete | ||
delay(1000); | ||
|
||
// Read the scratchpad | ||
oneWire.reset(); | ||
oneWire.select(addr); | ||
oneWire.write(0xBE); // Read Scratchpad | ||
|
||
for (uint8_t i = 0; i < 9; i++) { | ||
data[i] = oneWire.read(); | ||
} | ||
|
||
// Verify that data was returned (non-zero values in the scratchpad) | ||
bool dataReturned = false; | ||
for (uint8_t i = 0; i < 9; i++) { | ||
if (data[i] != 0) { | ||
dataReturned = true; | ||
break; | ||
} | ||
} | ||
|
||
// Print result and pass/fail message | ||
if (dataReturned) { | ||
// Serial.println(" - Data received"); | ||
} else { | ||
TEST_FAIL_MESSAGE(" - No valid data returned from the sensor."); | ||
} | ||
} | ||
|
||
// Define test runner for the OneWire sensor test group | ||
TEST_GROUP_RUNNER(onewire_sensor) { | ||
RUN_TEST_CASE(onewire_sensor, test_device_presence); | ||
RUN_TEST_CASE(onewire_sensor, test_device_description); | ||
RUN_TEST_CASE(onewire_sensor, test_data_returned); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider defining a named constant for the OneWire bus pin instead of using the hard-coded value (5) to enhance code readability and ease future modifications.
Copilot uses AI. Check for mistakes.