From: Lukáš Jiřiště Date: Mon, 19 Feb 2024 22:12:48 +0000 (+0100) Subject: Add indications for opening and closing FETs X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=2d2156eb7e380aab8d58892d6d356b5a99d5603c;p=FET_sim.git Add indications for opening and closing FETs --- diff --git a/inc/FET_sim.h b/inc/FET_sim.h index 285a7a2..6a6bccf 100644 --- a/inc/FET_sim.h +++ b/inc/FET_sim.h @@ -106,6 +106,7 @@ const char *state_color_escape(t_state state); void draw_single(t_vec *mosfets, size_t i); void update_nodes(t_vec *nodes); +int should_open(t_type type, t_state state); int sim_step(t_vec *nodes, t_vec *mosfets); void print_start(void); diff --git a/src/colors.c b/src/colors.c index 343ac73..060031e 100644 --- a/src/colors.c +++ b/src/colors.c @@ -37,10 +37,14 @@ void draw_single(t_vec *mosfets, size_t i) } if (mosfet->gate) { - if (!mosfet->is_opened) - ft_printf("%4u%s-%s%c-\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type); - else + if (mosfet->is_opened && should_open(mosfet->type, mosfet->gate->state)) ft_printf("%4u%s-%s%c%s|%s\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type, state_color_escape(mosfet->source->state), g_default_ac); + else if (should_open(mosfet->type, mosfet->gate->state)) + ft_printf("%4u%s-%s%c\\\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type); + else if (mosfet->is_opened) + ft_printf("%4u%s-%s%c%s\\%s\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type, state_color_escape(mosfet->source->state), g_default_ac); + else + ft_printf("%4u%s-%s%c-\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type); } else ft_printf("%sNULL--%s%c\n", g_red_ac, g_default_ac, mosfet->type); diff --git a/src/sim_main.c b/src/sim_main.c index 37929e6..54e35f2 100644 --- a/src/sim_main.c +++ b/src/sim_main.c @@ -1,23 +1,20 @@ #include "FET_sim.h" #include "libft.h" +int should_open(t_type type, t_state state) +{ + return ((type == p && state == on) || (type == n && state == off)); +} + // Maybe an error should be return when gate is NULL static void update_mosfet(t_mosfet *mosfet) { - t_state state; - if (!mosfet->gate) { mosfet->is_opened = 0; return ; } - state = mosfet->gate->state; - if (mosfet->type == p && state == on) - mosfet->is_opened = 1; - else if (mosfet->type == n && state == off) - mosfet->is_opened = 1; - else - mosfet->is_opened = 0; + mosfet->is_opened = should_open(mosfet->type, mosfet->gate->state); return ; } @@ -38,7 +35,7 @@ static void update_mosfets(t_vec *mosfets) int sim_step(t_vec *nodes, t_vec *mosfets) { - update_nodes(nodes); update_mosfets(mosfets); + update_nodes(nodes); return (1); }