Compare commits

..

No commits in common. "2038522e0fb2c5d73a9f8a599647ec1ed6b273c4" and "9f9141c5f0d1fce78959729e1b0a6b909e44e670" have entirely different histories.

View file

@ -35,21 +35,14 @@ HM330x::HM330x() {};
// Initialize the Sensor // Initialize the Sensor
void HM330x::initialize(void) { void HM330x::initialize(void) {
uint8_t retryCount = 0; uint8_t retryCount = 0;
DEBUG_PRINTLN("HM330x::initialize"); DEBUG_PRINTLN("HM330x::initialize");
// Wait for Sensor to get Ready
DEBUG_PRINTLN("HM330x::initialize Waiting for Sensor Startup");
delay(30000);
DEBUG_PRINTLN("HM330x::initialize Trying to send Select");
// Send select command // Send select command
while (!sendCmd(HM330x_SELECT)) { while (!sendCmd(HM330x_SELECT)) {
if (retryCount++ >= 10) { if (retryCount++ >= 0) {
DEBUG_PRINTLN("HM330x::initialize Select Failed!");
return; return;
} else { } else {
delay(500); delay(100);
DEBUG_PRINTLN("HM330x::initialize Retrying Select...");
} }
} }
} }
@ -63,18 +56,13 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
// Initialize Payload with 0s // Initialize Payload with 0s
for (uint8_t i=startbyte; i < startbyte+6; i++) for (uint8_t i=startbyte; i < startbyte+6; i++)
payload[i] = 0xFF; payload[i] = 0;
// Get Data from the Sensors // Get Data from the Sensors
Wire.requestFrom(HM330x_ADDR, HM330x_DATA_LEN); Wire.requestFrom(HM330x_ADDR, HM330x_DATA_LEN);
if (Wire.available()) { if (Wire.available()) {
DEBUG_PRINT("HM330x::getSensorData reading I2C:") for (uint8_t i = 0; i<HM330x_DATA_LEN; i++)
for (uint8_t i = 0; i<HM330x_DATA_LEN; i++){
data[i] = Wire.read(); data[i] = Wire.read();
DEBUG_PRINT(" 0x");
DEBUG_PRINT(data[i], HEX);
}
DEBUG_PRINTLN("");
if (calcSum(data) == data[HM330x_DATA_LEN-1]) { if (calcSum(data) == data[HM330x_DATA_LEN-1]) {
for (uint8_t pos = 5; pos<8; pos++) { for (uint8_t pos = 5; pos<8; pos++) {
@ -83,9 +71,6 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
startbyte += 2; startbyte += 2;
} }
return startbyte; return startbyte;
} else {
for (uint8_t i=startbyte; i < startbyte+6; i++)
payload[i] = 0xEE;
} }
} }
return startbyte+6; return startbyte+6;
@ -93,8 +78,6 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
// Send only a Command // Send only a Command
bool HM330x::sendCmd(uint8_t cmd) { bool HM330x::sendCmd(uint8_t cmd) {
DEBUG_PRINT("HM330x::sendCmd: 0x")
DEBUG_PRINTLN(cmd, HEX);
Wire.beginTransmission(HM330x_ADDR); Wire.beginTransmission(HM330x_ADDR);
Wire.write(cmd); Wire.write(cmd);
return Wire.endTransmission(); return Wire.endTransmission();
@ -106,8 +89,6 @@ uint8_t HM330x::calcSum(uint8_t bytes[]) {
for (int i = 0; i < HM330x_DATA_LEN - 1; i++) { for (int i = 0; i < HM330x_DATA_LEN - 1; i++) {
checksum += bytes[i]; checksum += bytes[i];
} }
DEBUG_PRINT("HM330x::calcSum: 0x");
DEBUG_PRINTLN(checksum, HEX);
return checksum; return checksum;
} }