-
Notifications
You must be signed in to change notification settings - Fork 3
src/corelibs/spi: Added the 3wire test with the TLE5012. #55
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
1
commit into
main
Choose a base branch
from
test_spi_3wire
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
Changes from all commits
Commits
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,68 @@ | ||
/* test_spi_3wire.cpp | ||
* | ||
* This test is used to verify if the TLE5012 sensor is responding using 3-wire SPI communication. | ||
*/ | ||
|
||
// std includes | ||
#include <tlx5012-arduino.hpp> | ||
#include "test_common_includes.h" | ||
|
||
// Use the tle5012 namespace | ||
using namespace tle5012; | ||
|
||
// TLE5012 sensor instance and variables | ||
static Tle5012Ino Tle5012Sensor = Tle5012Ino(); | ||
static errorTypes checkError; | ||
|
||
// Test group definition | ||
TEST_GROUP(spi_3wire); | ||
|
||
TEST_SETUP(spi_3wire) { | ||
// Initialize the TLE5012 sensor | ||
|
||
checkError = Tle5012Sensor.begin(); | ||
} | ||
|
||
TEST_TEAR_DOWN(spi_3wire) { | ||
// Cleanup if necessary | ||
} | ||
|
||
// Test case: Verify if the sensor is responding | ||
TEST(spi_3wire, test_sensor_response) { | ||
TEST_ASSERT_EQUAL(tle5012::NO_ERROR, checkError); // Check if initialization was successful | ||
} | ||
|
||
|
||
// Test case: Request data from the sensor using 3-wire SPI | ||
TEST(spi_3wire, test_3wire_request) { | ||
double command = 0.0; // Example command to request data from the sensor | ||
int response = 0; | ||
|
||
// Use the sendReceiveSPI function to perform 3-wire SPI communication | ||
response = Tle5012Sensor.getAngleValue(command); | ||
|
||
// Verify the response (this is an example; adjust based on expected behavior) | ||
TEST_ASSERT_NOT_EQUAL(1, response); // Ensure the response is not an error | ||
TEST_ASSERT_TRUE(response >= -180.0 && response <= 180.0); // Ensure the angle is within a valid range | ||
} | ||
|
||
// Test case: Request temperature data from the sensor | ||
TEST(spi_3wire, test_temperature_request) { | ||
double temperature = 0.0; | ||
int result = 0; | ||
|
||
// Use the getTemperature function to request temperature data from the sensor | ||
result = Tle5012Sensor.getTemperature(temperature); | ||
|
||
Serial.print(temperature); | ||
// Verify the response | ||
TEST_ASSERT_EQUAL(tle5012::NO_ERROR, result); // Ensure the request was successful | ||
TEST_ASSERT_TRUE(temperature >= -40.0 && temperature <= 150.0); // Ensure the temperature is within a valid range | ||
} | ||
|
||
// Define test runner for the SPI 3-wire test group | ||
TEST_GROUP_RUNNER(spi_3wire) { | ||
RUN_TEST_CASE(spi_3wire, test_sensor_response); | ||
RUN_TEST_CASE(spi_3wire, test_3wire_request); | ||
RUN_TEST_CASE(spi_3wire, test_temperature_request); | ||
} |
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.
We have to check if we can test the 3Wire SPI without depending on the library...
Otherwise this test is out of scope of arduino-core-test.