示例#1
0
int main(void){
  HIDInterface* hid;
  hid_return ret;
  HIDInterfaceMatcher matcher = { VENDOR, PRODUCT, NULL, NULL, 0 };
  char packet[PACKET_LEN];

  hid_set_debug(HID_DEBUG_NONE);
  hid_set_debug_stream(stderr);
  hid_set_usb_debug(0);
  
  hid_init();
  hid = hid_new_HIDInterface();
  ret = hid_force_open(hid, 0, &matcher, 3);

  if (ret == HID_RET_FAIL_DETACH_DRIVER) {
      printf("Failed to detach Driver for Device %04x:%04x; Permission?\n", VENDOR, PRODUCT);
      return 1;
  }

  if (ret != HID_RET_SUCCESS) {
      printf("Could not open HID device %04x:%04x (ret was %d)\n", VENDOR, PRODUCT, ret);
      return 1;
  }

  // printf("hid_force_open ret=%d\n", ret);

  // hid_set_idle(hid,0,0);

  // Discard till first '\n'
  do {
    memset(packet,0,sizeof(packet));
    ret = hid_interrupt_read(hid,0x81,packet,PACKET_LEN,1000);
  } while (getTheChar(packet[1]) != '\n');

  while (1) {
    memset(packet,0,sizeof(packet));

    ret = hid_interrupt_read(hid,0x81,packet,PACKET_LEN,1000);

    /*
    if (ret == HID_RET_FAIL_INT_READ) {
        printf("Fail hid_interrupt_read\n");
    } else {
        printf("hid_interrupt_read ret=%d\n", ret);
    }
    */

    if( ret == HID_RET_SUCCESS ) {
      //printPacket(packet,PACKET_LEN);
      showTemperature(packet);
    }
  }

  hid_close(hid);
  hid_delete_HIDInterface(&hid);
  hid_cleanup();
  return 0;
}
示例#2
0
void Lcd::showValues() {
  showHumidity();
  showTemperature();
  showCo2();
}
DiagramWidget::DiagramWidget(QWidget *parent) :
    QWidget(parent)
{
    tableWidget=new QTableWidget();
    QStringList list;
    list.append(tr("Type"));
    list.append(tr("Record Date"));
    list.append(tr("Time"));
    list.append(tr("Selected Value"));
    list.append(tr("Unit"));
    list.append(tr("Maximum Value"));
    list.append(tr("Minimum Value"));
    list.append(tr("Average Value"));
    list.append(tr("Upper Limit"));
    list.append(tr("Lower Limit"));
    list.append(tr("Number"));
    tableWidget->setColumnCount(11);
    tableWidget->setRowCount(2);
    tableWidget->setHorizontalHeaderLabels(list);
    tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

    tableWidget->setItem(0,0,new QTableWidgetItem(tr("Temperature")));
    tableWidget->setItem(1,0,new QTableWidgetItem(tr("Humidity")));
    tableWidget->setItem(0,4,new QTableWidgetItem("°C"));
    tableWidget->setItem(1,4,new QTableWidgetItem("%RH"));

    bigAct=new QAction(QIcon(":/png/png/big"),"",0);
    smallAct=new QAction(QIcon(":/png/png/small"),"",0);
    reductionAct=new QAction(QIcon(":/png/png/back"),"",0);
    radioRB1=new QRadioButton(tr("Temperature+Humidity"));
    radioRB2=new QRadioButton(tr("Temperature"));
    radioRB3=new QRadioButton(tr("Humidity"));
    radioRB1->setChecked(true);
    bigAct->setToolTip(tr("curves zoom out"));
    smallAct->setToolTip(tr("curves zoom in"));
    reductionAct->setText(tr("Rstore"));

    QToolBar *toolBar=new QToolBar();
    toolBar->addSeparator();
    toolBar->addAction(bigAct);
    toolBar->addAction(smallAct);
    toolBar->addAction(reductionAct);
    toolBar->addSeparator();
    toolBar->addWidget(radioRB1);
    toolBar->addWidget(radioRB2);
    toolBar->addWidget(radioRB3);

    customPlot=new QCustomPlot();
    customPlot->legend->setVisible(true);
    customPlot->legend->setIconSize(10,5);
    customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignLeft);
    customPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom);
    customPlot->addGraph();
    customPlot->addGraph();
    customPlot->addGraph();
    customPlot->addGraph();
    customPlot->addGraph();
    customPlot->addGraph();
    customPlot->addGraph();
    customPlot->graph(0)->setName(tr("Temperature"));
    customPlot->graph(1)->setName(tr("Humidity"));
    QPen pen;
    pen.setWidth(2);
    pen.setColor(QColor(0,0,255));
    customPlot->graph(0)->setPen(pen);
    pen.setColor(QColor(0,128,0));
    customPlot->graph(1)->setPen(pen);
    pen.setColor(QColor(128,64,0));
    pen.setWidth(1);
    customPlot->graph(2)->setPen(pen);
    pen.setColor(QColor(255,0,0));
    pen.setStyle(Qt::DashLine);
    customPlot->graph(3)->setPen(pen);
    customPlot->graph(4)->setPen(pen);
    pen.setColor(QColor(255,0,255));
    customPlot->graph(5)->setPen(pen);
    customPlot->graph(6)->setPen(pen);
//    customPlot->graph(2)->setVisible(false);
    customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    QString format=QString("%1\n%2").arg(_dateFormat).arg(_timeFormat);
    customPlot->xAxis->setDateTimeFormat(format);
    customPlot->xAxis->setAutoTickStep(false);
    customPlot->legend->removeAt(2);
    customPlot->legend->removeAt(3);
    customPlot->legend->removeAt(4);
    customPlot->legend->removeAt(5);
    customPlot->legend->removeAt(6);

    QVBoxLayout *hLayout=new QVBoxLayout(this);
    hLayout->addWidget(toolBar);
    hLayout->addWidget(customPlot,5);
    hLayout->addWidget(tableWidget,1);


    //信号/槽
    connect(reductionAct,SIGNAL(triggered()),this,SLOT(reduction()));
    connect(customPlot,SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mousemoved(QMouseEvent*)));
    connect(customPlot,SIGNAL(mousePress(QMouseEvent*)),this,SLOT(mousePress(QMouseEvent*)));
    connect(radioRB1,SIGNAL(clicked()),this,SLOT(showAll()));
    connect(radioRB2,SIGNAL(clicked()),this,SLOT(showTemperature()));
    connect(radioRB3,SIGNAL(clicked()),this,SLOT(showHumidity()));
    connect(bigAct,SIGNAL(triggered()),this,SLOT(bigAct_trogged()));
    connect(smallAct,SIGNAL(triggered()),this,SLOT(smallAct_trogged()));
}