From a660ebc092a62cb9b388e7578c2c5235e0d75125 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Sun, 27 Sep 2020 23:33:35 -0400 Subject: [PATCH] Enumerate pinouts directory and show list of files available to display --- hardware/_controller/README.md | 5 ++ hardware/_controller/_controller.ino | 44 ++++++++++-------- ...eather-m0-basic.bmp => feather-m0-bsc.bmp} | Bin 3 files changed, 30 insertions(+), 19 deletions(-) rename hardware/_controller/pinouts/{feather-m0-basic.bmp => feather-m0-bsc.bmp} (100%) diff --git a/hardware/_controller/README.md b/hardware/_controller/README.md index 5a93ffd..455a16a 100644 --- a/hardware/_controller/README.md +++ b/hardware/_controller/README.md @@ -40,6 +40,11 @@ These libraries are used by the project and can be installed via the Arduino IDE - Button for accessing password selection pop-up to help with password entry over serial - This should be configured via a text file on the sd card - Way to display pinouts stored on micro sd card + - Max number of files is 20 + - Max filename length is 24 (this includes the ```.``` and extension of the file) + - The pinouts should be stored as bmp files *up to* 24 bit + - Pinouts should be sized as close to 320x240 as possible + - Pinouts should be stored at ```/pinouts``` on the root of the SD card - Configuration read from muxes (if attached) ## Implementation (Complete) diff --git a/hardware/_controller/_controller.ino b/hardware/_controller/_controller.ino index 0190a9d..770756b 100644 --- a/hardware/_controller/_controller.ino +++ b/hardware/_controller/_controller.ino @@ -30,8 +30,14 @@ // The adagfx driver was updated to be able to retun a reference to the sd card // This will NOT work w/o the driver tweak // The implementation of gslc_GetSDCard only lives in the ada cpp driver so we need to extern it here +#define MAX_FILE_NAME_CHARS 21 // Add 1 to the max limit for null termination of filenames (SdFat API need) +#define MAX_PINOUTS 24 +#define DIRECTORY_PINOUTS "/pinouts" #include "src/SdFat/SdFat.h" extern SdFat SD; +SdFile dirFile; +SdFile file; +char fileName[MAX_FILE_NAME_CHARS]; // Account for null termination // @@ -275,25 +281,25 @@ void setup() { gslc_InputMapAdd(&m_gui, GSLC_INPUT_PIN_ASSERT, KBD_SW_OK, GSLC_ACTION_SELECT, 0); // Setup list of diagrams - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Raspberry Pi"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Friendly Arm M4"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Orange Pi v1"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Banana Pi"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "O-Droid HC2"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Arduino (AVR)"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Ardunio (ARM)"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Cisco Console"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "APC Console"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Raritan Console"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Adafruit Feather"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "Adafruit Metro"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "[Unused 01]"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "[Unused 02]"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "[Unused 03]"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "[Unused 04]"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "[Unused 05]"); - gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, "[Unused 06]"); - gslc_ElemXListboxSetSel(&m_gui, m_pElemLsDiagrams, listDiagramSelection); + + // List files in pinouts directory and add to main list of available pinout files + if (!dirFile.open(DIRECTORY_PINOUTS, O_RDONLY)) { + SD.errorHalt("open root failed"); + } + int n = 0; + while (n < MAX_PINOUTS && file.openNext(&dirFile, O_RDONLY)) { + n++; + // Skip directories and hidden files. + if (!file.isSubDir() && !file.isHidden()) { + // Save dirIndex of file in directory. + file.getName(fileName, MAX_FILE_NAME_CHARS * sizeof(char)); + #if defined(DBG_LOG) || defined(DBG_TOUCH) || defined(DBG_FRAME_RATE) || defined(DBG_DRAW_IMM) || defined(DBG_DRIVER) + Serial.println(fileName); + #endif + gslc_ElemXListboxAddItem(&m_gui, m_pElemLsDiagrams, fileName); + } + file.close(); + } // Set diagrams slider max equal to the number of elements listDiagramsSize = gslc_ElemXListboxGetItemCnt(&m_gui, m_pElemLsDiagrams); diff --git a/hardware/_controller/pinouts/feather-m0-basic.bmp b/hardware/_controller/pinouts/feather-m0-bsc.bmp similarity index 100% rename from hardware/_controller/pinouts/feather-m0-basic.bmp rename to hardware/_controller/pinouts/feather-m0-bsc.bmp