Skip to content

Commit 4d784e5

Browse files
updated I2C tests to use LM75B instead of TMP102 sensor
1 parent 908003b commit 4d784e5

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

LM75B.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://developer.mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac

TESTS/API/I2C/I2C.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "unity.h"
44
#include "utest.h"
55
#include "rtos.h"
6-
#include "TMP102.h"
6+
#include "LM75B.h"
77
#include <I2CEeprom.h>
88

99
using namespace utest::v1;
@@ -12,29 +12,33 @@ using namespace utest::v1;
1212

1313
const char *convBool(bool value) { return value ? "true" : "false"; }
1414

15-
#define I2C_SENTINAL 'Z'
15+
#define I2C_SENTINAL 'Z' //TODO: make this a random letter or string
1616
#define TMP102_ADDR 0x90
1717
#define EEPROM_ADDR 0xA0
1818

1919
// a test to see if the temperature can be read. A I2C failure returns a 0
2020
void test_tmp102(){
21-
TMP102 temperature(I2C_SDA, I2C_SCL, TMP102_ADDR); //A0 pin is connected to ground
22-
TEST_ASSERT(0 != temperature.read());
21+
//TMP102 temperature(I2C_SDA, I2C_SCL, TMP102_ADDR); //A0 pin is connected to ground
22+
LM75B temperature(I2C_SDA, I2C_SCL);
23+
TEST_ASSERT_MESSAGE(0 != temperature.open(),"Failed to open sensor");
24+
TEST_ASSERT_MESSAGE(NULL != temperature.temp(),"Invalid value NULL returned");
25+
TEST_ASSERT_MESSAGE(50 > temperature.temp(),"Its too Hot (>10C), Faulty Sensor?");
26+
TEST_ASSERT_MESSAGE(0 < temperature.temp(),"Its Too Cold (<0C), Faulty Sensor?");
2327
}
2428

2529
// A test to write the EEprom
2630
void test_eeprom_W(){
2731
I2CEeprom memory(I2C_SDA,I2C_SCL, EEPROM_ADDR, 32, 0);
28-
TEST_ASSERT(memory.write(1, I2C_SENTINAL) == 1); // check data was written
32+
TEST_ASSERT_MESSAGE(memory.write(1, I2C_SENTINAL) == 1,"data not written, error with EEPROM?"); // check data was written
2933
}
3034

3135

3236
// A test to read the EEprom
3337
void test_eeprom_R(){
3438
I2CEeprom memory(I2C_SDA,I2C_SCL, EEPROM_ADDR, 32, 0);
3539
char value = 'a';
36-
TEST_ASSERT(memory.read(1,value) == 1); // check data was read
37-
TEST_ASSERT(I2C_SENTINAL == value); // check data integrity
40+
TEST_ASSERT_MESSAGE(memory.read(1,value) == 1,"data failed to be read correctly"); // check data was read
41+
TEST_ASSERT_MESSAGE(I2C_SENTINAL == value,"data read does not match data written! bad EEPROM?"); // check data integrity
3842
}
3943

4044
// A test to Write then read the eeprom

TMP102.lib

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)