Created
May 9, 2015 03:15
-
-
Save dpkoch/aa6ed1e33919debf2023 to your computer and use it in GitHub Desktop.
Generates header symbol definitions for including in an EAGLE library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#define TRUE 1 | |
#define FALSE 0 | |
static const char SYMBOL_OPEN[] = "<symbol name=\"HEADER-%dPOS\">\n"; | |
static const char SYMBOL_CLOSE[] = "</symbol>\n"; | |
static const char PIN_STRING[] = "<pin name=\"P$%d\" x=\"%.2f\" y=\"%.2f\" visible=\"pad\" length=\"short\" function=\"dot\"/>\n"; | |
static const char WIRE_STRING[] = "<wire x1=\"%.2f\" y1=\"%.2f\" x2=\"%.2f\" y2=\"%.2f\" width=\"%.4f\" layer=\"%d\"/>\n"; | |
static const char NAME_STRING[] = "<text x=\"%.2f\" y=\"%.3f\" size=\"%.3f\" layer=\"%d\">>NAME</text>\n"; | |
static const char VALUE_STRING[] = "<text x=\"%.2f\" y=\"%.3f\" size=\"%.3f\" layer=\"%d\" align=\"top-left\">>VALUE</text>\n"; | |
static const float GRID = 2.54; | |
static const float PIN_X = -1.0; | |
static const float WIRE_X1 = -2.5; | |
static const float WIRE_X2 = 0.5; | |
static const float WIRE_WIDTH = 0.16; | |
static const int WIRE_LAYER = 94; | |
static const float TEXT_X = -2.5; | |
static const float TEXT_Y_OFFSET = 0.3; | |
static const float TEXT_SIZE = 0.7; | |
static const int NAME_LAYER = 95; | |
static const int VALUE_LAYER = 96; | |
void print_usage(char* command) | |
{ | |
printf("Usage: %s MIN MAX\n", command); | |
} | |
char isint(char* input) | |
{ | |
if (!(isdigit(input[0]) || input[0] == '-')) | |
return FALSE; | |
char* char_ptr; | |
for (char_ptr = input + 1; *char_ptr != '\0'; char_ptr++) | |
{ | |
if (!isdigit(*char_ptr)) | |
return FALSE; | |
} | |
return TRUE; | |
} | |
void print_pin(int num, int ypos) | |
{ | |
printf(PIN_STRING, num, PIN_X*GRID, ypos*GRID); | |
} | |
void print_wire(int pos) | |
{ | |
int y1 = (pos / 2) + 1; | |
int y2 = -((pos / 2) + (pos % 2) - 1) - 1;; | |
printf(WIRE_STRING, WIRE_X1*GRID, y1*GRID, WIRE_X1*GRID, y2*GRID, WIRE_WIDTH*GRID, WIRE_LAYER); | |
printf(WIRE_STRING, WIRE_X2*GRID, y1*GRID, WIRE_X2*GRID, y2*GRID, WIRE_WIDTH*GRID, WIRE_LAYER); | |
printf(WIRE_STRING, WIRE_X1*GRID, y1*GRID, WIRE_X2*GRID, y1*GRID, WIRE_WIDTH*GRID, WIRE_LAYER); | |
printf(WIRE_STRING, WIRE_X1*GRID, y2*GRID, WIRE_X2*GRID, y2*GRID, WIRE_WIDTH*GRID, WIRE_LAYER); | |
} | |
void print_text(int pos) | |
{ | |
float name_y = (pos / 2) + 1 + TEXT_Y_OFFSET; | |
float value_y = -((pos / 2) + (pos % 2) - 1) - 1 - TEXT_Y_OFFSET; | |
printf(NAME_STRING, TEXT_X*GRID, name_y*GRID, TEXT_SIZE*GRID, NAME_LAYER); | |
printf(VALUE_STRING, TEXT_X*GRID, value_y*GRID, TEXT_SIZE*GRID, VALUE_LAYER); | |
} | |
void print_symbol(int pos) | |
{ | |
printf(SYMBOL_OPEN, pos); | |
int i; | |
for (i = 0; i < pos; i++) | |
{ | |
print_pin(i + 1, pos / 2 - i); | |
} | |
print_wire(pos); | |
print_text(pos); | |
printf(SYMBOL_CLOSE); | |
} | |
int main(int argc, char** argv) | |
{ | |
if (argc != 3 || !isint(argv[1]) || !isint(argv[2])) | |
{ | |
print_usage(argv[0]); | |
return 0; | |
} | |
int min = atoi(argv[1]); | |
int max = atoi(argv[2]); | |
if (!(min >= 1 && max >= min)) | |
{ | |
printf("MIN and MAX must be integers >= 1 with MAX >= MIN\n"); | |
return 0; | |
} | |
int i; | |
for (i = min; i <= max; i++) | |
{ | |
print_symbol(i); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment