コード例 #1
0
ファイル: SHT1x.cpp プロジェクト: lthiery/SHT1x
/**
 * Requests, reads, and parses temperatures in F
 */
float SHT1x::readTemperatureF()
{
  requestTemperature();
  return parseTemperatureF(readInTemperature());
}
コード例 #2
0
SerialConsole::SerialConsole(QWidget *parent) :
    QDockWidget(tr("Serial console"), parent)
{
	setObjectName("SerialConsole");

    extruder_temperature = 0.0;
    bed_temperature = 0.0;
    nb_processed_commands = 0;
    start_time.start();

    QWidget *widget = new QWidget;
    setWidget(widget);
    QVBoxLayout *layout = new QVBoxLayout;
    widget->setLayout(layout);

    QComboBox *serial_ports = new QComboBox;

	const QList<QSerialPortInfo> &available_ports = QSerialPortInfo::availablePorts();
	for(const QSerialPortInfo &port : available_ports)
    {
        serial_ports->addItem(QIcon::fromTheme("printer"), port.portName(), port.portName());
    }
    connect(serial_ports,SIGNAL(activated(QString)),this,SLOT(connectTo(QString)));

    QHBoxLayout *history_layout = new QHBoxLayout;
    scroll_bar = new QScrollBar(Qt::Vertical);
    scroll_bar->setMinimum(0);
    scroll_bar->setValue(0);
    history_layout->addWidget(history = new SimpleTextEdit);
	history->setMaxSize(10000);
    history_layout->addWidget(scroll_bar);
    connect(history,SIGNAL(scrollPositionChanged(int)),scroll_bar,SLOT(setValue(int)));
    connect(scroll_bar,SIGNAL(valueChanged(int)),history,SLOT(setScrollPosition(int)));
    connect(history,SIGNAL(maxScrollChanged(int)),this,SLOT(updateScrollBar(int)));

    layout->addWidget(serial_ports);
    layout->addLayout(history_layout);
    layout->addWidget(cmd = new QLineEdit);

    history->setFocusPolicy(Qt::NoFocus);
    cmd->setFocusPolicy(Qt::StrongFocus);

	rs232 = new QSerialPort(this);
	rs232->setBaudRate(115200);

    connect(rs232,SIGNAL(readyRead()),this,SLOT(readMessage()));
    connect(cmd,SIGNAL(returnPressed()),this,SLOT(sendMessage()));

    ack_timer = new QTimer(this);
    ack_timer->setSingleShot(true);
    ack_timer->setInterval(2000);
    connect(ack_timer,SIGNAL(timeout()),this,SLOT(kickAfterTimeout()));

    QTimer *timer = new QTimer(this);
    timer->setInterval(10000);
    timer->setSingleShot(false);
    connect(timer,SIGNAL(timeout()),this,SLOT(requestTemperature()));
    timer->start();

    ack_expected_before_sending_a_command = 0;
    b_paused = false;

    QSettings settings;
    settings.beginGroup("SerialConsole");
    const QString &serial_port = settings.value("serial_port", QString()).toString();
    settings.endGroup();

    int idx = 0;
	for(const QSerialPortInfo &port : available_ports)
        if (port.portName() == serial_port)
        {
            serial_ports->setCurrentIndex(idx);
            connectTo(serial_port);
            break;
        }
        else
            ++idx;
}
コード例 #3
0
ファイル: SHT1x.cpp プロジェクト: lthiery/SHT1x
/**
 * Requests, reads, and parses temperatures in C
 */
float SHT1x::readTemperatureC()
{
  //just putting together functions
  requestTemperature();
  return parseTemperatureC(readInTemperature());
}