aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/ble/SimpleWeatherService.cpp31
-rw-r--r--src/components/ble/SimpleWeatherService.h16
-rw-r--r--src/displayapp/screens/WatchFacePineTimeStyle.cpp2
3 files changed, 32 insertions, 17 deletions
diff --git a/src/components/ble/SimpleWeatherService.cpp b/src/components/ble/SimpleWeatherService.cpp
index 2ba26321..90adb926 100644
--- a/src/components/ble/SimpleWeatherService.cpp
+++ b/src/components/ble/SimpleWeatherService.cpp
@@ -29,18 +29,30 @@ namespace {
enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown };
uint64_t ToUInt64(const uint8_t* data) {
- return *(reinterpret_cast<const uint64_t*>(data));
+ return data[0] +
+ (data[1] << 8) +
+ (data[2] << 16) +
+ (data[3] << 24) +
+ (static_cast<uint64_t>(data[4]) << 32) +
+ (static_cast<uint64_t>(data[5]) << 48) +
+ (static_cast<uint64_t>(data[6]) << 48) +
+ (static_cast<uint64_t>(data[7]) << 56);
+ }
+
+ int16_t ToInt16(const uint8_t* data) {
+ return data[0] +
+ (data[1] << 8);
}
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
SimpleWeatherService::Location cityName;
- std::memcpy(cityName.data(), &dataBuffer[13], 32);
+ std::memcpy(cityName.data(), &dataBuffer[16], 32);
cityName[32] = '\0';
return SimpleWeatherService::CurrentWeather (ToUInt64(&dataBuffer[2]),
- dataBuffer[10],
- dataBuffer[11],
- dataBuffer[12],
- SimpleWeatherService::Icons{dataBuffer[13 + 32]},
+ ToInt16(&dataBuffer[10]),
+ ToInt16(&dataBuffer[12]),
+ ToInt16(&dataBuffer[14]),
+ SimpleWeatherService::Icons{dataBuffer[16 + 32]},
std::move(cityName));
}
@@ -51,7 +63,10 @@ namespace {
const uint8_t nbDaysInBuffer = dataBuffer[10];
const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer);
for (int i = 0; i < nbDays; i++) {
- days[i] = SimpleWeatherService::Forecast::Day {dataBuffer[11 + (i * 3)], dataBuffer[12 + (i * 3)], SimpleWeatherService::Icons{dataBuffer[13 + (i * 3)]}};
+ days[i] = SimpleWeatherService::Forecast::Day {
+ ToInt16(&dataBuffer[11 + (i * 5)]),
+ ToInt16(&dataBuffer[13 + (i * 5)]),
+ SimpleWeatherService::Icons{dataBuffer[15 + (i * 5)]}};
}
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
}
@@ -95,7 +110,7 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
currentWeather->minTemperature,
currentWeather->maxTemperature,
currentWeather->iconId,
- currentWeather->location);
+ currentWeather->location.data());
}
break;
case MessageType::Forecast:
diff --git a/src/components/ble/SimpleWeatherService.h b/src/components/ble/SimpleWeatherService.h
index 561917eb..02a4c1e4 100644
--- a/src/components/ble/SimpleWeatherService.h
+++ b/src/components/ble/SimpleWeatherService.h
@@ -64,9 +64,9 @@ namespace Pinetime {
using Location = std::array<char, 33>; // 32 char + \0 (end of string)
struct CurrentWeather {
CurrentWeather(uint64_t timestamp,
- uint8_t temperature,
- uint8_t minTemperature,
- uint8_t maxTemperature,
+ int16_t temperature,
+ int16_t minTemperature,
+ int16_t maxTemperature,
Icons iconId,
Location&& location)
: timestamp {timestamp},
@@ -78,9 +78,9 @@ namespace Pinetime {
}
uint64_t timestamp;
- uint8_t temperature;
- uint8_t minTemperature;
- uint8_t maxTemperature;
+ int16_t temperature;
+ int16_t minTemperature;
+ int16_t maxTemperature;
Icons iconId;
Location location;
@@ -92,8 +92,8 @@ namespace Pinetime {
uint8_t nbDays;
struct Day {
- uint8_t minTemperature;
- uint8_t maxTemperature;
+ int16_t minTemperature;
+ int16_t maxTemperature;
Icons iconId;
};
diff --git a/src/displayapp/screens/WatchFacePineTimeStyle.cpp b/src/displayapp/screens/WatchFacePineTimeStyle.cpp
index 5259d553..9885bb42 100644
--- a/src/displayapp/screens/WatchFacePineTimeStyle.cpp
+++ b/src/displayapp/screens/WatchFacePineTimeStyle.cpp
@@ -543,7 +543,7 @@ void WatchFacePineTimeStyle::Refresh() {
if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();
if (optCurrentWeather) {
- lv_label_set_text_fmt(temperature, "%d°", optCurrentWeather->temperature);
+ lv_label_set_text_fmt(temperature, "%d°", (optCurrentWeather->temperature)/100);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
lv_obj_realign(temperature);
lv_obj_realign(weatherIcon);