single repo

This commit is contained in:
Adolfo Reyna
2026-01-01 13:33:51 -05:00
parent 8b56187ef1
commit bc8ae91eba
334 changed files with 124529 additions and 2 deletions
@@ -0,0 +1,80 @@
#include "ShapeRenderer.h"
void pico_ssd1306::drawLine(pico_ssd1306::SSD1306 *ssd1306, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
pico_ssd1306::WriteMode mode) {
int x, y, dx, dy, dx0, dy0, px, py, xe, ye, i;
dx = x1 - x0;
dy = y1 - y0;
dx0 = fabs(dx);
dy0 = fabs(dy);
px = 2 * dy0 - dx0;
py = 2 * dx0 - dy0;
if (dy0 <= dx0) {
if (dx >= 0) {
x = x0;
y = y0;
xe = x1;
} else {
x = x1;
y = y1;
xe = x0;
}
ssd1306->setPixel(x, y, mode);
for (i = 0; x < xe; i++) {
x = x + 1;
if (px < 0) {
px = px + 2 * dy0;
} else {
if ((dx < 0 && dy < 0) || (dx > 0 && dy > 0)) {
y = y + 1;
} else {
y = y - 1;
}
px = px + 2 * (dy0 - dx0);
}
ssd1306->setPixel(x, y, mode);
}
} else {
if (dy >= 0) {
x = x0;
y = y0;
ye = y1;
} else {
x = x1;
y = y1;
ye = y0;
}
ssd1306->setPixel(x, y, mode);
for (i = 0; y < ye; i++) {
y = y + 1;
if (py <= 0) {
py = py + 2 * dx0;
} else {
if ((dx < 0 && dy < 0) || (dx > 0 && dy > 0)) {
x = x + 1;
} else {
x = x - 1;
}
py = py + 2 * (dx0 - dy0);
}
ssd1306->setPixel(x, y, mode);
}
}
}
void pico_ssd1306::drawRect(pico_ssd1306::SSD1306 *ssd1306, uint8_t x_start, uint8_t y_start, uint8_t x_end, uint8_t y_end,
pico_ssd1306::WriteMode mode) {
drawLine(ssd1306, x_start, y_start, x_end, y_start, mode);
drawLine(ssd1306, x_start, y_end, x_end, y_end, mode);
drawLine(ssd1306, x_start, y_start, x_start, y_end, mode);
drawLine(ssd1306, x_end, y_start, x_end, y_end, mode);
}
void pico_ssd1306::fillRect(pico_ssd1306::SSD1306 *ssd1306, uint8_t x_start, uint8_t y_start, uint8_t x_end, uint8_t y_end,
pico_ssd1306::WriteMode mode) {
for (uint8_t x = x_start; x <= x_end; x++) {
for (uint8_t y = y_start; y <= y_end; y++) {
ssd1306->setPixel(x, y, mode);
}
}
}
@@ -0,0 +1,27 @@
#ifndef SSD1306_SHAPERENDERER_H
#define SSD1306_SHAPERENDERER_H
#include <math.h>
#include "../ssd1306.h"
namespace pico_ssd1306{
/// \brief Draws a line from x0, y0 to x1, y1.
/// It supports all drawing angles
/// \param ssd1306 - is the pointer to a SSD1306 object aka an initialised display
/// \param x0, y0, x1, y1 are the start and end coordinates between which the line will be drawn
/// \param mode - mode describes setting behavior. See WriteMode doc for more information
void drawLine (pico_ssd1306::SSD1306 *ssd1306, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, pico_ssd1306::WriteMode mode = pico_ssd1306::WriteMode::ADD);
/// \brief Draws a 1px wide rectangle between x0, y0 and x1, y1
/// \param x_start, x_end, y_start, y_end - corner points for the rectangle
/// \param mode - mode describes setting behavior. See WriteMode doc for more information
void drawRect (pico_ssd1306::SSD1306 *ssd1306 , uint8_t x_start, uint8_t y_start, uint8_t x_end, uint8_t y_end, pico_ssd1306::WriteMode mode = pico_ssd1306::WriteMode::ADD);
/// \brief Fills a rectangle from x0, y0 to x1, y1
/// \param x_start, x_end, y_start, y_end - corner points for the rectangle
/// \param mode - mode describes setting behavior. See WriteMode doc for more information
void fillRect (pico_ssd1306::SSD1306 *ssd1306 , uint8_t x_start, uint8_t y_start, uint8_t x_end, uint8_t y_end, pico_ssd1306::WriteMode mode = pico_ssd1306::WriteMode::ADD);
}
#endif //SSD1306_SHAPERENDERER_H
+27
View File
@@ -0,0 +1,27 @@
# Shape Renderer Module
## This module provides functions for drawing basic geometrical shapes with simple code
## 1. Importing
```c++
#include "pico-ssd1306/shapeRenderer/ShapeRenderer.h"
```
note that core library and hardware_i2c library's need to be imported to use this library so follow steps from section 1
of [readme.md](../readme.md)
## 2. Differences from core library
Calling functions from modules is different from core lib. You can't just do ```object.drawLine(...``` since modules don't
actually extend the SSD1306 class. You need to provide module functions with a pointer to a display object. So the first
argument of every module draw function is a pointer to a display.
To see this more clearly here is an example:
```c++
// Create a new display object
pico_ssd1306::SSD1306 display = pico_ssd1306::SSD1306(I2C_PORT, 0x3D, pico_ssd1306::Size::W128xH64);
// Draw a line from x: 0, y: 0 to x: 128, y: 64
// Notice how we first pass the address of display object to the function
pico_ssd1306::drawLine(&display, 0, 0, 128, 64);
```
## All functions are documented [here](https://ssd1306.harbys.me)