From e89eb58de47db89e9ebab2d065a28777be77f95b Mon Sep 17 00:00:00 2001 From: Stanislav N Mikhailov Date: Thu, 2 Jan 2025 00:12:20 +0300 Subject: [PATCH] decomposition --- CMakeLists.txt | 2 +- DrawBezier.c | 8 +------- DrawBezier.h | 3 +-- Reverse.c | 5 +++++ Reverse.h | 4 ++++ SetPixel.c | 8 ++++++++ SetPixel.h | 5 +++++ SineWave.c | 20 ++++++++++++++++++++ SineWave.h | 4 ++++ font_data.c | 4 ++-- font_data_dirt.c | 8 -------- font_data_dirt.h | 12 ------------ main.c | 22 +--------------------- main.h | 1 + 14 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 Reverse.c create mode 100644 Reverse.h create mode 100644 SetPixel.c create mode 100644 SetPixel.h create mode 100644 SineWave.c create mode 100644 SineWave.h delete mode 100644 font_data_dirt.c delete mode 100644 font_data_dirt.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e876d16..3073f9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 17) pico_sdk_init() -add_executable(${PROJECT_NAME} main.c Thread.c DrawBezier.c font_data.c) +add_executable(${PROJECT_NAME} main.c Thread.c DrawBezier.c font_data.c Reverse.c SineWave.c SetPixel.c) target_link_libraries(${PROJECT_NAME} pico_stdlib diff --git a/DrawBezier.c b/DrawBezier.c index d47ac0e..1eae67d 100644 --- a/DrawBezier.c +++ b/DrawBezier.c @@ -1,11 +1,5 @@ #include "DrawBezier.h" -// Установка пикселя в буфере (с проверкой границ) -void set_pixel(uint16_t x, uint16_t y, uint16_t color) { - if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) { - frame_buffer[y * WIDTH + x] = color; - } -} - +#include "SetPixel.h" // Функция для вычисления базисного полинома Бернштейна float bernstein(int i, int n, float t) { // Вычисление биномиального коэффициента C(n, i) diff --git a/DrawBezier.h b/DrawBezier.h index 1d3240a..c9c4a9f 100644 --- a/DrawBezier.h +++ b/DrawBezier.h @@ -1,9 +1,8 @@ #include #include -#include #include #include "Thread.h" -void set_pixel(uint16_t x, uint16_t y, uint16_t color); + float bernstein(int i, int n, float t); void draw_bezier(const int *points_x, const int *points_y, size_t num_points, uint16_t color); \ No newline at end of file diff --git a/Reverse.c b/Reverse.c new file mode 100644 index 0000000..adae891 --- /dev/null +++ b/Reverse.c @@ -0,0 +1,5 @@ +unsigned short reverse(unsigned short x) +{ + x = (x & 0xFF) << 8 | (x & 0xFF00) >> 8; + return x; +} \ No newline at end of file diff --git a/Reverse.h b/Reverse.h new file mode 100644 index 0000000..5588c6a --- /dev/null +++ b/Reverse.h @@ -0,0 +1,4 @@ +#ifndef REVERSE_H +#define REVERSE_H +unsigned short reverse(unsigned short x); +#endif \ No newline at end of file diff --git a/SetPixel.c b/SetPixel.c new file mode 100644 index 0000000..6706a49 --- /dev/null +++ b/SetPixel.c @@ -0,0 +1,8 @@ +#include "SetPixel.h" +#include "Thread.h" +// Установка пикселя в буфере (с проверкой границ) +void set_pixel(uint16_t x, uint16_t y, uint16_t color) { + if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) { + frame_buffer[y * WIDTH + x] = color; + } +} diff --git a/SetPixel.h b/SetPixel.h new file mode 100644 index 0000000..6321885 --- /dev/null +++ b/SetPixel.h @@ -0,0 +1,5 @@ +#ifndef SET_PIXEL_H +#define SET_PIXEL_H +#include +void set_pixel(uint16_t x, uint16_t y, uint16_t color); +#endif \ No newline at end of file diff --git a/SineWave.c b/SineWave.c new file mode 100644 index 0000000..d0e4db5 --- /dev/null +++ b/SineWave.c @@ -0,0 +1,20 @@ +#include "SineWave.h" +#include "font_data.h" +#include "Thread.h" +#include "Reverse.h" +#include "SetPixel.h" +#include +void generate_sine_wave_points(size_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift) { + if (num_points == 0) { + return; + } + + float step = (2.0f * M_PI * frequency) / (num_points - 1); + float x_step = (float)WIDTH / (num_points - 1); + + for (size_t i = 0; i < num_points; i++) { + int x = offset_x + (int)(i * x_step); + int y = offset_y + (int)(amplitude * sinf(i * step + phase_shift)); // Добавлен сдвиг фазы + set_pixel(x, y, reverse(0b0000011111100000)); + } +} diff --git a/SineWave.h b/SineWave.h new file mode 100644 index 0000000..ed7023d --- /dev/null +++ b/SineWave.h @@ -0,0 +1,4 @@ +#ifdef SINE_WAVE_H +#define SINE_WAVE_H +void generate_sine_wave_points(size_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift); +#endif \ No newline at end of file diff --git a/font_data.c b/font_data.c index af80b05..5502af9 100644 --- a/font_data.c +++ b/font_data.c @@ -1,8 +1,8 @@ // Шрифт, сгенерированный из /home/smikhai/Repo/rp_pico_test/Font/font_grid_with_cyrillic.bmp #include "font_data.h" #include "Thread.h" -#include "DrawBezier.h" - +#include "SetPixel.h" +#include const uint16_t image_linear_width = 704; const uint8_t char_width = 22; diff --git a/font_data_dirt.c b/font_data_dirt.c deleted file mode 100644 index 7db9e7b..0000000 --- a/font_data_dirt.c +++ /dev/null @@ -1,8 +0,0 @@ -// Изображение, сгенерированное из Font/font_grid_with_cyrillic.bmp -#include - -const uint16_t image_linear_width = 7744; -const uint8_t char_width = 22; -const uint8_t char_height = 22; -const uint16_t total_chars = 352; - diff --git a/font_data_dirt.h b/font_data_dirt.h deleted file mode 100644 index af0a786..0000000 --- a/font_data_dirt.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef IMAGE_DATA_H -#define IMAGE_DATA_H - -#include - -extern const uint16_t image_linear_width; -extern const uint8_t char_width; -extern const uint8_t char_height; -extern const uint16_t total_chars; -extern const uint8_t image_data[]; - -#endif // IMAGE_DATA_H diff --git a/main.c b/main.c index 6347a8d..6700472 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ #include "pico/stdlib.h" #include "DrawBezier.h" #include "font_data.h" - +#include "Reverse.h" int main() { uint16_t red = 0; uint16_t green = 0; @@ -65,23 +65,3 @@ void fillBufer (uint16_t* buffer,uint16_t color){ } -unsigned short reverse(unsigned short x) -{ - x = (x & 0xFF) << 8 | (x & 0xFF00) >> 8; - return x; -} - -void generate_sine_wave_points(size_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift) { - if (num_points == 0) { - return; - } - - float step = (2.0f * M_PI * frequency) / (num_points - 1); - float x_step = (float)WIDTH / (num_points - 1); - - for (size_t i = 0; i < num_points; i++) { - int x = offset_x + (int)(i * x_step); - int y = offset_y + (int)(amplitude * sinf(i * step + phase_shift)); // Добавлен сдвиг фазы - set_pixel(x, y, reverse(0b0000011111100000)); - } -} diff --git a/main.h b/main.h index e1df071..c034a87 100644 --- a/main.h +++ b/main.h @@ -1,3 +1,4 @@ + #include void fillBufer (uint16_t* buffer,uint16_t color); unsigned short reverse(unsigned short x);