Newer
Older
weather_station / WeatherStation.ino

#include <avr/pgmspace.h>

#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <address.h>
#include <hid.h>
#include <hiduniversal.h>

#include <printhex.h>
#include <message.h>
#include <hexdump.h>
#include <parsetools.h>

#include "hidwh1080rptparser.h"

USB                                             Usb;
USBHub                                          Hub(&Usb);
HIDUniversal                                    Hid(&Usb);

WH1080ReportParser parser;

void setup()
{
  Serial.begin( 9600 );
  Serial.println("Start");

  if (Usb.Init() == -1)
      Serial.println("OSC did not start.");
      
  delay( 200 );

  if (!Hid.SetReportParser(0, &parser))
      ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1  ); 
}

void loop()
{
    Usb.Task();
    if ((Usb.getUsbTaskState() == USB_STATE_RUNNING) && parser.startDelay && (parser.startDelay <= millis())) {
      int rcode = Hid.SetReport(0, 0, 0x02, 0x01, sizeof(parser.report), parser.report);
      if (rcode != 0) {
        Serial.print("Rcode = ");
        Serial.println(rcode, HEX);
      }
      parser.startDelay = 0;
    }
}