Ver código fonte

upd progcalc

MX 2 anos atrás
pai
commit
9bb86587ad

+ 1 - 1
non_catalog_apps/prog_calculator/application.fam

@@ -11,6 +11,6 @@ App(
     fap_category="Tools",
     fap_author="@armixz",
     fap_weburl="https://github.com/armixz/Flipper-Zero-Programmer-Calculator",
-    fap_version="0.8",
+    fap_version="0.9",
     fap_description="Calculator, for Programmers!",
 )

+ 54 - 54
non_catalog_apps/prog_calculator/calculation_logic.c

@@ -23,21 +23,21 @@ static const char* HEX_TO_BINARY_TABLE[16] = {
     "1110", 
     "1111"};
 
-bool decToBin(const char* decString, char* binaryResult, size_t resultSize) {
-    if(decString == NULL || binaryResult == NULL || resultSize < 2) {
-        return false; // Invalid pointers or insufficient result size
+bool decToBin(const char* decString, char* decToBinResult, size_t resultSize) {
+    if(decString == NULL || decToBinResult == NULL || resultSize < 2) {
+        return false; // INVALID pointers or insufficient result size
     }
 
     char* end;
-    unsigned long num = strtoul(decString, &end, 10);
+    unsigned long long num = strtoull(decString, &end, 10);
 
     if(*end != '\0' || *decString == '\0') {
-        return false; // Invalid decimal
+        return false; // INVALID decimal
     }
 
     // Calculate the number of bits
     size_t bitsNeeded = 0;
-    unsigned long tempNum = num;
+    unsigned long long tempNum = num;
     while(tempNum > 0) {
         bitsNeeded++;
         tempNum >>= 1;
@@ -48,7 +48,7 @@ bool decToBin(const char* decString, char* binaryResult, size_t resultSize) {
         if(resultSize < 2) {
             return false; // buffer
         }
-        strcpy(binaryResult, "0");
+        strcpy(decToBinResult, "0");
         return true;
     }
 
@@ -57,24 +57,24 @@ bool decToBin(const char* decString, char* binaryResult, size_t resultSize) {
         return false;
     }
 
-    binaryResult[bitsNeeded] = '\0'; // Null-terminate the result
+    decToBinResult[bitsNeeded] = '\0'; // Null-terminate the result
 
     // fill the binary string from the end
     for(int i = bitsNeeded - 1; i >= 0; i--) {
-        binaryResult[i] = (num & 1) + '0'; // the least significant bit
+        decToBinResult[i] = (num & 1) + '0'; // the least significant bit
         num >>= 1;
     }
 
     return true;
 }
 
-bool decToHex(const char* decString, char* hexResult, size_t resultSize) {
-    if(decString == NULL || hexResult == NULL || resultSize == 0) {
+bool decToHex(const char* decString, char* decToHexResult, size_t resultSize) {
+    if(decString == NULL || decToHexResult == NULL || resultSize == 0) {
         return false;
     }
 
     char* end;
-    unsigned long num = strtoul(decString, &end, 10);
+    unsigned long long num = strtoull(decString, &end, 10);
 
     if(*end != '\0' || *decString == '\0') {
         return false;
@@ -82,7 +82,7 @@ bool decToHex(const char* decString, char* hexResult, size_t resultSize) {
 
     // buffer size
     size_t requiredSize = 1;
-    unsigned long tempNum = num;
+    unsigned long long tempNum = num;
 
     while(tempNum >= 16) {
         requiredSize++;
@@ -93,31 +93,31 @@ bool decToHex(const char* decString, char* hexResult, size_t resultSize) {
         return false;
     }
 
-    hexResult[requiredSize] = '\0';
+    decToHexResult[requiredSize] = '\0';
 
     // convert to hexadecimal in reverse order
     do{
         int remainder = num % 16;
-        hexResult[--requiredSize] = (remainder < 10) ? ('0' + remainder) : ('A' + (remainder - 10));
+        decToHexResult[--requiredSize] = (remainder < 10) ? ('0' + remainder) : ('A' + (remainder - 10));
         num /= 16;
     } while(num > 0);
 
     return true;
 }
 
-bool decToChar(const char* decString, char* outChar) {
-    if(decString == NULL || outChar == NULL || *decString == '\0') {
+bool decToChar(const char* decString, char* decToCharResult) {
+    if(decString == NULL || decToCharResult == NULL || *decString == '\0') {
         return false;
     }
 
     char* end;
-    unsigned long num = strtoul(decString, &end, 10);
+    unsigned long long num = strtoull(decString, &end, 10);
 
     if(*end != '\0' || num > 255) {
         return false;
     }
 
-    *outChar = (char)num;
+    *decToCharResult = (char)num;
     return true;
 }
 
@@ -140,8 +140,8 @@ bool hexDigitToBinary(char hexDigit, char* binary) {
     }
 }
 
-bool hexToBin(const char* hexString, char* binaryResult, size_t resultSize) {
-    if(hexString == NULL || binaryResult == NULL || resultSize == 0) {
+bool hexToBin(const char* hexString, char* hexToBinResult, size_t resultSize) {
+    if(hexString == NULL || hexToBinResult == NULL || resultSize == 0) {
         return false;
     }
 
@@ -165,22 +165,22 @@ bool hexToBin(const char* hexString, char* binaryResult, size_t resultSize) {
         if(resultSize < 4) {
             return false;
         }
-        memcpy(binaryResult, hexToBinary, 4);
-        binaryResult += 4;
+        memcpy(hexToBinResult, hexToBinary, 4);
+        hexToBinResult += 4;
         hexString++;
         resultSize -= 4;
     }
 
-    *binaryResult = '\0';
+    *hexToBinResult = '\0';
     return true;
 }
 
-bool hexToDec(const char* hexString, int* outNum) {
-    if(hexString == NULL || outNum == NULL) {
+bool hexToDec(const char* hexString, int* hexToDecResult) {
+    if(hexString == NULL || hexToDecResult == NULL) {
         return false;
     }
 
-    *outNum = 0;
+    *hexToDecResult = 0;
     while(*hexString) {
         char digit = *hexString;
         int value;
@@ -195,31 +195,31 @@ bool hexToDec(const char* hexString, int* outNum) {
             return false;
         }
 
-        if(*outNum > INT_MAX / 16 || (*outNum == INT_MAX / 16 && value > INT_MAX % 16)) {
+        if(*hexToDecResult > INT_MAX / 16 || (*hexToDecResult == INT_MAX / 16 && value > INT_MAX % 16)) {
             return false; // check overflow
         }
 
-        *outNum = *outNum * 16 + value;
+        *hexToDecResult = *hexToDecResult * 16 + value;
         hexString++;
     }
 
     return true;
 }
 
-bool binToDec(const char* binaryString, int* decResult) {
-    if(binaryString == NULL || decResult == NULL) {
+bool binToDec(const char* binaryString, int* binToDecResult) {
+    if(binaryString == NULL || binToDecResult == NULL) {
         return false;
     }
 
-    *decResult = 0;
+    *binToDecResult = 0;
     for(const char* p = binaryString; *p; ++p) {
         if(*p != '0' && *p != '1') {
             return false;
         }
-        if(*decResult > INT_MAX / 2) {
+        if(*binToDecResult > INT_MAX / 2) {
             return false; // check overflow
         }
-        *decResult = (*decResult << 1) | (*p - '0');
+        *binToDecResult = (*binToDecResult << 1) | (*p - '0');
     }
 
     return true;
@@ -234,8 +234,8 @@ char binaryToHexDigit(const char* bin) {
     return (value < 10) ? ('0' + value) : ('A' + (value - 10));
 }
 
-bool binToHex(const char* binaryString, char* hexResult, size_t resultSize) {
-    if(binaryString == NULL || hexResult == NULL || resultSize == 0) {
+bool binToHex(const char* binaryString, char* binToHexResult, size_t resultSize) {
+    if(binaryString == NULL || binToHexResult == NULL || resultSize == 0) {
         return false;
     }
 
@@ -243,7 +243,7 @@ bool binToHex(const char* binaryString, char* hexResult, size_t resultSize) {
 
     for(size_t i = 0; i < binLength; ++i) {
         if(binaryString[i] != '0' && binaryString[i] != '1') {
-            snprintf(hexResult, resultSize, "Invalid Binary");
+            snprintf(binToHexResult, resultSize, "INVALID Binary");
             return false;
         }
     }
@@ -268,12 +268,12 @@ bool binToHex(const char* binaryString, char* hexResult, size_t resultSize) {
         }
 
         if(tempIndex == 4) {
-            hexResult[hexIndex++] = binaryToHexDigit(tempBin);
+            binToHexResult[hexIndex++] = binaryToHexDigit(tempBin);
             tempIndex = 0;
         }
     }
 
-    hexResult[hexIndex] = '\0';
+    binToHexResult[hexIndex] = '\0';
     return true;
 }
 
@@ -287,51 +287,51 @@ void calculate(Calculator* calculator_state) {
 
     switch(calculator_state->mode) {
     case ModeDecToBin:
-        if(!decToBin(calculator_state->text, calculator_state->binaryResult, sizeof(calculator_state->binaryResult))) {
-            snprintf(calculator_state->binaryResult, sizeof(calculator_state->binaryResult), "Invalid Dec");
+        if(!decToBin(calculator_state->text, calculator_state->decToBinResult, sizeof(calculator_state->decToBinResult))) {
+            snprintf(calculator_state->decToBinResult, sizeof(calculator_state->decToBinResult), "INVALID D");
         }
         break;
 
     case ModeDecToHex:
-        if(!decToHex(calculator_state->text, calculator_state->hexResult, sizeof(calculator_state->hexResult))) {
-            snprintf(calculator_state->hexResult, sizeof(calculator_state->hexResult), "Invalid Dec");
+        if(!decToHex(calculator_state->text, calculator_state->decToHexResult, sizeof(calculator_state->decToHexResult))) {
+            snprintf(calculator_state->decToHexResult, sizeof(calculator_state->decToHexResult), "INVALID D");
         }
         break;
 
     case ModeDecToChar:
         if(decToChar(calculator_state->text, &result)) {
-            calculator_state->charResult[0] = result;
-            calculator_state->charResult[1] = '\0';
+            calculator_state->decToCharResult[0] = result;
+            calculator_state->decToCharResult[1] = '\0';
         } else {
-            snprintf(calculator_state->charResult, sizeof(calculator_state->charResult), "Invalid Dec");
+            snprintf(calculator_state->decToCharResult, sizeof(calculator_state->decToCharResult), "INVALID D");
         }
         break;
 
     case ModeHexToBin:
-        if(!hexToBin(calculator_state->text, calculator_state->binaryResult, sizeof(calculator_state->binaryResult))) {
-            snprintf(calculator_state->binaryResult, sizeof(calculator_state->binaryResult), "Invalid Hex");
+        if(!hexToBin(calculator_state->text, calculator_state->hexToBinResult, sizeof(calculator_state->hexToBinResult))) {
+            snprintf(calculator_state->hexToBinResult, sizeof(calculator_state->hexToBinResult), "INVALID H");
         }
         break;
 
     case ModeHexToDec:
         if(hexToDec(calculator_state->text, &num)) {
-            snprintf(calculator_state->decResult, sizeof(calculator_state->decResult), "%d", num);
+            snprintf(calculator_state->hexToDecResult, sizeof(calculator_state->hexToDecResult), "%d", num);
         } else {
-            snprintf(calculator_state->decResult, sizeof(calculator_state->decResult), "Invalid Hex");
+            snprintf(calculator_state->hexToDecResult, sizeof(calculator_state->hexToDecResult), "INVALID H");
         }
         break;
 
     case ModeBinToDec:
         if(binToDec(calculator_state->text, &num)) {
-            snprintf(calculator_state->decResult, sizeof(calculator_state->decResult), "%d", num);
+            snprintf(calculator_state->binToDecResult, sizeof(calculator_state->binToDecResult), "%d", num);
         } else {
-            snprintf(calculator_state->decResult, sizeof(calculator_state->decResult), "Invalid Binary");
+            snprintf(calculator_state->binToDecResult, sizeof(calculator_state->binToDecResult), "INVALID B");
         }
         break;
 
     case ModeBinToHex:
-        if(!binToHex(calculator_state->text, calculator_state->hexResult, sizeof(calculator_state->hexResult))) {
-            snprintf(calculator_state->hexResult, sizeof(calculator_state->hexResult), "Invalid Binary");
+        if(!binToHex(calculator_state->text, calculator_state->binToHexResult, sizeof(calculator_state->binToHexResult))) {
+            snprintf(calculator_state->binToHexResult, sizeof(calculator_state->binToHexResult), "INVALID B");
         }
         break;
 

+ 2 - 2
non_catalog_apps/prog_calculator/calculation_logic.h

@@ -3,8 +3,8 @@
 
 #include "calculator_state.h"
 
-bool decToBin(const char* decString, char* binaryResult, size_t resultSize);
-bool decToHex(const char* decString, char* hexResult, size_t resultSize);
+bool decToBin(const char* decString, char* decToBinResult, size_t resultSize);
+bool decToHex(const char* decString, char* decToHexResult, size_t resultSize);
 bool decToChar(const char* decString, char* outChar);
 bool hexToBin(const char* hexString, char* binaryResult, size_t resultSize);
 bool hexToDec(const char* hexString, int* outNum);

+ 12 - 8
non_catalog_apps/prog_calculator/calculator_state.h

@@ -4,7 +4,8 @@
 #include <furi.h>
 #include <stdbool.h>
 
-#define MAX_TEXT_LENGTH 30
+#define MAX_TEXT_LENGTH_INPUT 19
+#define MAX_TEXT_LENGTH_RESULT 37
 
 typedef enum {
     ModeNone,
@@ -25,14 +26,17 @@ typedef struct {
 typedef struct {
     FuriMutex* mutex;
     selectedPosition position;
-    char text[MAX_TEXT_LENGTH];
-    char originalInput[MAX_TEXT_LENGTH];
-    char binaryResult[MAX_TEXT_LENGTH];
-    char hexResult[MAX_TEXT_LENGTH];
-    char decResult[MAX_TEXT_LENGTH];
-    char charResult[MAX_TEXT_LENGTH];
+    char text[MAX_TEXT_LENGTH_INPUT];
+    char originalInput[MAX_TEXT_LENGTH_INPUT];
+    char decToBinResult[MAX_TEXT_LENGTH_RESULT];
+    char decToHexResult[MAX_TEXT_LENGTH_RESULT];
+    char decToCharResult[MAX_TEXT_LENGTH_RESULT];
+    char hexToBinResult[MAX_TEXT_LENGTH_RESULT];
+    char hexToDecResult[MAX_TEXT_LENGTH_RESULT];
+    char binToDecResult[MAX_TEXT_LENGTH_RESULT];
+    char binToHexResult[MAX_TEXT_LENGTH_RESULT];
     short textLength;
-    char log[MAX_TEXT_LENGTH];
+    char log[MAX_TEXT_LENGTH_RESULT];
     bool newInputStarted;
     CalculatorMode mode;
 } Calculator;

+ 10 - 7
non_catalog_apps/prog_calculator/input_handling.c

@@ -84,7 +84,7 @@ void handle_long_press(Calculator* calculator_state, ViewPort* view_port, InputE
     switch(event->key) {
         case InputKeyOk:
             if(calculator_state->position.x == 0 && calculator_state->position.y == 4) {
-                if(calculator_state->textLength < MAX_TEXT_LENGTH) {
+                if(calculator_state->textLength < MAX_TEXT_LENGTH_INPUT) {
                     calculator_state->text[calculator_state->textLength++] = ')';
                     calculator_state->text[calculator_state->textLength] = '\0';
                 }
@@ -101,7 +101,7 @@ void handle_key_press(Calculator* calculator_state, char key) {
     switch(key) {
     case '=':
         // Logic for '=' key
-        strncpy(calculator_state->originalInput, calculator_state->text, MAX_TEXT_LENGTH);
+        strncpy(calculator_state->originalInput, calculator_state->text, MAX_TEXT_LENGTH_INPUT);
         calculate(calculator_state);
         // calculator_state->text[0] = '\0';
         calculator_state->textLength = 0;
@@ -110,10 +110,13 @@ void handle_key_press(Calculator* calculator_state, char key) {
         // Logic for 'R' key, typically 'Clear'
         calculator_state->text[0] = '\0';
         calculator_state->textLength = 0;
-        calculator_state->binaryResult[0] = '\0';  // Clear binary result
-        calculator_state->decResult[0] = '\0';     // Clear binary result
-        calculator_state->charResult[0] = '\0';    // Clear binary result
-        calculator_state->hexResult[0] = '\0';     // Clear hex result
+        calculator_state->decToBinResult[0] = '\0';
+        calculator_state->decToHexResult[0] = '\0';
+        calculator_state->decToCharResult[0] = '\0';
+        calculator_state->hexToBinResult[0] = '\0';
+        calculator_state->hexToDecResult[0] = '\0';
+        calculator_state->binToDecResult[0] = '\0';
+        calculator_state->binToHexResult[0] = '\0';
         calculator_state->newInputStarted = false;
         break;
     case '<':
@@ -132,7 +135,7 @@ void handle_key_press(Calculator* calculator_state, char key) {
             calculator_state->newInputStarted = false;
         }
         // Add the new character to the text, respecting the maximum text length
-        if(calculator_state->textLength < MAX_TEXT_LENGTH - 1) {
+        if(calculator_state->textLength < MAX_TEXT_LENGTH_INPUT - 1) {
             calculator_state->text[calculator_state->textLength++] = key;
             calculator_state->text[calculator_state->textLength] = '\0';
         }

+ 86 - 39
non_catalog_apps/prog_calculator/ui_drawing.c

@@ -16,8 +16,8 @@ void generate_calculator_layout(Canvas* canvas) {
 
     // display
     canvas_draw_frame(canvas, 0, 0, 64, 62);  // display frame
-    canvas_draw_frame(canvas, 2, 2, 60, 31);  // output  frame
-    canvas_draw_frame(canvas, 2, 34, 60, 26); // input   frame
+    canvas_draw_frame(canvas, 2, 2, 60, 38);  // output  frame
+    canvas_draw_frame(canvas, 2, 41, 60, 19); // input   frame
 
     // Horizonal and Vertical lines
     // drawElement(canvas, NULL, 0, 48, 64, 2, 0);  // H line 1
@@ -36,29 +36,29 @@ void generate_calculator_layout(Canvas* canvas) {
     drawElement(canvas, NULL, 62, 61, 2, 65, 0); // V line 6
 
     // MODE key and display
-    // row 1 and 2
-    drawElement(canvas, "", 4, 72, 0, 0, FontSecondary);
+    // row 1
+    drawElement(canvas, "M", 4, 72, 0, 0, FontSecondary);
 
     // Keys
-    // row 3
+    // row 2
     drawElement(canvas, "7", 5, 85, 0, 0, FontSecondary);
     drawElement(canvas, "8", 17, 85, 0, 0, FontSecondary);
     drawElement(canvas, "9", 29, 85, 0, 0, FontSecondary);
     drawElement(canvas, "A", 42, 85, 0, 0, FontSecondary);
     drawElement(canvas, "B", 54, 85, 0, 0, FontSecondary);
-    // row 4
+    // row 3
     drawElement(canvas, "4", 5, 98, 0, 0, FontSecondary);
     drawElement(canvas, "5", 17, 98, 0, 0, FontSecondary);
     drawElement(canvas, "6", 29, 98, 0, 0, FontSecondary);
     drawElement(canvas, "C", 42, 98, 0, 0, FontSecondary);
     drawElement(canvas, "D", 54, 98, 0, 0, FontSecondary);
-    // row 5
+    // row 4
     drawElement(canvas, "1", 6, 111, 0, 0, FontSecondary);
     drawElement(canvas, "2", 17, 111, 0, 0, FontSecondary);
     drawElement(canvas, "3", 29, 111, 0, 0, FontSecondary);
     drawElement(canvas, "E", 42, 111, 0, 0, FontSecondary);
     drawElement(canvas, "F", 54, 111, 0, 0, FontSecondary);
-    // row 6
+    // row 5
     drawElement(canvas, "<", 6, 124, 0, 0, FontSecondary);
     drawElement(canvas, "0", 17, 124, 0, 0, FontSecondary);
     drawElement(canvas, "=", 29, 124, 0, 0, FontSecondary);
@@ -72,14 +72,41 @@ void draw_highlighted_cell(Canvas* canvas, short x, short y, short width, short
     canvas_draw_box(canvas, x, y, width, height);
 }
 
-void displayResult(Canvas* canvas, char* result, int x, int y) {
-    const int maxLength = 24; // Maximum length for splitting into lines
-    const int lineLength = 12; // Length of each line
+void displayInput(Canvas* canvas, const char* input, int x, int y) {
+    const int maxLength = 18; // Maximum length for splitting into lines
+    const int lineLength = 9; // Length of each line
+    const int lineSpacing = 8; // Reduced line spacing
+
+    int length = strlen(input);
+
+    if(length > lineLength) {
+        char line1[lineLength + 1];
+        strncpy(line1, input, lineLength);
+        line1[lineLength] = '\0';
+
+        const char* line2 = input + lineLength;
+
+        canvas_draw_str(canvas, x, y, line1);
+        if (length > maxLength) {
+            char trimmedLine2[maxLength - lineLength + 1];
+            strncpy(trimmedLine2, line2, maxLength - lineLength);
+            trimmedLine2[maxLength - lineLength] = '\0';
+            canvas_draw_str(canvas, x, y + lineSpacing, trimmedLine2);
+        } else {
+            canvas_draw_str(canvas, x, y + lineSpacing, line2); // lineSpacing used here
+        }
+    } else {
+        canvas_draw_str(canvas, x, y, input); // Single line if lineLength characters or less
+    }
+}
+
+void displayResult(Canvas* canvas, const char* result, int x, int y) {
+    const int lineLength = 9; // Length of each line
     const int lineSpacing = 9; // Reduced line spacing
 
     int length = strlen(result);
 
-    if(length > maxLength) {
+    if(length > 3 * lineLength) {  // More than 3 lines
         char line1[lineLength + 1];
         strncpy(line1, result, lineLength);
         line1[lineLength] = '\0';
@@ -88,12 +115,31 @@ void displayResult(Canvas* canvas, char* result, int x, int y) {
         strncpy(line2, result + lineLength, lineLength);
         line2[lineLength] = '\0';
 
-        const char* line3 = result + (2 * lineLength);
+        char line3[lineLength + 1];
+        strncpy(line3, result + 2 * lineLength, lineLength);
+        line3[lineLength] = '\0';
+
+        const char* line4 = result + 3 * lineLength; // Remainder of the text
 
         canvas_draw_str(canvas, x, y, line1);
         canvas_draw_str(canvas, x, y + lineSpacing, line2);
-        canvas_draw_str(canvas, x, y + (2 * lineSpacing), line3);
-    } else if(length > lineLength) {
+        canvas_draw_str(canvas, x, y + 2 * lineSpacing, line3);
+        canvas_draw_str(canvas, x, y + 3 * lineSpacing, line4);
+    } else if(length > 2 * lineLength) {  // More than 2 lines
+        char line1[lineLength + 1];
+        strncpy(line1, result, lineLength);
+        line1[lineLength] = '\0';
+
+        char line2[lineLength + 1];
+        strncpy(line2, result + lineLength, lineLength);
+        line2[lineLength] = '\0';
+
+        const char* line3 = result + 2 * lineLength;
+
+        canvas_draw_str(canvas, x, y, line1);
+        canvas_draw_str(canvas, x, y + lineSpacing, line2);
+        canvas_draw_str(canvas, x, y + 2 * lineSpacing, line3);
+    } else if(length > lineLength) {  // More than 1 line
         char line1[lineLength + 1];
         strncpy(line1, result, lineLength);
         line1[lineLength] = '\0';
@@ -107,6 +153,7 @@ void displayResult(Canvas* canvas, char* result, int x, int y) {
     }
 }
 
+
 void calculator_draw_callback(Canvas* canvas, void* ctx) {
     furi_assert(ctx);
     const Calculator* calculator_state = ctx;
@@ -118,56 +165,56 @@ void calculator_draw_callback(Canvas* canvas, void* ctx) {
     // Draw the static UI layout
     generate_calculator_layout(canvas);
 
-    char resultLabel[2 * MAX_TEXT_LENGTH]; // Buffer to hold the result label
-    char modeNumber[3]; // Buffer to hold the mode number
+    char resultLabel[2 * MAX_TEXT_LENGTH_RESULT]; // Buffer to hold the result label
+    // char modeNumber[3]; // Buffer to hold the mode number
 
     // Check which mode is selected and prepare the label accordingly
     switch(calculator_state->mode) {
     case ModeDecToBin:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->binaryResult);
-        strcpy(modeNumber, "1");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->decToBinResult);
+        // strcpy(modeNumber, "M");
         break;
     case ModeDecToHex:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->hexResult);
-        strcpy(modeNumber, "2");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->decToHexResult);
+        // strcpy(modeNumber, "M");
         break;
     case ModeDecToChar:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->charResult);
-        strcpy(modeNumber, "3");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->decToCharResult);
+        // strcpy(modeNumber, "M");
         break;
     case ModeHexToBin:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->binaryResult);
-        strcpy(modeNumber, "4");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->hexToBinResult);
+        // strcpy(modeNumber, "M");
         break;
     case ModeHexToDec:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->decResult);
-        strcpy(modeNumber, "5");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->hexToDecResult);
+        // strcpy(modeNumber, "M");
         break;
     case ModeBinToDec:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->decResult);
-        strcpy(modeNumber, "6");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->binToDecResult);
+        // strcpy(modeNumber, "M");
         break;
     case ModeBinToHex:
-        snprintf(resultLabel, sizeof(resultLabel), "> %s", calculator_state->hexResult);
-        strcpy(modeNumber, "7");
+        snprintf(resultLabel, sizeof(resultLabel), "%s", calculator_state->binToHexResult);
+        // strcpy(modeNumber, "M");
         break;
     default:
         // If no mode is selected, you can display a default message or leave it empty
-        strncpy(resultLabel, "Click [M]ODE_________   <PCalc v0.8>", sizeof(resultLabel));
-        strcpy(modeNumber, "M");
+        strncpy(resultLabel, "         -> [M]ODE_________<P Calc v0.9>", sizeof(resultLabel));
+        // strcpy(modeNumber, "M");
         break;
     }
 
     // Display the result, splitting into two lines if necessary
-    displayResult(canvas, resultLabel, 5, 12);
+    displayResult(canvas, resultLabel, 4, 11);
 
     // Draw new input with ">" label or mode selection prompt
-    char inputLabel[MAX_TEXT_LENGTH + 1]; // Adjusted size for "> "
-    snprintf(inputLabel, sizeof(inputLabel), ">%s", calculator_state->text);
-    canvas_draw_str(canvas, 5, 44, inputLabel);
+    char inputLabel[MAX_TEXT_LENGTH_INPUT + 2]; // Adjusted size for "> "
+    snprintf(inputLabel, sizeof(inputLabel), "%s", calculator_state->text);
+    displayInput(canvas, inputLabel, 4, 50);
 
     // Replace "M" with the current mode number
-    canvas_draw_str(canvas, 5, 72, modeNumber); // Position where "M" was originally drawn
+    // canvas_draw_str(canvas, 5, 72, modeNumber); // Position where "M" was originally drawn
 
     // Define the cell dimensions for each row and column
     const short cellDimensions[5][5][2] = {
@@ -207,7 +254,7 @@ void calculator_draw_callback(Canvas* canvas, void* ctx) {
         break;
     }
     
-    canvas_draw_str(canvas, 15, 72, modeStr);
+    canvas_draw_str(canvas, 16, 71, modeStr);
     short cursorX = 2;
     short cursorY = 61; // Starting Y position
 

+ 2 - 1
non_catalog_apps/prog_calculator/ui_drawing.h

@@ -7,7 +7,8 @@
 void drawElement(Canvas* canvas, const char* str, int x, int y, int width, int height, Font font);
 void generate_calculator_layout(Canvas* canvas);
 void draw_highlighted_cell(Canvas* canvas, short x, short y, short width, short height);
-void displayResult(Canvas* canvas, char* result, int x, int y);
+void displayInput(Canvas* canvas, const char* input, int x, int y);
+void displayResult(Canvas* canvas, const char* result, int x, int y);
 void calculator_draw_callback(Canvas* canvas, void* ctx);
 
 #endif // UI_DRAWING_H