diff --git a/pipboyIO/extDisplay.cpp b/pipboyIO/extDisplay.cpp index 53b0cfa..2a3bf7b 100644 --- a/pipboyIO/extDisplay.cpp +++ b/pipboyIO/extDisplay.cpp @@ -2,6 +2,7 @@ #include #include #include "extDisplay.h" +#include "radDisplaySettings.h" #define EXT_DISPLAY_I2C_ADDRESS 0x3C #define EXT_SCREEN_WIDTH 128 @@ -17,7 +18,176 @@ void initExtDisplay() { for(;;); } + changeExt(0); +} + +void changeExt(float value) { extDisplay.clearDisplay(); - extDisplay.fillScreen(WHITE); + overlayOnExtDisplay(); + drawLineExtDisplay(valueOnExtDisplay(value)); + extDisplay.display(); +} + +void pixelOnExtDisplay(int16_t x, int16_t y) { + extDisplay.clearDisplay(); + extDisplay.drawPixel(x, y, WHITE); + extDisplay.display(); +} + +float valueOnExtDisplay(float value) { + return mapFloat(value, 10, 70, 150, 210); +} + +void drawLineExtDisplay(float value) { + int r = 120; + float rad = value * PI / 180.0; + float radSin = sin(rad); + float radCos = cos(rad); + + for (int x = extCenterX - 1; x < extCenterX + 1; x++) { + for (int y = extCenterY - 1; y < extCenterY + 1; y++) { + extDisplay.drawLine(x, y, x + (r * radSin), y - (r * radCos), WHITE); + } + } +} + +void overlayOnExtDisplay() { + int duga[2] = {85, 125}; + for (int d = 0; d < 2; d++) { + for (int angle = 150; angle <= 210.0; angle += 1) { + float rad = angle * PI / 180.0; + float radSin = sin(rad); + float radCos = cos(rad); + + int endX = 64 + (duga[d] * radSin); + int endY = -70 - (duga[d] * radCos); + extDisplay.drawPixel(endX, endY, WHITE); + + if (d == 0 && angle % 10 == 0) { + int duga0ext = 95; + int startX = 64 + (duga0ext * radSin); + int startY = -70 - (duga0ext * radCos); + extDisplay.drawLine(endX, endY, startX, startY, WHITE); + } + + if (d == 0 && angle % 2 == 0) { + int duga0ext = 90; + int startX = 64 + (duga0ext * radSin); + int startY = -70 - (duga0ext * radCos); + extDisplay.drawLine(endX, endY, startX, startY, WHITE); + } + + if (d == 1 && angle % 5 == 0) { + int duga1ext = 128; + int startX = 64 + (duga1ext * radSin); + int startY = -70 - (duga1ext * radCos); + extDisplay.drawLine(endX, endY, startX, startY, WHITE); + } + + if (d == 0 && angle % 10 == 0) { + int neededLetter = abs(140 - angle); + int duga1ext = duga[d] + 15; + int startX = 64 + (duga1ext * radSin); + int startY = -70 - (duga1ext * radCos); + int moveLetters = 5; + + for (int i = 0; i < sizeof(ZeroLetterPoint) / sizeof(ZeroLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + ZeroLetterPoint[i][0], startY + ZeroLetterPoint[i][1], WHITE); + } + + switch (neededLetter) { + case 10: + for (int i = 0; i < sizeof(OneLetterPoint) / sizeof(OneLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + OneLetterPoint[i][0], startY + OneLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 20: + for (int i = 0; i < sizeof(TwoLetterPoint) / sizeof(TwoLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + TwoLetterPoint[i][0], startY + TwoLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 30: + for (int i = 0; i < sizeof(ThreeLetterPoint) / sizeof(ThreeLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + ThreeLetterPoint[i][0], startY + ThreeLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 40: + for (int i = 0; i < sizeof(FourLetterPoint) / sizeof(FourLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + FourLetterPoint[i][0], startY + FourLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 50: + for (int i = 0; i < sizeof(FiveLetterPoint) / sizeof(FiveLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + FiveLetterPoint[i][0], startY + FiveLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 60: + for (int i = 0; i < sizeof(SixLetterPoint) / sizeof(SixLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + SixLetterPoint[i][0], startY + SixLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 70: + for (int i = 0; i < sizeof(SevenLetterPoint) / sizeof(SevenLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + SevenLetterPoint[i][0], startY + SevenLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + case 80: + for (int i = 0; i < sizeof(EightLetterPoint) / sizeof(EightLetterPoint[0]); i++) { + extDisplay.drawPixel(startX + EightLetterPoint[i][0], startY + EightLetterPoint[i][1] + moveLetters, WHITE); + } + break; + + default: + break; + } + } + } + } +} + +//display calc +// center 64 / -70 +// break high radius 132 +// break low raduis 80 + +// 80 min 150 +// 80 max 210 + +void lineCalcOnExtDisplay(int16_t x, int16_t y, int radius) { + extDisplay.clearDisplay(); + overlayOnExtDisplay(); + /*for (int r = -180; r < 180; r ++) { + float rad = r * PI / 180.0; + int endX = x + (radius * sin(rad)); + int endY = y - (radius * cos(rad)); + + if (endX <= 128 && endX >= 0 && endY <= 64 && endY >= 0) { + Serial.print(endX); + Serial.print(" "); + Serial.println(endY); + extDisplay.drawPixel(endX, endY, WHITE); + } + }*/ + + float rad = x * PI / 180.0; + int endX = 64 + (radius * sin(rad)); + int endY = -70 - (radius * cos(rad)); + + Serial.print(endX); + Serial.print(" "); + Serial.println(endY); + + if (endX <= 128 && endX >= 0 && endY <= 64 && endY >= 0) { + extDisplay.drawPixel(endX, endY, WHITE); + } + + extDisplay.display(); } \ No newline at end of file diff --git a/pipboyIO/extDisplay.h b/pipboyIO/extDisplay.h index 808eaa3..1b32c15 100644 --- a/pipboyIO/extDisplay.h +++ b/pipboyIO/extDisplay.h @@ -1,4 +1,13 @@ #define EXT_I2C_SDA 21 #define EXT_I2C_SCL 5 -void initExtDisplay(); \ No newline at end of file +const int extCenterX = 64; +const int extCenterY = -70; + +void initExtDisplay(); +void pixelOnExtDisplay(int16_t x, int16_t y); +void lineCalcOnExtDisplay(int16_t x, int16_t y, int radius); +void overlayOnExtDisplay(); +float valueOnExtDisplay(float value); +void drawLineExtDisplay(float value); +void changeExt(float value); \ No newline at end of file diff --git a/pipboyIO/pipboyIO.ino b/pipboyIO/pipboyIO.ino index 34da782..066e314 100644 --- a/pipboyIO/pipboyIO.ino +++ b/pipboyIO/pipboyIO.ino @@ -119,11 +119,15 @@ void processInput(String input) { String n2 = input.substring(firstSpace + 1, secondSpace); String n3 = input.substring(secondSpace + 1); - int displayId = n1.toInt(); - float x = n2.toFloat(); + int anyVar = n1.toInt(); + int x = n2.toInt(); int y = n3.toInt(); - if (displayId == 2) { - changeRad(x); + if (anyVar == 10002) { + changeRad(n2.toFloat()); + } + + if (anyVar == 10001) { + changeExt(n2.toFloat()); } } \ No newline at end of file diff --git a/pipboyIO/radDisplay.cpp b/pipboyIO/radDisplay.cpp index 7d816a4..bfa5b02 100644 --- a/pipboyIO/radDisplay.cpp +++ b/pipboyIO/radDisplay.cpp @@ -28,10 +28,6 @@ float convertValueToRadDisplay(float value) { return mapFloat(value, 0, 10, 90, -90); } -float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - void drawLineRadDisplay(float value) { int r = 45; float rad = value * PI / 180.0; diff --git a/pipboyIO/radDisplay.h b/pipboyIO/radDisplay.h index 1aa7887..b2dc015 100644 --- a/pipboyIO/radDisplay.h +++ b/pipboyIO/radDisplay.h @@ -16,4 +16,3 @@ float convertValueToRadDisplay(float value); void drawLineRadDisplay(float value); void calcRad(int16_t x, int16_t y, int radius, float radSin, float radCos); void overlayRadDisplay(); -float mapFloat(float x, float in_min, float in_max, float out_min, float out_max); \ No newline at end of file diff --git a/pipboyIO/radDisplaySettings.cpp b/pipboyIO/radDisplaySettings.cpp index e69de29..d6dda2b 100644 --- a/pipboyIO/radDisplaySettings.cpp +++ b/pipboyIO/radDisplaySettings.cpp @@ -0,0 +1,3 @@ +float mapFloat(float x, float in_min, float in_max, float out_min, float out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} \ No newline at end of file diff --git a/pipboyIO/radDisplaySettings.h b/pipboyIO/radDisplaySettings.h index 7daae4b..294b33a 100644 --- a/pipboyIO/radDisplaySettings.h +++ b/pipboyIO/radDisplaySettings.h @@ -1,10 +1,9 @@ const int TwoLetterPoint[][2] = { - {0,3},{0,2},{0,1},{0,0}, - {1,0}, - {1,1}, - {2,2}, - {3,3}, - {4,3},{4,2},{4,1},{4,0} + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 0}, + {2, 3}, {2, 2}, {2, 1}, {2, 0}, + {3, 3}, + {4, 3}, {4, 2}, {4, 1}, {4, 0} }; const int FourLetterPoint[][2] = { @@ -31,10 +30,60 @@ const int EightLetterPoint[][2] = { {4, 3}, {4, 2}, {4, 1}, {4, 0} }; +const int FullLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 3}, {1, 2}, {1, 1}, {1, 0}, + {2, 3}, {2, 2}, {2, 1}, {2, 0}, + {3, 3}, {3, 2}, {3, 1}, {3, 0}, + {4, 3}, {4, 2}, {4, 1}, {4, 0} +}; + const int radCenterX = 65; const int radCenterY = 55; const int radRadius[3] = {30, 40, 45}; const int internal = 0; const int external = 1; -const int extended = 2; \ No newline at end of file +const int extended = 2; + +const int ZeroLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 3}, {1, 0}, + {2, 3}, {2, 0}, + {3, 3}, {3, 0}, + {4, 3}, {4, 2}, {4, 1}, {4, 0} +}; + +const int ThreeLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 0}, + {2, 3}, {2, 2}, {2, 1}, {2, 0}, + {3, 0}, + {4, 3}, {4, 2}, {4, 1}, {4, 0} +}; + +const int FiveLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 3}, + {2, 3}, {2, 2}, {2, 1}, {2, 0}, + {3, 0}, + {4, 3}, {4, 2}, {4, 1}, {4, 0} +}; + +const int SevenLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 0}, + {2, 1}, + {3, 2}, + {4, 3}, +}; + +const int OneLetterPoint[][2] = { + {0, 1}, + {1, 2}, {1, 1}, + {2, 1}, + {3, 1}, + {4, 2}, {4, 1}, {4, 0} +}; + +float mapFloat(float x, float in_min, float in_max, float out_min, float out_max); \ No newline at end of file