Browse Source

rad display

main
gsd 6 months ago
parent
commit
e9f5d1ef8b
  1. 4
      .vscode/settings.json
  2. 169
      pipboyIO/display.cpp
  3. 6
      pipboyIO/display.h
  4. 4
      pipboyIO/pipboyIO.ino

4
.vscode/settings.json

@ -20,6 +20,8 @@
"span": "cpp",
"unordered_set": "cpp",
"format": "cpp",
"text_encoding": "cpp"
"text_encoding": "cpp",
"ios": "cpp",
"random": "cpp"
}
}

169
pipboyIO/display.cpp

@ -21,30 +21,35 @@ void initDisplay() {
//display1.clearDisplay();
//Serial.println("start display 2");
display2.clearDisplay();
//заливаем весь дисплей
/*display2.clearDisplay();
for (int x = 0; x < 128; x ++) {
for (int y = 0; y < 64; y++) {
display2.drawPixel(x, y, SSD1306_WHITE);
}
}
}*/
//default huynnya
display2.clearDisplay();
//display2BorderDebug();
display2Border();
display2DrawSenseLine(3.5);
display2.display();
//Serial.println("start display 2 test success");
}
void drawPoint(int displayId, int x, int y) {
//float rad = y * PI / 180.0;
switch (displayId)
{
case 1:
//display1.clearDisplay();
//display1.drawPixel(x, y, SSD1306_WHITE);
break;
case 2:
display2.clearDisplay();
display2Border();
display2.drawPixel(x, y, SSD1306_WHITE);
display2.display();
break;
display2.clearDisplay();
display2Border();
display2DrawSenseLine(map(x, 0, 10, 90, -90));
display2.display();
break;
default:
break;
}
@ -65,11 +70,153 @@ const int16_t borders[][2] = {
};
const int borderSize = sizeof(borders) / sizeof(borders[0]);
void display2Border() {
void display2BorderDebug() {
int x = 0;
int y = 1;
for (int i = 1; i <borderSize; i++) {
display2.drawLine(borders[i-1][x], borders[i-1][y], borders[i][x], borders[i][y], WHITE);
}
display2.drawLine(borders[borderSize-1][x], borders[borderSize-1][y], borders[0][x], borders[0][y], WHITE);
}
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 centerX = 65;
const int centerY = 55;
void display2Border() {
int radius[3] = {30, 40, 45};
const int internal = 0;
const int external = 1;
const int extended = 2;
display2.drawPixel(centerX, centerY, WHITE);
for (int r = 1; r < 5; r++) {
display2.drawCircle(centerX, centerY, r, WHITE);
}
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);
radsCalc(centerX, centerY, radius[internal], radSin, radCos);
radsCalc(centerX, centerY, radius[external], radSin, radCos);
//need chunk
if (absAngle % 18 == 0) {
if ((absAngle + 90) % 36 == 0) {
int endLineX = centerX + (radius[extended] * radSin);
int endLineY = centerY - (radius[extended] * radCos);
int endLine4ChrX = centerX + ((radius[extended]+5) * radSin);
int endLine4ChrY = centerY - ((radius[extended]+5) * radCos);
display2.drawLine(
centerX + (radius[internal] * radSin),
centerY - (radius[internal] * radCos),
endLineX,
endLineY,
WHITE
);
int letChr = (5 - ((angle + 90) / 36)) * 2;
switch (letChr)
{
case 2:
for (int i = 0; i < sizeof(TwoLetterPoint) / sizeof(TwoLetterPoint[0]); i++) {
display2.drawPixel(endLine4ChrX + TwoLetterPoint[i][0], endLine4ChrY + TwoLetterPoint[i][1], WHITE);
}
break;
case 4:
for (int i = 0; i < sizeof(FourLetterPoint) / sizeof(FourLetterPoint[0]); i++) {
display2.drawPixel(endLine4ChrX + FourLetterPoint[i][0], endLine4ChrY + FourLetterPoint[i][1], WHITE);
}
break;
case 6:
for (int i = 0; i < sizeof(SixLetterPoint) / sizeof(SixLetterPoint[0]); i++) {
display2.drawPixel(endLine4ChrX + SixLetterPoint[i][0], endLine4ChrY + SixLetterPoint[i][1], WHITE);
}
break;
case 8:
for (int i = 0; i < sizeof(EightLetterPoint) / sizeof(EightLetterPoint[0]); i++) {
display2.drawPixel(endLine4ChrX + EightLetterPoint[i][0], endLine4ChrY + EightLetterPoint[i][1], WHITE);
}
break;
default:
break;
}
} else {
display2.drawLine(
centerX + (radius[internal] * radSin),
centerY - (radius[internal] * radCos),
centerX + (radius[external] * radSin),
centerY - (radius[external] * radCos),
WHITE
);
}
}
}
}
void radsCalc(int16_t x, int16_t y, int radius, float radSin, float radCos) {
int endX = x + (radius * radSin);
int endY = y - (radius * radCos);
display2.drawPixel(endX, endY, WHITE);
}
void display2DrawSenseLine(float value) {
int r = 45;
float rad = value * PI / 180.0;
float radSin = sin(rad);
float radCos = cos(rad);
for (int x = centerX - 1; x < centerX + 1; x++) {
for (int y = centerY - 1; y < centerY + 1; y++) {
display2.drawLine(x, y, x + (r * radSin), y - (r * radCos), WHITE);
}
}
}
//65, 55, 50, ?
void rads(int16_t x, int16_t y, int radius, float rad) {
//float rad = angle * PI / 180.0;
//display2.drawPixel(x, y, WHITE);
int endX = x + (radius * sin(rad));
int endY = y - (radius * cos(rad));
display2.drawPixel(endX, endY, WHITE);
}

6
pipboyIO/display.h

@ -15,4 +15,8 @@
void initDisplay();
void drawPoint(int displayId, int x, int y);
void display2Border();
void display2BorderDebug();
void rads(int16_t x, int16_t y, int radius, float rad);
void radsCalc(int16_t x, int16_t y, int radius, float radSin, float radCos);
void display2Border();
void display2DrawSenseLine(float value);

4
pipboyIO/pipboyIO.ino

@ -120,5 +120,9 @@ void processInput(String input) {
int displayId = n1.toInt();
int x = n2.toInt();
int y = n3.toInt();
Serial.println(displayId);
Serial.println(x);
Serial.println(y);
drawPoint(displayId, x, y);
}
Loading…
Cancel
Save