#include<cairo/cairo.h>
#include"ses_core.h"
+#define SHOW_BITS 1000000.0
+
static void ses_text_a(cairo_t* cr, int x, int y, double a)
{
char text[64];
cairo_set_source_rgb(cr, 0.0, 0.0, 0.7);
if (a > 1e-1 || a < -1e-1) {
- snprintf(text, sizeof(text) - 1, "%lgA", (int)(a * 1000) / 1000.0);
+ snprintf(text, sizeof(text) - 1, "%lgA", (int64_t)(a * SHOW_BITS) / SHOW_BITS);
cairo_move_to (cr, x, y);
cairo_show_text(cr, text);
} else if (a > 1e-5 || a < -1e-5) {
- snprintf(text, sizeof(text) - 1, "%lgmA", (int)(a * 1000000) / 1000.0);
+ snprintf(text, sizeof(text) - 1, "%lgmA", (int64_t)(a * 1000.0 * SHOW_BITS) / SHOW_BITS);
cairo_move_to (cr, x, y);
cairo_show_text(cr, text);
} else if (a > 1e-9 || a < -1e-9) {
- snprintf(text, sizeof(text) - 1, "%lguA", (int64_t)(a * 1000000000LL) / 1000.0);
+ snprintf(text, sizeof(text) - 1, "%lguA", (int64_t)(a * 1000000.0 * SHOW_BITS) / SHOW_BITS);
cairo_move_to (cr, x, y);
cairo_show_text(cr, text);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.7);
if (v > 1e-1 || v < -1e-1) {
- snprintf(text, sizeof(text) - 1, "%lgv", (int)(v * 1000) / 1000.0);
+ snprintf(text, sizeof(text) - 1, "%lgv", (int64_t)(v * SHOW_BITS) / SHOW_BITS);
cairo_move_to (cr, x, y);
cairo_show_text(cr, text);
} else if (v > 1e-5 || v < -1e-5) {
- snprintf(text, sizeof(text) - 1, "%lgmV", (int)(v * 1000000) / 1000.0);
+ snprintf(text, sizeof(text) - 1, "%lgmV", (int64_t)(v * 1000.0 * SHOW_BITS) / SHOW_BITS);
cairo_move_to (cr, x, y);
cairo_show_text(cr, text);
} else if (v > 1e-9 || v < -1e-9) {
- snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(v * 1000000000LL) / 1000.0);
+ snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(v * 1000000.0 * SHOW_BITS) / SHOW_BITS);
cairo_move_to (cr, x, y);
cairo_show_text(cr, text);
ses_text_a(cr, c->x + 10, c->y + 25, c->a);
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
- if (c->r > 1e6)
- snprintf(text, sizeof(text) - 1, "%lgM", (int)(c->r / 10000) / 100.0);
- else if (c->r > 999)
- snprintf(text, sizeof(text) - 1, "%lgk", (int)(c->r / 10) / 100.0);
+ if (c->r + c->dr > 1e6)
+ snprintf(text, sizeof(text) - 1, "%lgM", (int64_t)(c->r + c->dr) / 1000.0);
+ else if (c->r + c->dr > 999)
+ snprintf(text, sizeof(text) - 1, "%lgk", (int64_t)((c->r + c->dr) * 1000.0) / 1000000.0);
else
- snprintf(text, sizeof(text) - 1, "%dΩ", (int)c->r);
+ snprintf(text, sizeof(text) - 1, "%lgΩ", (int64_t)((c->r + c->dr) * 1000.0) / 1000.0);
cairo_move_to (cr, c->x + 4, c->y - 5);
cairo_show_text(cr, text);
}
}
-int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
+int ses_simplify_draw(ScfEfunction* f, const char* file, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh, int64_t ns, int64_t count)
{
ScfEcomponent* B;
ScfEcomponent* c;
cairo_fill(cr);
cairo_stroke(cr);
+ cairo_select_font_face(cr, "Calibri", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+ cairo_set_font_size(cr, 20);
+ cairo_set_source_rgb(cr, 0, 0, 0);
+
+ int64_t t = ns * count;
+ int64_t s = t / 1000000000;
+ t %= 1000000000;
+ int64_t ms = t / 1000000;
+ t %= 1000000;
+ int64_t us = t / 1000;
+ t %= 1000;
+
+ uint8_t time[512];
+ snprintf(time, sizeof(time) - 1, "%ld,%ld,%ld,%ldns", s, ms, us, t);
+ cairo_move_to (cr, 10, 20);
+ cairo_show_text(cr, time);
+ cairo_stroke(cr);
+
long i;
long j;
long k;
n = snprintf(text, sizeof(text) - 1, "%lgv", B->pins[SCF_EDA_Battery_POS]->v);
else if (el->v > 1e-2 || el->v < -1e-2)
- n = snprintf(text, sizeof(text) - 1, "%lgv", (int)(el->v * 1000) / 1000.0);
+ n = snprintf(text, sizeof(text) - 1, "%lgv", (int64_t)(el->v * SHOW_BITS) / SHOW_BITS);
else if (el->v > 1e-5 || el->v < -1e-5)
- n = snprintf(text, sizeof(text) - 1, "%lgmV", (int)(el->v * 1000000) / 1000.0);
+ n = snprintf(text, sizeof(text) - 1, "%lgmV", (int64_t)(el->v * 1000.0 * SHOW_BITS) / SHOW_BITS);
else
- n = snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(el->v * 1000000000LL) / 1000.0);
+ n = snprintf(text, sizeof(text) - 1, "%lguV", (int64_t)(el->v * 1000000.0 * SHOW_BITS) / SHOW_BITS);
// A of line
if (el->aout > 1e-1 || el->aout < -1e-1)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgA", (int)(el->aout * 1000) / 1000.0);
+ n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgA", (int64_t)(el->aout * SHOW_BITS) / SHOW_BITS);
else if (el->aout > 1e-5 || el->aout < -1e-5)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgmA", (int)(el->aout * 1000000) / 1000.0);
+ n += snprintf(text + n, sizeof(text) - 1 - n, ", %lgmA", (int64_t)(el->aout * 1000.0 * SHOW_BITS) / SHOW_BITS);
else
- n += snprintf(text + n, sizeof(text) - 1 - n, ", %lguA", (int64_t)(el->aout * 1000000000LL) / 1000.0);
+ n += snprintf(text + n, sizeof(text) - 1 - n, ", %lguA", (int64_t)(el->aout * 1000000.0 * SHOW_BITS) / SHOW_BITS);
if (el->ain > 1e-1 || el->ain < -1e-1)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgA", (int)(el->ain * 1000) / 1000.0);
+ n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgA", (int64_t)(el->ain * SHOW_BITS) / SHOW_BITS);
else if (el->ain > 1e-5 || el->ain < -1e-5)
- n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgmA", (int)(el->ain * 1000000) / 1000.0);
+ n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lgmA", (int64_t)(el->ain * 1000.0 * SHOW_BITS) / SHOW_BITS);
else
- n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lguA", (int64_t)(el->ain * 1000000000LL) / 1000.0);
+ n += snprintf(text + n, sizeof(text) - 1 - n, ", in %lguA", (int64_t)(el->ain * 1000000.0 * SHOW_BITS) / SHOW_BITS);
int cx = INT_MAX;
int cy = l->y0;
static int _simplify_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
{
- ScfEline* el;
+ static int64_t i = 0;
- int i;
-#if 0
- for (i = 0; i < f->n_elines; i++) {
- el = f->elines[i];
-
- if (el->flags & SCF_EDA_PIN_OUT) {
- if (el->v < 1)
- return 0;
- else
- break;
- }
- }
+ char file[128];
+ snprintf(file, sizeof(file) - 1, "./simplify_%ld.png", i);
+#if 1
+ if (count < 60 * 1000)
+ return 0;
#endif
- char file[128];
- snprintf(file, sizeof(file) - 1, "./simplify_%ld.png", count);
+ if (count % 10 == 0) {
+#if 1
+ static FILE* fp = NULL;
+ if (!fp)
+ fp = fopen("v.txt", "w");
+
+ if (fp)
+ fprintf(fp, "%ld, %lg\n", i, f->elines[4]->v);
+#endif
+// ses_simplify_draw(f, file, f->x, f->y, f->w, f->h, ns, count);
+ i++;
+ }
-// if (count % 100 < 5)
- ses_simplify_draw(f, file, f->x, f->y, f->w, f->h);
return 0;
}
--- /dev/null
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#include"ses_core.h"
+
+int main(int argc, char* argv[])
+{
+ ScfEcomponent* B;
+
+ ScfEcomponent* R0;
+ ScfEcomponent* T0;
+ ScfEcomponent* R1;
+ ScfEcomponent* R2;
+
+ ScfEfunction* f;
+ ScfEboard* b;
+
+ b = scf_eboard__alloc();
+ f = scf_efunction__alloc("sin_oscillator");
+
+ EDA_INST_ADD_COMPONENT(f, B, SCF_EDA_Battery);
+
+ B->pins[SCF_EDA_Battery_NEG]->flags = SCF_EDA_PIN_NEG;
+ B->pins[SCF_EDA_Battery_POS]->flags = SCF_EDA_PIN_POS;
+
+ EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor);
+ EDA_INST_ADD_COMPONENT(f, T0, SCF_EDA_NPN);
+ EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor);
+ EDA_INST_ADD_COMPONENT(f, R2, SCF_EDA_Resistor);
+
+ EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, R0, 1);
+ EDA_PIN_ADD_PIN(B, SCF_EDA_Battery_POS, R1, 1);
+
+ EDA_PIN_ADD_PIN(R0, 0, T0, SCF_EDA_NPN_B);
+ EDA_PIN_ADD_PIN(R1, 0, T0, SCF_EDA_NPN_C);
+ EDA_PIN_ADD_PIN(T0, SCF_EDA_NPN_E, R2, 1);
+ EDA_PIN_ADD_PIN(R2, 0, B, SCF_EDA_Battery_NEG);
+
+ T0->pins[SCF_EDA_NPN_C]->flags |= SCF_EDA_PIN_OUT;
+ T0->pins[SCF_EDA_NPN_C]->hfe = 80;
+
+ R0->r = 1000 * 10;
+ R1->r = 1000;
+ R2->r = 100;
+
+ scf_eboard__add_function(b, f);
+
+ int len = 0;
+ uint8_t* buf = NULL;
+
+ ScfEboard_pack(b, &buf, &len);
+ ScfEboard_free(b);
+ b = NULL;
+
+ FILE* fp = fopen("./test.cpk", "wb");
+ if (!fp)
+ return -EINVAL;
+
+ fwrite(buf, len, 1, fp);
+ fclose(fp);
+
+ return 0;
+}