diff --git a/KiwiBoard.emf b/KiwiBoard.emf index 0156785..77be703 100644 --- a/KiwiBoard.emf +++ b/KiwiBoard.emf @@ -1,7 +1,7 @@ { "version": "1.00", "projectName": "KiwiBoard", - "author": "mtaylor", + "author": "2p3ca", "items": [ { "parentId": 0, @@ -139,7 +139,7 @@ { "parentId": 8, "type": "analogItem", - "defaultValue": "1", + "defaultValue": "6", "item": { "maxValue": 10, "offset": 1, @@ -238,9 +238,9 @@ { "parentId": 12, "type": "analogItem", - "defaultValue": "50", + "defaultValue": "350", "item": { - "maxValue": 950, + "maxValue": 650, "offset": 50, "divisor": 1, "unitName": "rpm", @@ -398,9 +398,9 @@ "type": "subMenu", "item": { "secured": false, - "name": "Advanced", - "variableName": "Advanced", - "id": 30, + "name": "Motor Settings", + "variableName": "MotorSettings", + "id": 52, "eepromAddress": -1, "readOnly": false, "localOnly": false, @@ -409,15 +409,16 @@ } }, { - "parentId": 30, + "parentId": 52, "type": "boolItem", "defaultValue": "false", "item": { - "naming": "YES_NO", - "name": "Invert Encoder", - "variableName": "InvertEncoder", - "id": 34, - "eepromAddress": 79, + "naming": "ON_OFF", + "name": "Motor Test", + "variableName": "motorTest", + "id": 44, + "eepromAddress": -1, + "functionName": "@motortest", "readOnly": false, "localOnly": false, "visible": true, @@ -425,7 +426,7 @@ } }, { - "parentId": 30, + "parentId": 52, "type": "analogItem", "defaultValue": "148", "item": { @@ -446,7 +447,7 @@ } }, { - "parentId": 30, + "parentId": 52, "type": "analogItem", "defaultValue": "17", "item": { @@ -467,7 +468,7 @@ } }, { - "parentId": 30, + "parentId": 52, "type": "boolItem", "defaultValue": "true", "item": { @@ -483,6 +484,57 @@ "staticDataInRAM": false } }, + { + "parentId": 7, + "type": "subMenu", + "item": { + "secured": false, + "name": "Hardware", + "variableName": "Advanced", + "id": 30, + "eepromAddress": -1, + "readOnly": false, + "localOnly": false, + "visible": true, + "staticDataInRAM": false + } + }, + { + "parentId": 30, + "type": "boolItem", + "defaultValue": "false", + "item": { + "naming": "YES_NO", + "name": "Invert Encoder", + "variableName": "InvertEncoder", + "id": 34, + "eepromAddress": 79, + "readOnly": false, + "localOnly": false, + "visible": true, + "staticDataInRAM": false + } + }, + { + "parentId": 30, + "type": "enumItem", + "defaultValue": "0", + "item": { + "enumEntries": [ + "Full Cycle", + "Quarter Cycle" + ], + "name": "Encoder Type", + "variableName": "EncoderType", + "id": 51, + "eepromAddress": 100, + "functionName": "@settings_changed", + "readOnly": false, + "localOnly": false, + "visible": true, + "staticDataInRAM": false + } + }, { "parentId": 30, "type": "boolItem", @@ -509,7 +561,7 @@ "offset": 0, "divisor": 1, "unitName": "%", - "step": 1, + "step": 10, "name": "Volume", "variableName": "SoundLevel", "id": 50, @@ -522,24 +574,7 @@ } }, { - "parentId": 30, - "type": "boolItem", - "defaultValue": "false", - "item": { - "naming": "ON_OFF", - "name": "Motor Test", - "variableName": "motorTest", - "id": 44, - "eepromAddress": -1, - "functionName": "@motortest", - "readOnly": false, - "localOnly": false, - "visible": true, - "staticDataInRAM": false - } - }, - { - "parentId": 30, + "parentId": 7, "type": "textItem", "defaultValue": "1.00", "item": { @@ -560,7 +595,6 @@ "embeddedPlatform": "ARDUINO32", "lastDisplayUuid": "e6342680-6fab-4d1b-ac08-ce8dbfc0974c", "lastInputUuid": "89cd7f70-0457-4884-97c2-0db904ccb0ba", - "lastRemoteUuid": "2c101fec-1f7d-4ff3-8d2b-992ad41e7fcb", "lastRemoteUuids": [ "2c101fec-1f7d-4ff3-8d2b-992ad41e7fcb" ], @@ -685,8 +719,8 @@ } ], "namingRecursive": false, - "saveToSrc": true, "useCppMain": true, + "saveLocation": "ALL_TO_SRC", "usingSizedEEPROMStorage": true, "eepromDefinition": "eeprom:", "authenticatorDefinition": "", @@ -698,5 +732,6 @@ }, "packageNamespace": "", "appIsModular": false - } + }, + "stringLists": [] } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 84d5295..cc4e3e9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,9 +15,9 @@ board = pico framework = arduino board_build.core = earlephilhower lib_deps = - davetcc/tcMenu@^3.1.0 - davetcc/IoAbstraction@^3.1.0 - davetcc/tcUnicodeHelper@^0.2.0 + davetcc/tcMenu@^4.0.0 + davetcc/IoAbstraction@^4.0.0 + davetcc/tcUnicodeHelper@^1.0.0 tommag/TMC5160@^1.1.0 bodmer/TFT_eSPI@^2.5.23 bitbank2/PNGdec@^1.0.1 diff --git a/src/EncoderShim.cpp b/src/EncoderShim.cpp index e055f7e..a444fbd 100644 --- a/src/EncoderShim.cpp +++ b/src/EncoderShim.cpp @@ -70,6 +70,21 @@ void EncoderShim::registerClickCallback(EncoderShimFn callback) { * Reinitialize the encoder with a and b pins reversed. */ void EncoderShim::invertEncoderDirection() { + reversed = true; setupRotaryEncoderWithInterrupt(ENC2, ENC1, this, HWACCEL_NONE, FULL_CYCLE); } +/** + * Set up as a quarter cycle encoder, be careful to not undo any encoder reversing that may of happened + */ +void EncoderShim::setQuarterCycleEncoder() { + if (reversed) { + setupRotaryEncoderWithInterrupt(ENC2, ENC1, this, HWACCEL_NONE, QUARTER_CYCLE); + + } else { + setupRotaryEncoderWithInterrupt(ENC1, ENC2, this, HWACCEL_NONE, QUARTER_CYCLE); + } + + +} + diff --git a/src/EncoderShim.h b/src/EncoderShim.h index badb054..5a62d68 100644 --- a/src/EncoderShim.h +++ b/src/EncoderShim.h @@ -42,6 +42,8 @@ class EncoderShim : EncoderListener, SwitchListener { */ void invertEncoderDirection(); + void setQuarterCycleEncoder(); + private: void encoderHasChanged(int newValue) override; @@ -54,6 +56,7 @@ class EncoderShim : EncoderListener, SwitchListener { EncoderShimFn encoderClickFn = nullptr; int encoderValue = 0;// last known encoder value + bool reversed = false; }; diff --git a/src/KiwiBoardFirmware_main.cpp b/src/KiwiBoardFirmware_main.cpp index 59f5fa5..581f012 100644 --- a/src/KiwiBoardFirmware_main.cpp +++ b/src/KiwiBoardFirmware_main.cpp @@ -20,7 +20,7 @@ #include "MenuChangeObserver.h" // Version Number -const char VERSION_NUM[] PROGMEM = "1.2.0"; +const char VERSION_NUM[] PROGMEM = "1.2.1"; PicoPlatform *platform; @@ -98,6 +98,11 @@ void setup() { // reinit menu system so encoder is configured properly. setupMenu(); } +// // If this is not a full cycle encoder, reinit encoder. +// if (menuEncoderType.getCurrentValue() == 1) { +// encoderShim->setQuarterCycleEncoder(); +// setupMenu(); +// } // Get saved values for sounder and sound level.. sounderOps->set_menuSound(menusounder.getBoolean()); @@ -181,12 +186,6 @@ void ui_tick() { drawable->startDraw(); drawable->drawXBitmap(Coord(135, 0), Coord(50, 50), KiwiLogoWidIcon0); drawable->endDraw(); - - drawable = renderer.getDeviceDrawable(); - drawable->setColors(RGB(0, 0, 0), RGB(0, 0, 0)); - drawable->drawBox(Coord(0, 238), Coord(320,2), true); - drawable->endDraw(); - } // Check for heat icon, if the heater is on, show the icon, otherwise swap in the blank widget diff --git a/src/KiwiBoardFirmware_menu.cpp b/src/KiwiBoardFirmware_menu.cpp index 433741a..37b95fc 100644 --- a/src/KiwiBoardFirmware_menu.cpp +++ b/src/KiwiBoardFirmware_menu.cpp @@ -20,27 +20,35 @@ TfteSpiDrawable gfxDrawable(&gfx, 100); GraphicsDeviceRenderer renderer(30, applicationInfo.name, &gfxDrawable); // Global Menu Item declarations -RENDERING_CALLBACK_NAME_INVOKE(fnVersionRtCall, textItemRenderFn, "Version", -1, NO_CALLBACK) -TextMenuItem menuVersion(fnVersionRtCall, "1.00", 43, 10, NULL); -const BooleanMenuInfo minfomotorTest = { "Motor Test", 44, 0xffff, 1, motortest, NAMING_ON_OFF }; -BooleanMenuItem menumotorTest(&minfomotorTest, false, &menuVersion, INFO_LOCATION_PGM); +const AnyMenuInfo minfoVersion = { "Version", 43, 0xffff, 0, NO_CALLBACK }; +TextMenuItem menuVersion(&minfoVersion, "1.00", 10, nullptr, INFO_LOCATION_PGM); const AnalogMenuInfo minfoSoundLevel = { "Volume", 50, 98, 100, soundLevel, 0, 1, "%" }; -AnalogMenuItem menuSoundLevel(&minfoSoundLevel, 0, &menumotorTest, INFO_LOCATION_PGM); +AnalogMenuItem menuSoundLevel(&minfoSoundLevel, 0, nullptr, INFO_LOCATION_PGM); const BooleanMenuInfo minfosounder = { "Sound", 49, 97, 1, soundChanged, NAMING_ON_OFF }; BooleanMenuItem menusounder(&minfosounder, false, &menuSoundLevel, INFO_LOCATION_PGM); +const char enumStrEncoderType_0[] = "Full Cycle"; +const char enumStrEncoderType_1[] = "Quarter Cycle"; +const char* const enumStrEncoderType[] = { enumStrEncoderType_0, enumStrEncoderType_1 }; +const EnumMenuInfo minfoEncoderType = { "Encoder Type", 51, 100, 1, settings_changed, enumStrEncoderType }; +EnumMenuItem menuEncoderType(&minfoEncoderType, 0, &menusounder, INFO_LOCATION_PGM); +const BooleanMenuInfo minfoInvertEncoder = { "Invert Encoder", 34, 79, 1, NO_CALLBACK, NAMING_YES_NO }; +BooleanMenuItem menuInvertEncoder(&minfoInvertEncoder, false, &menuEncoderType, INFO_LOCATION_PGM); +const SubMenuInfo minfoAdvanced = { "Hardware", 30, 0xffff, 0, NO_CALLBACK }; +BackMenuItem menuBackAdvanced(&minfoAdvanced, &menuInvertEncoder, INFO_LOCATION_PGM); +SubMenuItem menuAdvanced(&minfoAdvanced, &menuBackAdvanced, &menuVersion, INFO_LOCATION_PGM); const BooleanMenuInfo minfoStealthChop = { "StealthChop", 45, 96, 1, stealthChopChange, NAMING_ON_OFF }; -BooleanMenuItem menuStealthChop(&minfoStealthChop, true, &menusounder, INFO_LOCATION_PGM); +BooleanMenuItem menuStealthChop(&minfoStealthChop, true, nullptr, INFO_LOCATION_PGM); const AnalogMenuInfo minfoIRun = { "IRun", 33, 77, 31, iRunChanged, 0, 1, "" }; AnalogMenuItem menuIRun(&minfoIRun, 17, &menuStealthChop, INFO_LOCATION_PGM); const AnalogMenuInfo minfoGlobalScaler = { "Global Scaler", 32, 75, 255, GlobalScalerChanged, 0, 1, "" }; AnalogMenuItem menuGlobalScaler(&minfoGlobalScaler, 148, &menuIRun, INFO_LOCATION_PGM); -const BooleanMenuInfo minfoInvertEncoder = { "Invert Encoder", 34, 79, 1, NO_CALLBACK, NAMING_YES_NO }; -BooleanMenuItem menuInvertEncoder(&minfoInvertEncoder, false, &menuGlobalScaler, INFO_LOCATION_PGM); -const SubMenuInfo minfoAdvanced = { "Advanced", 30, 0xffff, 0, NO_CALLBACK }; -BackMenuItem menuBackAdvanced(&minfoAdvanced, &menuInvertEncoder, INFO_LOCATION_PGM); -SubMenuItem menuAdvanced(&minfoAdvanced, &menuBackAdvanced, NULL, INFO_LOCATION_PGM); +const BooleanMenuInfo minfomotorTest = { "Motor Test", 44, 0xffff, 1, motortest, NAMING_ON_OFF }; +BooleanMenuItem menumotorTest(&minfomotorTest, false, &menuGlobalScaler, INFO_LOCATION_PGM); +const SubMenuInfo minfoMotorSettings = { "Motor Settings", 52, 0xffff, 0, NO_CALLBACK }; +BackMenuItem menuBackMotorSettings(&minfoMotorSettings, &menumotorTest, INFO_LOCATION_PGM); +SubMenuItem menuMotorSettings(&minfoMotorSettings, &menuBackMotorSettings, &menuAdvanced, INFO_LOCATION_PGM); const AnalogMenuInfo minfoMaxPreheat = { "Preheat", 48, 94, 9, settings_changed, 1, 1, "min" }; -AnalogMenuItem menuMaxPreheat(&minfoMaxPreheat, 4, NULL, INFO_LOCATION_PGM); +AnalogMenuItem menuMaxPreheat(&minfoMaxPreheat, 4, nullptr, INFO_LOCATION_PGM); const AnalogMenuInfo minfocooldownTime = { "Cool Time", 19, 21, 9, settings_changed, 1, 1, "min" }; AnalogMenuItem menucooldownTime(&minfocooldownTime, 1, &menuMaxPreheat, INFO_LOCATION_PGM); const BooleanMenuInfo minfofanCooldown = { "Cooldown", 18, 20, 1, settings_changed, NAMING_ON_OFF }; @@ -51,22 +59,22 @@ const AnalogMenuInfo minfodry_duration = { "Time", 16, 16, 10, settings_changed, AnalogMenuItem menudry_duration(&minfodry_duration, 4, &menudry_speed, INFO_LOCATION_PGM); const SubMenuInfo minfoDrySettings = { "Dry", 15, 0xffff, 0, NO_CALLBACK }; BackMenuItem menuBackDrySettings(&minfoDrySettings, &menudry_duration, INFO_LOCATION_PGM); -SubMenuItem menuDrySettings(&minfoDrySettings, &menuBackDrySettings, &menuAdvanced, INFO_LOCATION_PGM); +SubMenuItem menuDrySettings(&minfoDrySettings, &menuBackDrySettings, &menuMotorSettings, INFO_LOCATION_PGM); const AnalogMenuInfo minfospinAMAX = { "Accel", 40, 88, 2000, settings_changed, 500, 1, "" }; -AnalogMenuItem menuspinAMAX(&minfospinAMAX, 375, NULL, INFO_LOCATION_PGM); -const AnalogMenuInfo minfospin_speed = { "Speed", 14, 14, 950, settings_changed, 50, 1, "rpm" }; -AnalogMenuItem menuspin_speed(&minfospin_speed, 50, &menuspinAMAX, INFO_LOCATION_PGM); +AnalogMenuItem menuspinAMAX(&minfospinAMAX, 375, nullptr, INFO_LOCATION_PGM); +const AnalogMenuInfo minfospin_speed = { "Speed", 14, 14, 650, settings_changed, 50, 1, "rpm" }; +AnalogMenuItem menuspin_speed(&minfospin_speed, 350, &menuspinAMAX, INFO_LOCATION_PGM); const AnalogMenuInfo minfospin_duration = { "Time", 13, 12, 119, settings_changed, 1, 1, "sec" }; AnalogMenuItem menuspin_duration(&minfospin_duration, 44, &menuspin_speed, INFO_LOCATION_PGM); const SubMenuInfo minfoSpinSettings = { "Spin", 12, 0xffff, 0, NO_CALLBACK }; BackMenuItem menuBackSpinSettings(&minfoSpinSettings, &menuspin_duration, INFO_LOCATION_PGM); SubMenuItem menuSpinSettings(&minfoSpinSettings, &menuBackSpinSettings, &menuDrySettings, INFO_LOCATION_PGM); const AnalogMenuInfo minfowashAMAX = { "Accel", 41, 90, 2000, settings_changed, 500, 1, "" }; -AnalogMenuItem menuwashAMAX(&minfowashAMAX, 400, NULL, INFO_LOCATION_PGM); +AnalogMenuItem menuwashAMAX(&minfowashAMAX, 400, nullptr, INFO_LOCATION_PGM); const AnalogMenuInfo minfowash_speed = { "Speed", 11, 10, 350, settings_changed, 50, 1, "rpm" }; AnalogMenuItem menuwash_speed(&minfowash_speed, 175, &menuwashAMAX, INFO_LOCATION_PGM); const AnalogMenuInfo minfoRotations = { "Rotations", 39, 86, 10, settings_changed, 1, 1, "" }; -AnalogMenuItem menuRotations(&minfoRotations, 1, &menuwash_speed, INFO_LOCATION_PGM); +AnalogMenuItem menuRotations(&minfoRotations, 6, &menuwash_speed, INFO_LOCATION_PGM); const AnalogMenuInfo minfowash_duration = { "Time", 9, 4, 9, settings_changed, 1, 1, "min" }; AnalogMenuItem menuwash_duration(&minfowash_duration, 4, &menuRotations, INFO_LOCATION_PGM); const SubMenuInfo minfowashSettings = { "Wash", 8, 0xffff, 0, NO_CALLBACK }; @@ -76,15 +84,15 @@ const AnalogMenuInfo minfoBacklight = { "Backlight", 36, 84, 7, backlightChange, AnalogMenuItem menuBacklight(&minfoBacklight, 3, &menuwashSettings, INFO_LOCATION_PGM); const SubMenuInfo minfoSettings = { "Settings", 7, 0xffff, 0, NO_CALLBACK }; BackMenuItem menuBackSettings(&minfoSettings, &menuBacklight, INFO_LOCATION_PGM); -SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, NULL, INFO_LOCATION_PGM); +SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, nullptr, INFO_LOCATION_PGM); const AnyMenuInfo minfoDry = { "Dry", 38, 0xffff, 0, dry }; ActionMenuItem menuDry(&minfoDry, &menuSettings, INFO_LOCATION_PGM); const AnyMenuInfo minfoSpin = { "Spin", 37, 0xffff, 0, spin }; ActionMenuItem menuSpin(&minfoSpin, &menuDry, INFO_LOCATION_PGM); AnyMenuInfo minfoWash = { "Wash", 2, 0xffff, 0, wash }; ActionMenuItem menuWash(&minfoWash, &menuSpin, INFO_LOCATION_RAM); -RENDERING_CALLBACK_NAME_INVOKE(fnRunTimeRtCall, timeItemRenderFn, "RunTime", -1, NO_CALLBACK) -TimeFormattedMenuItem menuRunTime(fnRunTimeRtCall, TimeStorage(0, 0, 0, 0), 6, (MultiEditWireType)6, &menuWash); +const AnyMenuInfo minfoRunTime = { "RunTime", 6, 0xffff, 0, NO_CALLBACK }; +TimeFormattedMenuItem menuRunTime(&minfoRunTime, TimeStorage(0, 0, 0, 0), (MultiEditWireType)6, &menuWash, INFO_LOCATION_PGM); void setupMenu() { // First we set up eeprom and authentication (if needed). @@ -93,10 +101,11 @@ void setupMenu() { // Now add any readonly, non-remote and visible flags. menuVersion.setReadOnly(true); menuspinAMAX.setStep(25); - menuspin_speed.setStep(5); menuwashAMAX.setStep(25); + menuspin_speed.setStep(5); menuwash_speed.setStep(5); menudry_speed.setStep(5); + menuSoundLevel.setStep(10); // Code generated by plugins. gfx.begin(); diff --git a/src/KiwiBoardFirmware_menu.h b/src/KiwiBoardFirmware_menu.h index 8898ce6..c01653f 100644 --- a/src/KiwiBoardFirmware_menu.h +++ b/src/KiwiBoardFirmware_menu.h @@ -30,15 +30,18 @@ extern GraphicsDeviceRenderer renderer; // Global Menu Item exports extern TextMenuItem menuVersion; -extern BooleanMenuItem menumotorTest; extern AnalogMenuItem menuSoundLevel; extern BooleanMenuItem menusounder; -extern BooleanMenuItem menuStealthChop; -extern AnalogMenuItem menuIRun; -extern AnalogMenuItem menuGlobalScaler; +extern EnumMenuItem menuEncoderType; extern BooleanMenuItem menuInvertEncoder; extern BackMenuItem menuBackAdvanced; extern SubMenuItem menuAdvanced; +extern BooleanMenuItem menuStealthChop; +extern AnalogMenuItem menuIRun; +extern AnalogMenuItem menuGlobalScaler; +extern BooleanMenuItem menumotorTest; +extern BackMenuItem menuBackMotorSettings; +extern SubMenuItem menuMotorSettings; extern AnalogMenuItem menuMaxPreheat; extern AnalogMenuItem menucooldownTime; extern BooleanMenuItem menufanCooldown; diff --git a/src/motorControl.cpp b/src/motorControl.cpp index 5b1dd51..4cdc6e3 100644 --- a/src/motorControl.cpp +++ b/src/motorControl.cpp @@ -187,6 +187,8 @@ void MotorControl::exec() { if (motor->getCurrentSpeed() == 0) { state.isRunning = false; state.isStopping = false; + motor->setCurrentPosition(0, true); // Reset position + motor->setTargetPosition(0); // Reset position platform->enableMotor(false); @@ -194,8 +196,8 @@ void MotorControl::exec() { stoppedCallback(state.program); } } else { - // Give it 10 10 ticks to finish before stopping it manually - if (!state.isTesting && state.stopping_cnt == 10) { + // Give it 50 ticks to finish before stopping it manually + if (!state.isTesting && state.stopping_cnt == 50) { motor->setCurrentPosition(0, true); // Reset position motor->setTargetPosition(0); // Reset position diff --git a/src/tcMenuTfteSpi.cpp b/src/tcMenuTfteSpi.cpp index 6716905..6286c6f 100644 --- a/src/tcMenuTfteSpi.cpp +++ b/src/tcMenuTfteSpi.cpp @@ -13,10 +13,11 @@ */ #include "tcMenuTfteSpi.h" -#include "tcUnicodeHelper.h" +#include "tcUnicodeTFT_eSPI.h" #include using namespace iotouch; +using namespace tcgfx; TfteSpiDrawable::TfteSpiDrawable(TFT_eSPI *tft, int spriteHeight) : tft(tft), spriteWithConfig(nullptr), spriteHeight(spriteHeight) {} @@ -110,7 +111,7 @@ void TfteSpiDrawable::fontPtrToNum(const void* font, int mag) { } UnicodeFontHandler *TfteSpiDrawable::createFontHandler() { - return fontHandler = new UnicodeFontHandler(tft, tccore::ENCMODE_UTF8); + return fontHandler = new UnicodeFontHandler(newTFT_eSPITextPipeline(tft), tccore::ENCMODE_UTF8); } // @@ -126,7 +127,7 @@ bool TftSpriteAndConfig::initSprite(const Coord &spriteWhere, const Coord &sprit if(spriteSize.x > size.x || spriteSize.y > size.y) return false; if(root->isTcUnicodeEnabled() && fontHandler == nullptr) { - fontHandler = new UnicodeFontHandler(&sprite, tccore::ENCMODE_UTF8); + fontHandler = new UnicodeFontHandler(newTFT_eSPITextPipeline(&sprite), tccore::ENCMODE_UTF8); } // create the sprite if needed