From b791e9ab3358083ecac40d409096e4624ef3878b Mon Sep 17 00:00:00 2001 From: Erik Strand <erik.strand@cba.mit.edu> Date: Fri, 10 May 2019 00:37:45 -0400 Subject: [PATCH] Start drawing traces --- node_board/main.cpp | 111 +++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 42 deletions(-) diff --git a/node_board/main.cpp b/node_board/main.cpp index 81f77ef..729c2b8 100644 --- a/node_board/main.cpp +++ b/node_board/main.cpp @@ -3,10 +3,10 @@ //-------------------------------------------------------------------------------------------------- struct Rectangle { - uint32_t x_min; - uint32_t x_max; - uint32_t y_min; - uint32_t y_max; + int32_t x_min; + int32_t x_max; + int32_t y_min; + int32_t y_max; }; //-------------------------------------------------------------------------------------------------- @@ -21,19 +21,23 @@ public: png_writer_.set_all_pixels(255); } - uint32_t to_px(double x) { - return static_cast<uint32_t>(pix_per_mm_ * x); + int32_t to_px(double x) { + return static_cast<int32_t>(pix_per_mm_ * x); } - void set_pixel(uint32_t x, uint32_t y, uint8_t value = 255) { + void set_pixel(int32_t x, int32_t y, uint8_t value = 255) { png_writer_.set_pixel(x, height_px_ - y - 1, value); } - void draw_rectangle( - uint32_t x_min, uint32_t x_max, uint32_t y_min, uint32_t y_max, uint8_t value = 255 + void draw_int_rectangle( + int32_t x_min, int32_t x_max, int32_t y_min, int32_t y_max, uint8_t value = 255 ) { - for (uint32_t x = x_min; x <= x_max; ++x) { - for (uint32_t y = y_min; y <= y_max; ++y) { + x_min = std::max(0, x_min); + x_max = std::min(width_px_, x_max); + y_min = std::max(0, y_min); + y_max = std::min(height_px_, y_max); + for (int32_t x = x_min; x < x_max; ++x) { + for (int32_t y = y_min; y < y_max; ++y) { set_pixel(x, y, value); } } @@ -42,11 +46,11 @@ public: void draw_rectangle( double x_min, double x_max, double y_min, double y_max, uint8_t value = 255 ) { - draw_rectangle(to_px(x_min), to_px(x_max), to_px(y_min), to_px(y_max), value); + draw_int_rectangle(to_px(x_min), to_px(x_max), to_px(y_min), to_px(y_max), value); } void draw_rectangle(Rectangle const& r, uint8_t value = 255) { - draw_rectangle(r.x_min, r.x_max, r.y_min, r.y_max, value); + draw_int_rectangle(r.x_min, r.x_max, r.y_min, r.y_max, value); } void draw_pad(double x_min, double x_max, double y_min, double y_max) { @@ -66,9 +70,9 @@ public: double height_; double pix_per_mm_; double min_cut_thickness_; - uint32_t width_px_; - uint32_t height_px_; - uint32_t min_cut_thickness_px_; + int32_t width_px_; + int32_t height_px_; + int32_t min_cut_thickness_px_; }; //-------------------------------------------------------------------------------------------------- @@ -81,46 +85,69 @@ int main() { double pad_y_max; // board params - double const width = 6; + double const width = 6.6; double const height = 14; - double const ppmm = 50; - double const min_cut_thickness = 0.4; + double const ppmm = 50; // equivalent to 1270 ppi + double const min_cut_thickness = 0.38; + double const min_trace_thickness = 0.35; Board board(width, height, ppmm, min_cut_thickness); // SOIC dims - double const pad_width = 0.5; + double const pad_width = 0.6; double const pad_height = 2.4; //double const soic_width = 5; double const soic_height = 7; double const soic_pitch = 1.27; - // Draw the SOIC pads - double const soic_pos_x = 0.5 * (width - 3 * soic_pitch - pad_width); - double const soic_pos_y = 0.5 * (height - soic_height); - for (uint32_t i = 0; i < 4; ++i) { + // SOIC pads + double const soic_pos_x = min_trace_thickness + min_cut_thickness; + double const soic_btm_y = 0.5 * (height - soic_height); + double const soic_top_y = height - soic_btm_y; + for (int32_t i = 0; i < 4; ++i) { pad_x_min = soic_pos_x + i * soic_pitch; pad_x_max = pad_x_min + pad_width; - pad_y_min = soic_pos_y; - pad_y_max = pad_y_min + pad_height; - board.draw_pad(pad_x_min, pad_x_max, pad_y_min, pad_y_max); - pad_y_min = height - pad_y_max; - pad_y_max = pad_y_min + pad_height; - board.draw_pad(pad_x_min, pad_x_max, pad_y_min, pad_y_max); + pad_y_max = soic_btm_y + pad_height; + board.draw_pad(pad_x_min, pad_x_max, soic_btm_y, pad_y_max); + pad_y_min = soic_top_y - pad_height; + board.draw_pad(pad_x_min, pad_x_max, pad_y_min, soic_top_y); } - // Cable attachment dims - /* - double const cable_pad_height = 2.4; - pad_x_min = (width - 2 * min_cut_thickness) / 3; + // Data/VCC divider + pad_x_min += pad_width + min_cut_thickness + min_trace_thickness; pad_x_max = pad_x_min + min_cut_thickness; - pad_y_min = 0; - pad_y_max = pad_y_min + cable_pad_height; - for (uint32_t x = to_px(pad_x_min); x < to_px(pad_x_max); ++x) { - for (uint32_t y = to_px(pad_y_min); y < to_px(pad_y_max); ++y) { - set_pixel(x, y); - } - } - */ + pad_y_min = soic_btm_y - min_cut_thickness; + pad_y_max = soic_top_y + min_cut_thickness; + std::cout << "Power trace is " << width - pad_x_max << "mm\n"; + board.draw_rectangle(pad_x_min, pad_x_max, pad_y_min, pad_y_max, 0); + + // Ground/data divider + pad_x_min = min_trace_thickness; + pad_x_max = pad_x_min + min_cut_thickness; + board.draw_rectangle(pad_x_min, pad_x_max, soic_btm_y, soic_top_y, 0); + + // Ground pad links + pad_x_min += min_cut_thickness + 0.5 * (pad_width - min_trace_thickness); + pad_x_max = pad_x_min + min_trace_thickness; + pad_y_min = soic_btm_y - min_cut_thickness; + pad_y_max = soic_btm_y; + board.draw_rectangle(pad_x_min, pad_x_max, pad_y_min, pad_y_max, 255); + + // Data and power pad links + pad_y_min = soic_top_y - pad_height - min_cut_thickness; + pad_y_max = soic_top_y + min_cut_thickness; + board.draw_rectangle(pad_x_min, pad_x_max, pad_y_min, pad_y_max, 255); + pad_x_min += soic_pitch; + pad_x_max += soic_pitch; + board.draw_rectangle(pad_x_min, pad_x_max, pad_y_min, pad_y_max, 255); + + // Cable attachment dividers + double const cable_pad_width = (width - 2 * min_cut_thickness) / 3; + pad_x_min = cable_pad_width; + pad_x_max = pad_x_min + min_cut_thickness; + board.draw_rectangle(pad_x_min, pad_x_max, 0, soic_btm_y - min_cut_thickness, 0); + pad_x_min += cable_pad_width + min_cut_thickness; + pad_x_max = pad_x_min + min_cut_thickness; + board.draw_rectangle(pad_x_min, pad_x_max, 0, soic_btm_y - 2 * min_cut_thickness, 0); board.save("node_board_traces.png"); -- GitLab