Skip to content

Commit 4652dc9

Browse files
authored
Merge pull request #9 from sparkfun/release_candidate
v3.0.3
2 parents 034ccf3 + eda6523 commit 4652dc9

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ getIMEI KEYWORD2
4545
isConnected KEYWORD2
4646
passThruI2Cread KEYWORD2
4747
passThruI2Cwrite KEYWORD2
48+
configureSleepPin KEYWORD2
49+
setSleepPin KEYWORD2
4850

4951
#######################################
5052
# Constants (LITERAL1)

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=IridiumSBDi2c
2-
version=3.0.2
2+
version=3.0.3
33
author=Mikal Hart and Paul Clark (PaulZC)
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=This library supports satellite data transmissions from anywhere on earth using the RockBLOCK family of Iridium 9602 and 9603 modems.

src/IridiumSBD.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ int IridiumSBD::internalSendReceiveSBD(const char *txTxtMessage, const uint8_t *
741741
diagprint(moCode);
742742
diagprint(F("\r\n"));
743743

744-
if (moCode >= 0 && moCode <= 4) // this range indicates successful return!
744+
if (moCode <= 4) // this range indicates successful return!
745745
{
746746
diagprint(F("SBDIX success!\r\n"));
747747

@@ -1101,7 +1101,11 @@ void IridiumSBD::power(bool on)
11011101
}
11021102
else
11031103
{
1104-
pinMode(this->sleepPin, OUTPUT); // Make the sleep pin an output
1104+
if (this->sleepPinConfigured == false)
1105+
{
1106+
configureSleepPin();
1107+
this->sleepPinConfigured = true;
1108+
}
11051109
}
11061110
}
11071111

@@ -1110,15 +1114,14 @@ void IridiumSBD::power(bool on)
11101114
diagprint(F("Powering on modem...\r\n"));
11111115
if (this->useSerial)
11121116
{
1113-
digitalWrite(this->sleepPin, HIGH); // HIGH = awake
1117+
setSleepPin(HIGH); // HIGH = awake
11141118
}
11151119
else
11161120
{
11171121
enable9603(true);
11181122
}
11191123
lastPowerOnTime = millis();
11201124
}
1121-
11221125
else
11231126
{
11241127
// Best Practices Guide suggests waiting at least 2 seconds
@@ -1130,7 +1133,7 @@ void IridiumSBD::power(bool on)
11301133
diagprint(F("Powering off modem...\r\n"));
11311134
if (this->useSerial)
11321135
{
1133-
digitalWrite(this->sleepPin, LOW); // LOW = asleep
1136+
setSleepPin(LOW); // LOW = asleep
11341137
}
11351138
else
11361139
{
@@ -1139,6 +1142,22 @@ void IridiumSBD::power(bool on)
11391142
}
11401143
}
11411144

1145+
void IridiumSBD::configureSleepPin()
1146+
{
1147+
pinMode(this->sleepPin, OUTPUT); // Make the sleep pin an output
1148+
diagprint(F("configureSleepPin: sleepPin configured\r\n"));
1149+
}
1150+
1151+
void IridiumSBD::setSleepPin(uint8_t enable)
1152+
{
1153+
digitalWrite(this->sleepPin, enable); // HIGH = awake, LOW = asleep
1154+
diagprint(F("setSleepPin: sleepPin set "));
1155+
if (enable == HIGH)
1156+
diagprint(F("HIGH\r\n"));
1157+
else
1158+
diagprint(F("LOW\r\n"));
1159+
}
1160+
11421161
void IridiumSBD::send(FlashString str, bool beginLine, bool endLine)
11431162
{
11441163
if (beginLine)
@@ -1393,17 +1412,12 @@ void IridiumSBD::check9603data()
13931412
wireport->beginTransmission((uint8_t)deviceaddress); // Talk to the I2C device
13941413
wireport->write(LEN_REG); // Point to the serial buffer length
13951414
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1396-
wireport->requestFrom((uint8_t)deviceaddress, 2); // Request two bytes
1397-
if (wireport->available() >= 2)
1415+
if (wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)2) == 2) // Request two bytes
13981416
{
13991417
uint8_t msb = wireport->read();
14001418
uint8_t lsb = wireport->read();
14011419
bytesAvailable = (((uint16_t)msb) << 8) | lsb;
14021420
}
1403-
while (wireport->available())
1404-
{
1405-
wireport->read(); // Mop up any unexpected bytes
1406-
}
14071421

14081422
//Now read the serial bytes (if any)
14091423
if (bytesAvailable > 0)
@@ -1416,14 +1430,14 @@ void IridiumSBD::check9603data()
14161430
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
14171431
while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
14181432
{
1419-
wireport->requestFrom((uint8_t)deviceaddress, SER_PACKET_SIZE, false); // Request SER_PACKET_SIZE bytes, don't release the bus
1433+
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)SER_PACKET_SIZE, (uint8_t)false); // Request SER_PACKET_SIZE bytes, don't release the bus
14201434
while (wireport->available())
14211435
{
14221436
i2cSerPoke(wireport->read()); // Read and store each byte
14231437
}
14241438
bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
14251439
}
1426-
wireport->requestFrom((uint8_t)deviceaddress, bytesAvailable); // Request remaining bytes, release the bus
1440+
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)bytesAvailable); // Request remaining bytes, release the bus
14271441
while (wireport->available())
14281442
{
14291443
i2cSerPoke(wireport->read()); // Read and store each byte
@@ -1441,15 +1455,10 @@ void IridiumSBD::check9603pins()
14411455
wireport->beginTransmission((uint8_t)deviceaddress); // Talk to the I2C device
14421456
wireport->write(IO_REG); // Point to the 'IO register'
14431457
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1444-
wireport->requestFrom((uint8_t)deviceaddress, 1); // Request one byte from the IO register
1445-
if (wireport->available())
1458+
if (wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)1) == 1) // Request one byte from the IO register
14461459
{
14471460
IO_REGISTER = wireport->read(); // Read the IO register
14481461
}
1449-
while (wireport->available())
1450-
{
1451-
wireport->read(); // Mop up any unexpected bytes (hopefully redundant!?)
1452-
}
14531462
}
14541463

14551464
//Set the IO pins
@@ -1476,17 +1485,12 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
14761485
wireport->beginTransmission((uint8_t)deviceaddress); // Talk to the I2C device
14771486
wireport->write(LEN_REG); // Point to the serial buffer length
14781487
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
1479-
wireport->requestFrom((uint8_t)deviceaddress, 2); // Request two bytes
1480-
if (wireport->available() >= 2)
1488+
if (wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)2) == 2) // Request two bytes
14811489
{
14821490
uint8_t msb = wireport->read();
14831491
uint8_t lsb = wireport->read();
14841492
bytesAvailable = (((uint16_t)msb) << 8) | lsb;
14851493
}
1486-
while (wireport->available())
1487-
{
1488-
wireport->read(); // Mop up any unexpected bytes
1489-
}
14901494

14911495
numBytes = (size_t)bytesAvailable; //Store bytesAvailable in numBytes
14921496

@@ -1503,7 +1507,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
15031507
wireport->endTransmission(); // Send data and release the bus (the 841 (WireS) doesn't like it if the Master holds the bus!)
15041508
while (bytesAvailable > SER_PACKET_SIZE) // If there are _more_ than SER_PACKET_SIZE bytes to be read
15051509
{
1506-
wireport->requestFrom((uint8_t)deviceaddress, SER_PACKET_SIZE, false); // Request SER_PACKET_SIZE bytes, don't release the bus
1510+
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)SER_PACKET_SIZE, (uint8_t)false); // Request SER_PACKET_SIZE bytes, don't release the bus
15071511
while (wireport->available())
15081512
{
15091513
uint8_t dbyte = wireport->read(); // Read a byte
@@ -1515,7 +1519,7 @@ int IridiumSBD::internalPassThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize,
15151519
}
15161520
bytesAvailable -= SER_PACKET_SIZE; // Decrease the number of bytes available by SER_PACKET_SIZE
15171521
}
1518-
wireport->requestFrom((uint8_t)deviceaddress, bytesAvailable); // Request remaining bytes, release the bus
1522+
wireport->requestFrom((uint8_t)deviceaddress, (uint8_t)bytesAvailable); // Request remaining bytes, release the bus
15191523
while (wireport->available())
15201524
{
15211525
uint8_t dbyte = wireport->read(); // Read a byte

src/IridiumSBD.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ class IridiumSBD
134134
int passThruI2Cread(uint8_t *rxBuffer, size_t &rxBufferSize, size_t &numBytes);
135135
int passThruI2Cwrite(uint8_t *txBuffer, size_t &txBufferSize);
136136

137+
// Weak functions to configure and set the sleep pin - user can overwrite with a custom functions if required
138+
void configureSleepPin() __attribute__((weak));
139+
void setSleepPin(uint8_t enable) __attribute__((weak));
140+
137141
IridiumSBD(Stream &str, int sleepPinNo = -1, int ringPinNo = -1)
138142
{
139143
useSerial = true;
@@ -146,6 +150,7 @@ class IridiumSBD
146150
asleep = true;
147151
reentrant = false;
148152
sleepPin = sleepPinNo;
153+
sleepPinConfigured = false;
149154
ringPin = ringPinNo;
150155
msstmWorkaroundRequested = true;
151156
ringAlertsEnabled = {ringPinNo != -1};
@@ -175,6 +180,7 @@ class IridiumSBD
175180
asleep = true;
176181
reentrant = false;
177182
sleepPin = -1;
183+
sleepPinConfigured = false;
178184
ringPin = -1;
179185
msstmWorkaroundRequested = false;
180186
ringAlertsEnabled = true;
@@ -218,6 +224,7 @@ class IridiumSBD
218224
bool asleep;
219225
bool reentrant;
220226
int sleepPin;
227+
bool sleepPinConfigured;
221228
int ringPin;
222229
bool msstmWorkaroundRequested;
223230
bool ringAlertsEnabled;

0 commit comments

Comments
 (0)