Skip to content

Commit

Permalink
Windspeed
Browse files Browse the repository at this point in the history
  • Loading branch information
iachievedit committed Oct 12, 2024
1 parent a5bfc0c commit 30d8544
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 96 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ For what it's worth, I'm not the only one traumatized by the demise of the Weath

Around September 7, 2022, individuals across the country began reporting their WeatherFX units had come back to life. Indeed, mine did as well. Occasionally the clock will be behind an hour and the current temperature will be wildly incorrect, so I think we'll keep working on this project!

**2024-10-12 Update**
My Bushnell WeatherFX continues to update, though it occasionally goes "offline" for a day or two.

## Hardware

Expand Down Expand Up @@ -59,6 +61,7 @@ Once you have your key and Apple Developer account information, create `config.h
```
// WeatherKit
// LATLNG is LAT/LNG for your location
// #define METRIC
#define LATLNG "32.7767/-96.7970" // Dallas, TX
// Your Apple Developer Information
Expand All @@ -80,6 +83,8 @@ Now, for the WeatherKit keys, in `config.h` define `WEATHERKIT_PUBKEY` and `WEAT
-----END PRIVATE KEY-----)"
```

> [!NOTE]
> Add `#define METRIC` to `config.h` if you prefer Celsius and kilometers.
### macOS

Expand Down
27 changes: 15 additions & 12 deletions WeatherFXLite.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
weatherfxlite
A lite replacement for the venerable Bushnell WeatherFX station. RIP.
Copyright (C) 2022 iAchieved.it LLC
Copyright (C) 2024 iAchieved.it LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -17,7 +17,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <math.h>
#include "WeatherFXLite.h"
#include "config.h"

#define CURRENT_CONDITION_TICKS 60
#define CURRENT_FORECAST_TICKS 60
Expand All @@ -29,19 +31,20 @@ WeatherFXLite::WeatherFXLite() {

window->setStyleSheet("background-color:black;");

#ifdef Q_OS_LINUX
#ifdef METRIC
ui.windUnits->setText("kph");
#endif

#ifdef Q_OS_LINUX
window->setWindowFlags(Qt::FramelessWindowHint);
window->setWindowState(Qt::WindowFullScreen);
QRect screenRect = QApplication::desktop()->screenGeometry(1);
window->move(QPoint(screenRect.x(), screenRect.y()));

#endif

#endif

window->show();

// Use WeatherKit
// Use the Apple WeatherKit API
weatherAPI = new WeatherKitAPI();

timer = new QTimer(this);
Expand All @@ -50,7 +53,7 @@ WeatherFXLite::WeatherFXLite() {
connect(weatherAPI, SIGNAL(currentForecastUpdate()), this, SLOT(updateForecastDisplay()));
connect(timer, SIGNAL(timeout()), this, SLOT(timerTick()));

timer->start(1000);
timer->start(1000); // 1 second

}

Expand All @@ -60,10 +63,8 @@ void WeatherFXLite::updateWeatherDisplay(void) {

ui.currentCondition->setText(current.condition);
ui.currentTemperature->setText(QString::number(current.temperature) + QString("°"));

ui.windSpeed->setText(QString::number(current.windSpeed));
ui.windDirection->setText(QString::number(current.windDirection) + QString("°"));

ui.windArrow->setDirection(current.windDirection);

std::string background = "background-color:" + backgroundForTemperature(current.temperature) + ";";
window->setStyleSheet(background.c_str());
Expand Down Expand Up @@ -99,7 +100,7 @@ void WeatherFXLite::timerTick(void) {

QDateTime now = QDateTime().currentDateTime();
QString timeNow = now.toString("h:mm A");
QString dateNow = now.toString("MMM dd, yyyy");
QString dateNow = now.toString("MMM dd");
ui.currentTime->setText(timeNow);
ui.currentDate->setText(dateNow);

Expand Down Expand Up @@ -134,11 +135,13 @@ const std::string backgrounds[] = {
/// @return
std::string WeatherFXLite::backgroundForTemperature(short temp) {

#ifdef CELSIUS
#ifdef METRIC
// Convert to Fahrenheit before indexing
temp = floor((temp * 9.0) / 5.0 + 32);
#endif

qDebug() << "Temperature: " << temp;

int tIndex = temp/10;
if (tIndex <= 0) tIndex = 0;
if (tIndex >= 9) tIndex = 9;
Expand Down
2 changes: 1 addition & 1 deletion WeatherFXLite.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
weatherfxlite
A lite replacement for the venerable Bushnell WeatherFX station. RIP.
Copyright (C) 2022 iAchieved.it LLC
Copyright (C) 2024 iAchieved.it LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
18 changes: 16 additions & 2 deletions WeatherKitAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,17 @@ void WeatherKitAPI::parseCurrentConditions(void) {
qDebug() << "windDirection: " << wd;

// Conversions
#ifdef CELSIUS
#ifdef METRIC
currentConditions.temperature = t.toDouble();
#else
currentConditions.temperature = floor((t.toDouble() * 9.0) / 5.0 + 32); // Celsius to Fahrenheit
#endif

#ifdef METRIC
currentConditions.windSpeed = round(ws.toDouble());
#else
currentConditions.windSpeed = round(ws.toDouble() * 0.621371); // kph to mph
#endif
currentConditions.windDirection = round(wd.toDouble());


Expand All @@ -206,6 +210,11 @@ void WeatherKitAPI::parseCurrentConditions(void) {
currentConditions.icon = nightIcons[c.toString()];
}

#ifdef DEBUG_EXTREMES
currentConditions.temperature = 120;
#endif


}

fDownloader->deleteLater();
Expand Down Expand Up @@ -246,14 +255,19 @@ void WeatherKitAPI::parseCurrentForecast(void) {
// Is the forecast for today?
if (qdt.date() == now.date()) {

#ifdef CELSIUS
#ifdef METRIC
double hi = f["temperatureMax"].toDouble();
double lo = f["temperatureMin"].toDouble();
#else
double hi = floor((f["temperatureMax"].toDouble() * 9.0) / 5.0 + 32);
double lo = floor((f["temperatureMin"].toDouble() * 9.0) / 5.0 + 32);
#endif

#ifdef DEBUG_EXTREMES
hi = 120;
lo = 100;
#endif

currentConditions.low = lo;
currentConditions.high = hi;

Expand Down
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ esac

qmake QMAKE_CXX="$QMAKE_CXX" QMAKE_LINK="$QMAKE_LINK" \
INCLUDEPATH+="$OPENSSL_PREFIX/include" LIBS+="-L$OPENSSL_PREFIX/lib -lcrypto"
make -j4

NUM_PROCESSORS=$(getconf _NPROCESSORS_ONLN)
make -j"$NUM_PROCESSORS"
7 changes: 2 additions & 5 deletions weatherfxLite.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ TEMPLATE = app
TARGET = weatherfxLite
INCLUDEPATH += . include

# Uncomment the following line to use the Celsius scale
# DEFINES += CELSIUS

#INCLUDEPATH += /opt/homebrew/opt/openssl@3/include
#LIBS += -L/opt/homebrew/opt/openssl@3/lib -lcrypto

QT += widgets network

# Input
FORMS += weatherFxLite.ui
HEADERS += WeatherKitAPI.h FileDownloader.h WeatherFXLite.h config.h
SOURCES += WeatherKitAPI.cpp main.cpp FileDownloader.cpp WeatherFXLite.cpp
HEADERS += WeatherKitAPI.h FileDownloader.h WeatherFXLite.h WindArrow.h config.h
SOURCES += WeatherKitAPI.cpp main.cpp FileDownloader.cpp WeatherFXLite.cpp WindArrow.cpp

# Output
DESTDIR = build
Expand Down
Loading

0 comments on commit 30d8544

Please sign in to comment.