~tristan957/tllt-cp

b641e5e72ab5748349f2a38fcac55ee01b2e34b3 — Tristan Partin 5 years ago b5ebdb5
Implement manual control of heating elements
4 files changed, 57 insertions(+), 37 deletions(-)

M data/ui/tllt-cp-window.ui
M driver/tllt-toaster.c
M driver/tllt-toaster.h
M src/tllt-cp-window.c
M data/ui/tllt-cp-window.ui => data/ui/tllt-cp-window.ui +18 -18
@@ 217,18 217,16 @@ Author: Tristan Partin
          </object>
        </child>
        <child>
          <object class="GtkMenuButton">
          <object class="GtkButton">
            <property name="label" translatable="yes">Login</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="popover">menu_popover</property>
            <child>
              <object class="GtkImage">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="icon_name">open-menu-symbolic</property>
              </object>
            </child>
            <property name="tooltip_text" translatable="yes">Login or create an account</property>
            <signal name="clicked" handler="on_login_button_clicked" object="TlltCpWindow" swapped="no"/>
            <style>
              <class name="suggested-action"/>
            </style>
          </object>
          <packing>
            <property name="pack_type">end</property>


@@ 236,16 234,18 @@ Author: Tristan Partin
          </packing>
        </child>
        <child>
          <object class="GtkButton">
            <property name="label" translatable="yes">Login</property>
          <object class="GtkMenuButton">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="tooltip_text" translatable="yes">Login or create an account</property>
            <signal name="clicked" handler="on_login_button_clicked" object="TlltCpWindow" swapped="no"/>
            <style>
              <class name="suggested-action"/>
            </style>
            <property name="popover">menu_popover</property>
            <child>
              <object class="GtkImage">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="icon_name">open-menu-symbolic</property>
              </object>
            </child>
          </object>
          <packing>
            <property name="pack_type">end</property>


@@ 636,7 636,7 @@ Author: Tristan Partin
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="active">True</property>
                        <signal name="state-set" handler="on_heating_element_swtich_state_set" object="TlltCpWindow" swapped="no"/>
                        <signal name="state-set" handler="on_heating_element_switch_state_set" object="TlltCpWindow" swapped="no"/>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>


@@ 648,7 648,7 @@ Author: Tristan Partin
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="active">True</property>
                        <signal name="state-set" handler="on_heating_element_swtich_state_set" object="TlltCpWindow" swapped="no"/>
                        <signal name="state-set" handler="on_heating_element_switch_state_set" object="TlltCpWindow" swapped="no"/>
                      </object>
                      <packing>
                        <property name="left_attach">1</property>

M driver/tllt-toaster.c => driver/tllt-toaster.c +20 -5
@@ 18,6 18,8 @@ typedef struct TlltToasterOperationArgs
	TlltToaster *toaster;
	int temperature;
	int total_time_seconds;
	gboolean top;
	gboolean bot;
	unsigned int ref_count;
	TlltToasterUpdateFunc update;
	gpointer user_data;


@@ 269,8 271,13 @@ control_toaster(gpointer user_data)
	case STATE_READ: {
		const double temp = tllt_sensor_read(TLLT_SENSOR(args->toaster->thermistor));
		if (temp < args->temperature) {
			tllt_powerable_on(TLLT_POWERABLE(args->toaster->top_heating_element));
			tllt_powerable_on(TLLT_POWERABLE(args->toaster->bottom_heating_element));
			if (args->top) {
				tllt_powerable_on(TLLT_POWERABLE(args->toaster->top_heating_element));
			}

			if (args->bot) {
				tllt_powerable_on(TLLT_POWERABLE(args->toaster->bottom_heating_element));
			}

			state = STATE_NO_READ;
		}


@@ 345,7 352,8 @@ prepare_toaster(gpointer user_data)

void
tllt_toaster_start(TlltToaster *self, const unsigned int time, const int temperature,
				   const TlltToasterUpdateFunc update, gpointer user_data)
				   const gboolean top, const gboolean bot, const TlltToasterUpdateFunc update,
				   gpointer user_data)
{
	TlltToasterPrivate *priv = tllt_toaster_get_instance_private(self);



@@ 358,13 366,20 @@ tllt_toaster_start(TlltToaster *self, const unsigned int time, const int tempera
	toaster_op_args->user_data			= user_data;
	toaster_op_args->toaster			= self;
	toaster_op_args->temperature		= temperature;
	toaster_op_args->top				= top;
	toaster_op_args->bot				= bot;
	toaster_op_args->ref_count			= 1;
	g_object_ref(self);

	const double temp = tllt_sensor_read(TLLT_SENSOR(self->thermistor));
	if (temp < temperature) {
		tllt_powerable_on(TLLT_POWERABLE(self->top_heating_element));
		tllt_powerable_on(TLLT_POWERABLE(self->bottom_heating_element));
		if (top) {
			tllt_powerable_on(TLLT_POWERABLE(self->top_heating_element));
		}

		if (bot) {
			tllt_powerable_on(TLLT_POWERABLE(self->bottom_heating_element));
		}
	} else {
		tllt_powerable_off(TLLT_POWERABLE(self->top_heating_element));
		tllt_powerable_off(TLLT_POWERABLE(self->bottom_heating_element));

M driver/tllt-toaster.h => driver/tllt-toaster.h +2 -1
@@ 23,7 23,8 @@ typedef void (*TlltToasterUpdateFunc)(unsigned int time, double progress, gpoint

TlltToaster *tllt_toaster_new_from_config_file(const char *file_path, GError **err);
void tllt_toaster_start(TlltToaster *self, const unsigned int time, const int temperature,
						const TlltToasterUpdateFunc update, gpointer user_data);
						gboolean top, gboolean bot, const TlltToasterUpdateFunc update,
						gpointer user_data);
void tllt_toaster_stop(TlltToaster *self);
gboolean tllt_toaster_is_running(TlltToaster *self);


M src/tllt-cp-window.c => src/tllt-cp-window.c +17 -13
@@ 205,7 205,8 @@ on_recipe_started(G_GNUC_UNUSED TlltCpRecipeListItem *list_item, TlltCpRecipe *r

	if (dto != NULL) {
		g_object_ref(self);
		tllt_toaster_start(priv->toaster, dto->time, dto->temperature, update_timer, self);
		tllt_toaster_start(priv->toaster, dto->time, dto->temperature, TRUE, TRUE, update_timer,
						   self);
	} else {
		priv->toaster_user			   = NULL;
		priv->currently_running_recipe = NULL;


@@ 298,7 299,7 @@ on_user_profiles_flow_box_child_activated(G_GNUC_UNUSED GtkFlowBox *widget, GtkF
}

static gboolean
on_heating_element_swtich_state_set(G_GNUC_UNUSED GtkSwitch *widget, G_GNUC_UNUSED gboolean state,
on_heating_element_switch_state_set(G_GNUC_UNUSED GtkSwitch *widget, G_GNUC_UNUSED gboolean state,
									gpointer user_data)
{
	TlltCpWindow *self		  = TLLT_CP_WINDOW(user_data);


@@ 322,21 323,15 @@ on_timer_start_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_dat
	TlltCpWindow *self		  = TLLT_CP_WINDOW(user_data);
	TlltCpWindowPrivate *priv = tllt_cp_window_get_instance_private(self);

	// Reset switches for next run
	if (!gtk_switch_get_active(priv->top_heating_element_switch)) {
		gtk_switch_set_active(priv->top_heating_element_switch, TRUE);
	}

	if (!gtk_switch_get_active(priv->bottom_heating_element_switch)) {
		gtk_switch_set_active(priv->top_heating_element_switch, TRUE);
	}

	const int minutes = gtk_spin_button_get_value_as_int(priv->timer_minutes_spin_button);
	const int seconds = gtk_spin_button_get_value_as_int(priv->timer_seconds_spin_button);

	g_object_ref(self);
	tllt_toaster_start(priv->toaster, minutes * 60 + seconds,
					   gtk_range_get_value(GTK_RANGE(priv->temperature_scale)), update_timer, self);
					   gtk_range_get_value(GTK_RANGE(priv->temperature_scale)),
					   gtk_switch_get_active(priv->top_heating_element_switch),
					   gtk_switch_get_active(priv->bottom_heating_element_switch), update_timer,
					   self);
}

static void


@@ 370,6 365,15 @@ on_toaster_stopped(G_GNUC_UNUSED TlltToaster *toaster, gpointer user_data)
		gtk_widget_destroy(GTK_WIDGET(dialog));
	}

	// Reset switches for next run
	if (!gtk_switch_get_active(priv->top_heating_element_switch)) {
		gtk_switch_set_active(priv->top_heating_element_switch, TRUE);
	}

	if (!gtk_switch_get_active(priv->bottom_heating_element_switch)) {
		gtk_switch_set_active(priv->top_heating_element_switch, TRUE);
	}

	priv->toaster_user			   = NULL;
	priv->currently_running_recipe = NULL;



@@ 488,7 492,7 @@ tllt_cp_window_class_init(TlltCpWindowClass *klass)
	gtk_widget_class_bind_template_callback(wid_class, on_timer_reset_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_toaster_stop_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_temperature_scale_format_value);
	gtk_widget_class_bind_template_callback(wid_class, on_heating_element_swtich_state_set);
	gtk_widget_class_bind_template_callback(wid_class, on_heating_element_switch_state_set);
}

static void