From c223b7aa5729b94a20069914854a7fea16856932 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Tue, 17 Jul 2018 18:25:15 +1000 Subject: [PATCH] i2c scanning is now optional: i2cScan = 1 prints the 7 bit addresses in decimal --- src/main.cpp | 37 +++++++++++++++++++------------------ src/options.cpp | 2 ++ src/options.h | 3 +++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a002ae4..00b1413 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1130,25 +1130,26 @@ void DisplayI2CScan(int y_pos) { int BSCMaster = options.I2CBusMaster(); - snprintf(tempBuffer, tempBufferSize, "Scanning i2c devices on bus %d ...\r\n", BSCMaster); - screen.PrintText(false, 0, y_pos += 16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); + snprintf(tempBuffer, tempBufferSize, "Scanning i2c bus %d ...\r\n", BSCMaster); + screen.PrintText(false, 0, y_pos , tempBuffer, COLOUR_WHITE, COLOUR_BLACK); + RPI_I2CInit(BSCMaster, 1); - int address = 0; - for (int y=0; y<8; y++) + + int count=0; + int ptr = 0; + ptr = snprintf (tempBuffer+ptr, tempBufferSize-ptr, "Found "); + for (int address = 0; address<128; address++) { - int x=0; - for (x=0; x<16; x++) + if (RPI_I2CScan(BSCMaster, address)) { - int ret = RPI_I2CScan(BSCMaster, address); - if (ret) - tempBuffer[x] = '*'; - else - tempBuffer[x] = '.'; - address++; + ptr += snprintf (tempBuffer+ptr, tempBufferSize-ptr, "%3d ", address); + count++; } - tempBuffer[x] = 0; - screen.PrintText(false, 0, y_pos += 16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); } + if (count == 0) + ptr += snprintf (tempBuffer+ptr, tempBufferSize-ptr, "Nothing"); + + screen.PrintText(false, 0, y_pos+16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); } static void CheckOptions() @@ -1277,11 +1278,11 @@ extern "C" snprintf(tempBuffer, tempBufferSize, "This is free software, and you are welcome to redistribute it."); screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); - if (options.ShowOptions()) - DisplayOptions(y_pos+32); + if (options.I2CScan()) + DisplayI2CScan(y_pos+=32); -// if (options.I2CScan()) - DisplayI2CScan(y_pos+32); + if (options.ShowOptions()) + DisplayOptions(y_pos+=32); if (!options.QuickBoot()) IEC_Bus::WaitMicroSeconds(3 * 1000000); diff --git a/src/options.cpp b/src/options.cpp index 4ebde18..fb4569c 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -142,6 +142,7 @@ Options::Options(void) , screenHeight(768) , i2cBusMaster(1) , i2cLcdAddress(0x3C) + , i2cScan(0) , i2cLcdFlip(0) , i2cLcdOnContrast(127) , i2cLcdModel(0) @@ -216,6 +217,7 @@ void Options::Process(char* buffer) ELSE_CHECK_DECIMAL_OPTION(screenHeight) ELSE_CHECK_DECIMAL_OPTION(i2cBusMaster) ELSE_CHECK_DECIMAL_OPTION(i2cLcdAddress) + ELSE_CHECK_DECIMAL_OPTION(i2cScan) ELSE_CHECK_DECIMAL_OPTION(i2cLcdFlip) ELSE_CHECK_DECIMAL_OPTION(i2cLcdOnContrast) ELSE_CHECK_DECIMAL_OPTION(i2cLcdDimContrast) diff --git a/src/options.h b/src/options.h index f53d758..b5eb17b 100644 --- a/src/options.h +++ b/src/options.h @@ -72,11 +72,13 @@ public: inline unsigned int I2CBusMaster() const { return i2cBusMaster; } inline unsigned int I2CLcdAddress() const { return i2cLcdAddress; } + inline unsigned int I2CScan() const { return i2cScan; } inline unsigned int I2CLcdFlip() const { return i2cLcdFlip; } inline unsigned int I2CLcdOnContrast() const { return i2cLcdOnContrast; } inline unsigned int I2CLcdDimContrast() const { return i2cLcdDimContrast; } inline unsigned int I2CLcdDimTime() const { return i2cLcdDimTime; } inline unsigned int I2CLcdModel() const { return i2cLcdModel; } + inline const char* GetLcdLogoName() const { return LcdLogoName; } inline float ScrollHighlightRate() const { return scrollHighlightRate; } @@ -114,6 +116,7 @@ private: unsigned int i2cBusMaster; unsigned int i2cLcdAddress; + unsigned int i2cScan; unsigned int i2cLcdFlip; unsigned int i2cLcdOnContrast; unsigned int i2cLcdDimContrast;