def arduino(): ''' Configure now settings for the arduino. ''' sform = UpdateSetpointForm() uform = UpdateForm() wform = SerialWaitForm() dform = DisconnectForm() gform = UpdateGainForm() iform = UpdateIntegralForm() diff_form = UpdateDifferentialForm() id = int(sform.id.data) arduino = TempControl.query.get(id) if sform.validate_on_submit(): arduino.setpoint = sform.setpoint.data db.session.commit() success = arduino.set_setpoint() if success: flash('We set the setpoint to {}'.format(sform.setpoint.data)) else: flash('Serial port not open.', 'error') return redirect(url_for('thermocontrol.change_arduino', ard_nr=id)) else: return render_template('change_arduino.html', form=uform, dform=dform, sform=sform, gform=gform, iform=iform, diff_form=diff_form, wform=wform, ard=arduino)
def serialwait(): ''' Update the serial waiting time. ''' sform = UpdateSetpointForm() uform = UpdateForm() wform = SerialWaitForm() dform = DisconnectForm() gform = UpdateGainForm() iform = UpdateIntegralForm() diff_form = UpdateDifferentialForm() id = int(wform.id.data) arduino = TempControl.query.get(id) if wform.validate_on_submit(): n_wait = wform.serial_time.data arduino.sleeptime = n_wait db.session.commit() flash('We update every {} s'.format(n_wait)) return redirect(url_for('thermocontrol.change_arduino', ard_nr=id)) else: return render_template('change_arduino.html', form=uform, dform=dform, cform=cform, sform=sform, gform=gform, iform=iform, diff_form=diff_form, wform=wform, ard=arduino)
def change_arduino(ard_nr): ''' Change the parameters of a specific arduino ''' arduino = TempControl.query.get(ard_nr) if not arduino: flash('No tempcontrols installed', 'error') return redirect(url_for('thermocontrol.add_tempcontrol')) uform = UpdateForm(id=ard_nr) sform = UpdateSetpointForm(id=ard_nr) gform = UpdateGainForm(id=ard_nr) iform = UpdateIntegralForm(id=ard_nr) diff_form = UpdateDifferentialForm(id=ard_nr) wform = SerialWaitForm(id=ard_nr) dform = DisconnectForm(id=ard_nr) return render_template('change_arduino.html', form=uform, dform=dform, sform=sform, gform=gform, iform=iform, diff_form=diff_form, wform=wform, ard=arduino)
def update_tc(): ''' Update the serial port. ''' sform = UpdateSetpointForm() uform = UpdateForm() wform = SerialWaitForm() dform = DisconnectForm() gform = UpdateGainForm() iform = UpdateIntegralForm() diff_form = UpdateDifferentialForm() id = int(uform.id.data) arduino = TempControl.query.get(id) if uform.validate_on_submit(): n_port = uform.serial_port.data try: if arduino.connection_open(): arduino.stop() arduino.update_serial(n_port) if arduino.is_open(): flash('We updated the serial to {}'.format(n_port)) else: flash('Update of the serial port went wrong.', 'error') except Exception as e: flash('{}'.format(e), 'error') return redirect(url_for('thermocontrol.change_arduino', ard_nr=id)) else: return render_template('change_arduino.html', form=uform, dform=dform, cform=cform, sform=sform, gform=gform, iform=iform, diff_form=diff_form, wform=wform, ard=arduino)
def diff(): ''' Configure the new gain for the arduino. ''' sform = UpdateSetpointForm() uform = UpdateForm() wform = SerialWaitForm() dform = DisconnectForm() gform = UpdateGainForm() iform = UpdateIntegralForm() diff_form = UpdateDifferentialForm() id = int(diff_form.id.data) arduino = TempControl.query.get(id) if diff_form.validate_on_submit(): n_tau = diff_form.tau.data arduino.diff = n_tau db.session.commit() success = arduino.set_differential() if success: flash( 'We set the differentiation time to {} seconds'.format(n_tau)) else: flash('Serial port not open.', 'error') return redirect(url_for('thermocontrol.change_arduino', ard_nr=id)) else: return render_template('change_arduino.html', form=uform, dform=dform, sform=sform, gform=gform, iform=iform, diff_form=diff_form, wform=wform, ard=arduino)