diff --git a/pipboyIO/pipboyIO.ino b/pipboyIO/pipboyIO.ino index 183ddc3..df3ae21 100644 --- a/pipboyIO/pipboyIO.ino +++ b/pipboyIO/pipboyIO.ino @@ -2,7 +2,7 @@ #include #include #include -#include "display.h" +#include "radDisplay.h" const int input[] = {}; long inputCurrentValue[] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -28,7 +28,7 @@ void setup() { #endif setupEncoder(); - initDisplay(); + initRadDisplay(); pinMode(buttonInput[0], INPUT); @@ -118,11 +118,10 @@ void processInput(String input) { String n3 = input.substring(secondSpace + 1); int displayId = n1.toInt(); - int x = n2.toInt(); + float x = n2.toFloat(); int y = n3.toInt(); - - Serial.println(displayId); - Serial.println(x); - Serial.println(y); - drawPoint(displayId, x, y); + + if (displayId == 2) { + changeRad(x); + } } \ No newline at end of file diff --git a/pipboyIO/radDisplay.cpp b/pipboyIO/radDisplay.cpp new file mode 100644 index 0000000..7d816a4 --- /dev/null +++ b/pipboyIO/radDisplay.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include "radDisplay.h" +#include "radDisplaySettings.h" + +Adafruit_SSD1306 radDisplay(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1); + +void initRadDisplay() { + Wire1.begin(RAD_I2C_SDA, RAD_I2C_SCL); + if(!radDisplay.begin(SSD1306_SWITCHCAPVCC, RAD_DISPLAY_I2C_ADDRESS)) { + //Serial.println("SSD1306 #2 allocation failed"); + for(;;); + } + + changeRad(0); +} + +void changeRad(float value) { + radDisplay.clearDisplay(); + radDisplay.fillScreen(RADBGRND); + overlayRadDisplay(); + drawLineRadDisplay(convertValueToRadDisplay(value)); + radDisplay.display(); +} + +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; + float radSin = sin(rad); + float radCos = cos(rad); + + for (int x = radCenterX - 1; x < radCenterX + 1; x++) { + for (int y = radCenterY - 1; y < radCenterY + 1; y++) { + radDisplay.drawLine(x, y, x + (r * radSin), y - (r * radCos), RADCOLOR); + } + } +} + +//todo optimaze +void calcRad(int16_t x, int16_t y, int radius, float radSin, float radCos) { + int endX = x + (radius * radSin); + int endY = y - (radius * radCos); + radDisplay.drawPixel(endX, endY, RADCOLOR); +} + +void overlayRadDisplay() { + radDisplay.drawPixel(radCenterX, radCenterY, RADCOLOR); + for (int r = 1; r < 5; r++) { + radDisplay.drawCircle(radCenterX, radCenterY, r, RADCOLOR); + } + + for (int angle = -90; angle <= 90; angle++) { + float rad = angle * PI / 180.0; + int absAngle = abs(angle); + float radSin = sin(rad); + float radCos = cos(rad); + + calcRad(radCenterX, radCenterY, radRadius[internal], radSin, radCos); + calcRad(radCenterX, radCenterY, radRadius[external], radSin, radCos); + + //need chunk + if (absAngle % 18 == 0) { + if ((absAngle + 90) % 36 == 0) { + int endLineX = radCenterX + (radRadius[extended] * radSin); + int endLineY = radCenterY - (radRadius[extended] * radCos); + + int endLine4ChrX = radCenterX + ((radRadius[extended]+5) * radSin); + int endLine4ChrY = radCenterY - ((radRadius[extended]+5) * radCos); + + radDisplay.drawLine( + radCenterX + (radRadius[internal] * radSin), + radCenterY - (radRadius[internal] * radCos), + endLineX, + endLineY, + RADCOLOR + ); + + int letChr = (5 - ((angle + 90) / 36)) * 2; + switch (letChr) + { + case 2: + for (int i = 0; i < sizeof(TwoLetterPoint) / sizeof(TwoLetterPoint[0]); i++) { + radDisplay.drawPixel(endLine4ChrX + TwoLetterPoint[i][0], endLine4ChrY + TwoLetterPoint[i][1], RADCOLOR); + } + break; + case 4: + for (int i = 0; i < sizeof(FourLetterPoint) / sizeof(FourLetterPoint[0]); i++) { + radDisplay.drawPixel(endLine4ChrX + FourLetterPoint[i][0], endLine4ChrY + FourLetterPoint[i][1], RADCOLOR); + } + break; + case 6: + for (int i = 0; i < sizeof(SixLetterPoint) / sizeof(SixLetterPoint[0]); i++) { + radDisplay.drawPixel(endLine4ChrX + SixLetterPoint[i][0], endLine4ChrY + SixLetterPoint[i][1], RADCOLOR); + } + break; + case 8: + for (int i = 0; i < sizeof(EightLetterPoint) / sizeof(EightLetterPoint[0]); i++) { + radDisplay.drawPixel(endLine4ChrX + EightLetterPoint[i][0], endLine4ChrY + EightLetterPoint[i][1], RADCOLOR); + } + break; + default: + break; + } + + + } else { + radDisplay.drawLine( + radCenterX + (radRadius[internal] * radSin), + radCenterY - (radRadius[internal] * radCos), + radCenterX + (radRadius[external] * radSin), + radCenterY - (radRadius[external] * radCos), + RADCOLOR + ); + } + } + } +} \ No newline at end of file diff --git a/pipboyIO/radDisplay.h b/pipboyIO/radDisplay.h new file mode 100644 index 0000000..1aa7887 --- /dev/null +++ b/pipboyIO/radDisplay.h @@ -0,0 +1,19 @@ +#include + +#define RAD_I2C_SDA 19 //19 +#define RAD_I2C_SCL 18 //18 +#define RAD_DISPLAY_I2C_ADDRESS 0x3C + +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 64 + +#define RADCOLOR BLACK +#define RADBGRND WHITE + +void initRadDisplay(); +void changeRad(float value); +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 new file mode 100644 index 0000000..e69de29 diff --git a/pipboyIO/radDisplaySettings.h b/pipboyIO/radDisplaySettings.h new file mode 100644 index 0000000..7daae4b --- /dev/null +++ b/pipboyIO/radDisplaySettings.h @@ -0,0 +1,40 @@ +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} +}; + +const int FourLetterPoint[][2] = { + {0, 1}, + {1, 2}, {1, 1}, + {2, 3}, {2, 1}, + {3, 3},{3,2}, {3, 1}, {3, 0}, + {4, 1} +}; + +const int SixLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 3}, + {2, 3}, {2, 2}, {2, 1}, {2, 0}, + {3, 3}, {3, 0}, + {4, 3}, {4, 2}, {4, 1}, {4, 0} +}; + +const int EightLetterPoint[][2] = { + {0, 3}, {0, 2}, {0, 1}, {0, 0}, + {1, 3}, {1, 0}, + {2, 3}, {2, 2}, {2, 1}, {2, 0}, + {3, 3}, {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