Skip to content
Snippets Groups Projects
Commit b791e9ab authored by Erik Strand's avatar Erik Strand
Browse files

Start drawing traces

parent 882fb2a2
Branches
No related tags found
No related merge requests found
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
struct Rectangle { struct Rectangle {
uint32_t x_min; int32_t x_min;
uint32_t x_max; int32_t x_max;
uint32_t y_min; int32_t y_min;
uint32_t y_max; int32_t y_max;
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
...@@ -21,19 +21,23 @@ public: ...@@ -21,19 +21,23 @@ public:
png_writer_.set_all_pixels(255); png_writer_.set_all_pixels(255);
} }
uint32_t to_px(double x) { int32_t to_px(double x) {
return static_cast<uint32_t>(pix_per_mm_ * 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); png_writer_.set_pixel(x, height_px_ - y - 1, value);
} }
void draw_rectangle( void draw_int_rectangle(
uint32_t x_min, uint32_t x_max, uint32_t y_min, uint32_t y_max, uint8_t value = 255 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) { x_min = std::max(0, x_min);
for (uint32_t y = y_min; y <= y_max; ++y) { 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); set_pixel(x, y, value);
} }
} }
...@@ -42,11 +46,11 @@ public: ...@@ -42,11 +46,11 @@ public:
void draw_rectangle( void draw_rectangle(
double x_min, double x_max, double y_min, double y_max, uint8_t value = 255 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) { 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) { void draw_pad(double x_min, double x_max, double y_min, double y_max) {
...@@ -66,9 +70,9 @@ public: ...@@ -66,9 +70,9 @@ public:
double height_; double height_;
double pix_per_mm_; double pix_per_mm_;
double min_cut_thickness_; double min_cut_thickness_;
uint32_t width_px_; int32_t width_px_;
uint32_t height_px_; int32_t height_px_;
uint32_t min_cut_thickness_px_; int32_t min_cut_thickness_px_;
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
...@@ -81,46 +85,69 @@ int main() { ...@@ -81,46 +85,69 @@ int main() {
double pad_y_max; double pad_y_max;
// board params // board params
double const width = 6; double const width = 6.6;
double const height = 14; double const height = 14;
double const ppmm = 50; double const ppmm = 50; // equivalent to 1270 ppi
double const min_cut_thickness = 0.4; double const min_cut_thickness = 0.38;
double const min_trace_thickness = 0.35;
Board board(width, height, ppmm, min_cut_thickness); Board board(width, height, ppmm, min_cut_thickness);
// SOIC dims // SOIC dims
double const pad_width = 0.5; double const pad_width = 0.6;
double const pad_height = 2.4; double const pad_height = 2.4;
//double const soic_width = 5; //double const soic_width = 5;
double const soic_height = 7; double const soic_height = 7;
double const soic_pitch = 1.27; double const soic_pitch = 1.27;
// Draw the SOIC pads // SOIC pads
double const soic_pos_x = 0.5 * (width - 3 * soic_pitch - pad_width); double const soic_pos_x = min_trace_thickness + min_cut_thickness;
double const soic_pos_y = 0.5 * (height - soic_height); double const soic_btm_y = 0.5 * (height - soic_height);
for (uint32_t i = 0; i < 4; ++i) { 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_min = soic_pos_x + i * soic_pitch;
pad_x_max = pad_x_min + pad_width; pad_x_max = pad_x_min + pad_width;
pad_y_min = soic_pos_y; pad_y_max = soic_btm_y + pad_height;
pad_y_max = pad_y_min + pad_height; board.draw_pad(pad_x_min, pad_x_max, soic_btm_y, pad_y_max);
board.draw_pad(pad_x_min, pad_x_max, pad_y_min, pad_y_max); pad_y_min = soic_top_y - pad_height;
pad_y_min = height - pad_y_max; board.draw_pad(pad_x_min, pad_x_max, pad_y_min, soic_top_y);
pad_y_max = pad_y_min + pad_height;
board.draw_pad(pad_x_min, pad_x_max, pad_y_min, pad_y_max);
} }
// Cable attachment dims // Data/VCC divider
/* pad_x_min += pad_width + min_cut_thickness + min_trace_thickness;
double const cable_pad_height = 2.4;
pad_x_min = (width - 2 * min_cut_thickness) / 3;
pad_x_max = pad_x_min + min_cut_thickness; pad_x_max = pad_x_min + min_cut_thickness;
pad_y_min = 0; pad_y_min = soic_btm_y - min_cut_thickness;
pad_y_max = pad_y_min + cable_pad_height; pad_y_max = soic_top_y + min_cut_thickness;
for (uint32_t x = to_px(pad_x_min); x < to_px(pad_x_max); ++x) { std::cout << "Power trace is " << width - pad_x_max << "mm\n";
for (uint32_t y = to_px(pad_y_min); y < to_px(pad_y_max); ++y) { board.draw_rectangle(pad_x_min, pad_x_max, pad_y_min, pad_y_max, 0);
set_pixel(x, y);
} // 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"); board.save("node_board_traces.png");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment