46 m_hidHandle =
nullptr;
52 return "HiTech Weather";
60 LOG_ERROR(
"Failed to initialize HID library");
65 m_hidHandle =
hid_open(HITECH_VID, HITECH_PID,
nullptr);
68 LOGF_ERROR(
"Unable to open HiTech Weather device (VID: 0x%04X, PID: 0x%04X). "
69 "Please check device is connected and permissions are correct.",
70 HITECH_VID, HITECH_PID);
79 char manufacturer[256];
80 wcstombs(manufacturer, wstr, 256);
81 LOGF_INFO(
"Manufacturer: %s", manufacturer);
87 wcstombs(product, wstr, 256);
91 LOG_INFO(
"HiTech Weather connected successfully");
100 m_hidHandle =
nullptr;
104 LOG_INFO(
"HiTech Weather disconnected");
113 addParameter(
"WEATHER_TEMPERATURE",
"Temperature (C)", -30, 50, 15);
116 addParameter(
"WEATHER_SKY_TEMPERATURE",
"Sky Temp (C)", -50, 30, 15);
120 addParameter(
"WEATHER_CLOUD_COVER",
"Clouds (%)", 0, 100, 15);
130 double ambientTemp = 0;
133 if (!getSkyTemperature(skyTemp))
135 LOG_ERROR(
"Failed to read sky temperature");
140 if (!getAmbientTemperature(ambientTemp))
142 LOG_ERROR(
"Failed to read ambient temperature");
147 double cloudCover = calculateCloudCover(ambientTemp, skyTemp);
154 LOGF_DEBUG(
"Sky: %.2f°C, Ambient: %.2f°C, Cloud Cover: %.1f%%",
155 skyTemp, ambientTemp, cloudCover);
160bool HitechWeather::getSkyTemperature(
double &skyTemp)
166 unsigned char cmd[8] = {CMD_GET_SKY_TEMP, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
177 unsigned char buf[8];
187 LOGF_ERROR(
"Insufficient data received for getSkyTemp: %d bytes", res);
194 LOGF_ERROR(
"Invalid getSkyTemp response signature: 0x%02X", buf[2]);
200 uint16_t rawTemp = (buf[0] * 256) + buf[1];
201 skyTemp = (rawTemp * 0.02) - 273.7;
206bool HitechWeather::getAmbientTemperature(
double &ambientTemp)
212 unsigned char cmd[8] = {CMD_GET_AMBIENT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
223 unsigned char buf[8];
233 LOGF_ERROR(
"Insufficient data received for getAmb: %d bytes", res);
238 if (buf[0] != 0x64 || buf[4] != 0x21)
240 LOGF_ERROR(
"Invalid getAmb response signature: 0x%02X 0x%02X", buf[0], buf[4]);
247 uint16_t rawTemp = (buf[2] * 256) + buf[1];
248 ambientTemp = rawTemp / 100.0;
258double HitechWeather::calculateCloudCover(
double ambientTemp,
double skyTemp)
261 double hitecDelta = ambientTemp - skyTemp;
262 double absDelta = std::abs(hitecDelta);
268 double cloudCover = 100.0 * (1.0 - std::min(absDelta, 22.0) / 22.0);
271 cloudCover = std::max(0.0, std::min(100.0, cloudCover));
bool Disconnect() override
Disconnect from device.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
const char * getDefaultName() override
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
void addDebugControl()
Add Debug control to the driver.
void addParameter(std::string name, std::string label, double numMinOk, double numMaxOk, double percWarning, bool flipWarning=false)
Add a physical weather measurable parameter to the weather driver.
bool setCriticalParameter(std::string name)
setCriticalParameter Set parameter that is considered critical to the operation of the observatory....
void setParameterValue(std::string name, double value)
setParameterValue Update weather parameter value
void setWeatherConnection(const uint8_t &value)
setWeatherConnection Set Weather connection mode. Child class should call this in the constructor bef...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
hid_device * hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number.
int HID_API_EXPORT hid_init(void)
Initialize the HIDAPI library.
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
Read an Input report from a HID device with timeout.
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
Write an Output report to a HID device.
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Product String from a HID device.
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
Get The Manufacturer String from a HID device.
void HID_API_EXPORT hid_close(hid_device *dev)
Close a HID device.
HID_API_EXPORT const wchar_t *HID_API_CALL hid_error(hid_device *dev)
Get a string describing the last error which occurred.
int HID_API_EXPORT hid_exit(void)
Finalize the HIDAPI library.
std::unique_ptr< HitechWeather > hitechWeather(new HitechWeather())
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)