Newer
Older
weather_station / hidwh1080rptparser.h
#if !defined(__HIDWH1080RPTPARSER_H__)
#define __HIDWH1080RPTPARSER_H__

#include <inttypes.h>
#include <avr/pgmspace.h>
#include "avrpins.h"
#include "max3421e.h"
#include "usbhost.h"
#include "usb_ch9.h"
#include "Usb.h"

#if defined(ARDUINO) && ARDUINO >=100
#include "Arduino.h"
#else
#include <WProgram.h>
#endif

#include "printhex.h"
#include "hexdump.h"
#include "message.h"
#include "confdescparser.h"
#include "hid.h"

// Following taken from wview-5.20.2
//
// Define the rain rate acuumulator period (minutes):
#define WH1080_RAIN_RATE_PERIOD         5

// Weather Station buffer parameters:
#define WH1080_RAIN_MAX             0x10000     // Wrap value for rain counter
#define WH1080_BUFFER_START         0x100       // Size of fixed block
                                                // start of buffer records
#define WH1080_BUFFER_CHUNK         0x20        // Size of chunk received over USB
// Weather Station record memory positions:
#define WH1080_DELAY                0   // Position of delay parameter
#define WH1080_HUMIDITY_IN          1   // Position of inside humidity parameter
#define WH1080_TEMPERATURE_IN       2   // Position of inside temperature parameter
#define WH1080_HUMIDITY_OUT         4   // Position of outside humidity parameter
#define WH1080_TEMPERATURE_OUT      5   // Position of outside temperature parameter
#define WH1080_ABS_PRESSURE         7   // Position of absolute pressure parameter
#define WH1080_WIND_AVE             9   // Position of wind direction parameter
#define WH1080_WIND_GUST            10  // Position of wind direction parameter
#define WH1080_WIND_DIR             12  // Position of wind direction parameter
#define WH1080_RAIN                 13  // Position of rain parameter
#define WH1080_STATUS               15  // Position of status parameter

// Control block offsets:
#define WH1080_SAMPLING_INTERVAL    16  // Position of sampling interval
#define WH1080_DATA_COUNT           27  // Position of data_count parameter
#define WH1080_CURRENT_POS          30  // Position of current_pos parameter

const prog_char WH1080_REPORT[] PROGMEM = {
  0xa1, 0x00, 0x00, 0x20, 0xa1, 0x00, 0x00, 0x20
};

class WH1080ReportParser : public HIDReportParser
{
  uint8_t chunk[WH1080_BUFFER_CHUNK], lastChunk[WH1080_BUFFER_CHUNK];
  uint8_t chunkStart;
  bool readingBlockZero;
  unsigned short currentPos;
  unsigned long lastMillis;
    
public:

  unsigned long startDelay;
  uint8_t report[8];

  WH1080ReportParser() {
    chunkStart = 0;
    readingBlockZero = true;
    for (uint8_t i = 0; i < sizeof(WH1080_REPORT); i++) {
      report[i] = pgm_read_byte(&WH1080_REPORT[i]);
    }
    memset(lastChunk, 0, WH1080_BUFFER_CHUNK);
    lastMillis = millis();
    startDelay = 1000 + millis();
  }

  virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif // __HIDWH1080RPTPARSER_H__