Skip to content

Commit

Permalink
Added "enable/disable logging" functionality to C++ and Java Libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
kauailabs committed Feb 28, 2017
1 parent 4ce6157 commit d34b079
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 4 deletions.
2 changes: 2 additions & 0 deletions roborio/c++/navx_frc_cpp/include/AHRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class AHRS : public SensorBase,
int GetActualUpdateRate();
int GetRequestedUpdateRate();

void EnableLogging(bool enable);

private:
void SPIInit( SPI::Port spi_port_id, uint32_t bitrate, uint8_t update_rate_hz );
void I2CInit( I2C::Port i2c_port_id, uint8_t update_rate_hz );
Expand Down
12 changes: 12 additions & 0 deletions roborio/c++/navx_frc_cpp/src/AHRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,18 @@ float AHRS::GetDisplacementZ() {
return (ahrs_internal->IsDisplacementSupported() ? displacement[2] : 0.f);
}

/**
* Enables or disables logging (via Console I/O) of AHRS library internal
* behaviors, including events such as transient communication errors.
* @param enable
*/
void AHRS::EnableLogging(bool enable) {
if ( this->io != NULL) {
io->EnableLogging(enable);
}
}


#define NAVX_IO_THREAD_NAME "navXIOThread"

void AHRS::SPIInit( SPI::Port spi_port_id, uint32_t bitrate, uint8_t update_rate_hz ) {
Expand Down
1 change: 1 addition & 0 deletions roborio/c++/navx_frc_cpp/src/IIOProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class IIOProvider {
virtual void ZeroDisplacement() = 0;
virtual void Run() = 0;
virtual void Stop() = 0;
virtual void EnableLogging(bool enable) = 0;
};

#endif /* SRC_IIOPROVIDER_H_ */
1 change: 1 addition & 0 deletions roborio/c++/navx_frc_cpp/src/IRegisterIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class IRegisterIO {
virtual bool Write(uint8_t address, uint8_t value ) = 0;
virtual bool Read(uint8_t first_address, uint8_t* buffer, uint8_t buffer_len) = 0;
virtual bool Shutdown() = 0;
virtual void EnableLogging(bool enable) = 0;
};

#endif /* SRC_IREGISTERIO_H_ */
4 changes: 4 additions & 0 deletions roborio/c++/navx_frc_cpp/src/RegisterIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ void RegisterIO::Stop() {
stop = true;
}

void RegisterIO::EnableLogging(bool enable) {
io_provider->EnableLogging(enable);
}

bool RegisterIO::GetConfiguration() {
bool success = false;
int retry_count = 0;
Expand Down
1 change: 1 addition & 0 deletions roborio/c++/navx_frc_cpp/src/RegisterIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RegisterIO : public IIOProvider {
void ZeroDisplacement();
void Run();
void Stop();
void EnableLogging(bool enable);
virtual ~RegisterIO();
private:
bool GetConfiguration();
Expand Down
5 changes: 4 additions & 1 deletion roborio/c++/navx_frc_cpp/src/RegisterIOI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
static priority_mutex imu_mutex;
RegisterIO_I2C::RegisterIO_I2C(I2C* port) {
this->port = port;
this->trace = true;
this->trace = false;
}

bool RegisterIO_I2C::Init() {
Expand Down Expand Up @@ -51,4 +51,7 @@ bool RegisterIO_I2C::Shutdown() {
return true;
}

void RegisterIO_I2C::EnableLogging(bool enable) {
trace = enable;
}

1 change: 1 addition & 0 deletions roborio/c++/navx_frc_cpp/src/RegisterIOI2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RegisterIO_I2C : public IRegisterIO {
bool Write(uint8_t address, uint8_t value );
bool Read(uint8_t first_address, uint8_t* buffer, uint8_t buffer_len);
bool Shutdown();
void EnableLogging(bool enable);
private:
I2C *port;
bool trace;
Expand Down
6 changes: 5 additions & 1 deletion roborio/c++/navx_frc_cpp/src/RegisterIOSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static priority_mutex imu_mutex;
RegisterIO_SPI::RegisterIO_SPI(SPI *port, uint32_t bitrate) {
this->port = port;
this->bitrate = bitrate;
this->trace = true;
this->trace = false;
}

bool RegisterIO_SPI::Init() {
Expand Down Expand Up @@ -65,3 +65,7 @@ bool RegisterIO_SPI::Read(uint8_t first_address, uint8_t* buffer, uint8_t buffer
bool RegisterIO_SPI::Shutdown() {
return true;
}

void RegisterIO_SPI::EnableLogging(bool enable) {
trace = enable;
}
1 change: 1 addition & 0 deletions roborio/c++/navx_frc_cpp/src/RegisterIOSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RegisterIO_SPI: public IRegisterIO {
bool Write(uint8_t address, uint8_t value );
bool Read(uint8_t first_address, uint8_t* buffer, uint8_t buffer_len);
bool Shutdown();
void EnableLogging(bool enable);
private:
SPI *port;
uint32_t bitrate;
Expand Down
2 changes: 2 additions & 0 deletions roborio/c++/navx_frc_cpp/src/SerialIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,5 @@ void SerialIO::Stop() {
stop = true;
}

void SerialIO::EnableLogging(bool enable) {
}
1 change: 1 addition & 0 deletions roborio/c++/navx_frc_cpp/src/SerialIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SerialIO : public IIOProvider {
void ZeroDisplacement();
void Run();
void Stop();
void EnableLogging(bool enable);
private:

SerialPort *ResetSerialPort();
Expand Down
11 changes: 11 additions & 0 deletions roborio/java/navx_frc/src/com/kauailabs/navx/frc/AHRS.java
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,17 @@ public String getFirmwareVersion() {
return fw_version;
}

/**
* Enables or disables logging (via Console I/O) of AHRS library internal
* behaviors, including events such as transient communication errors.
* @param enable
*/
public void enableLogging(boolean enable) {
if ( this.io != null) {
io.enableLogging(enable);
}
}

/***********************************************************/
/* Runnable Interface Implementation */
/***********************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ interface IIOProvider {
public void zeroDisplacement();
public void run();
public void stop();
public void enableLogging(boolean enable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface IRegisterIO {
boolean write(byte address, byte value );
boolean read(byte first_address, byte[] buffer);
boolean shutdown();
void enableLogging(boolean enable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,8 @@ public void zeroDisplacement() {
AHRSProtocol.NAVX_INTEGRATION_CTL_RESET_DISP_Z ) );
}

@Override
public void enableLogging(boolean enable) {
io_provider.enableLogging(enable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class RegisterIO_I2C implements IRegisterIO{

I2C port;
boolean trace = true;
boolean trace = false;

public RegisterIO_I2C( I2C i2c_port ) {
port = i2c_port;
Expand All @@ -25,6 +25,11 @@ public boolean init() {
return true;
}

@Override
public void enableLogging(boolean enable) {
trace = enable;
}

@Override
public boolean write(byte address, byte value ) {
boolean success;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RegisterIO_SPI implements IRegisterIO{

SPI port;
int bitrate;
boolean trace = true;
boolean trace = false;

static final int DEFAULT_SPI_BITRATE_HZ = 500000;

Expand All @@ -27,6 +27,10 @@ public RegisterIO_SPI( SPI spi_port ) {
bitrate = DEFAULT_SPI_BITRATE_HZ;
}

public void enableLogging(boolean enable) {
trace = enable;
}

public RegisterIO_SPI( SPI spi_port, int bitrate ) {
port = spi_port;
this.bitrate = bitrate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,5 +596,8 @@ public void stop() {
stop = true;
}

@Override
public void enableLogging(boolean enable) {
}

}

0 comments on commit d34b079

Please sign in to comment.