SimpleWeather service : new weather implementation
Fix recovery firmware and code formatting.
This commit is contained in:
parent
c94a59e7d3
commit
50c679023f
|
@ -22,19 +22,15 @@
|
|||
using namespace Pinetime::Controllers;
|
||||
|
||||
namespace {
|
||||
enum class MessageType {
|
||||
CurrentWeather,
|
||||
Forecast,
|
||||
Unknown
|
||||
};
|
||||
enum class MessageType { CurrentWeather, Forecast, Unknown };
|
||||
|
||||
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
|
||||
char cityName[33];
|
||||
std::memcpy(&cityName[0], &dataBuffer[13], 32);
|
||||
cityName[32] = '\0';
|
||||
return SimpleWeatherService::CurrentWeather {dataBuffer[2] + (dataBuffer[3] << 8) + (dataBuffer[4] << 16) + (dataBuffer[5] << 24) +
|
||||
((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) + ((uint64_t) dataBuffer[8] << 48) +
|
||||
((uint64_t) dataBuffer[9] << 54),
|
||||
((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) +
|
||||
((uint64_t) dataBuffer[8] << 48) + ((uint64_t) dataBuffer[9] << 54),
|
||||
dataBuffer[10],
|
||||
dataBuffer[11],
|
||||
dataBuffer[12],
|
||||
|
@ -44,23 +40,27 @@ namespace {
|
|||
|
||||
SimpleWeatherService::Forecast CreateForecast(const uint8_t* dataBuffer) {
|
||||
uint64_t timestamp = static_cast<uint64_t>(dataBuffer[2] + (dataBuffer[3] << 8) + (dataBuffer[4] << 16) + (dataBuffer[5] << 24) +
|
||||
((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) + ((uint64_t) dataBuffer[8] << 48) +
|
||||
((uint64_t) dataBuffer[9] << 54));
|
||||
((uint64_t) dataBuffer[6] << 32) + ((uint64_t) dataBuffer[7] << 40) +
|
||||
((uint64_t) dataBuffer[8] << 48) + ((uint64_t) dataBuffer[9] << 54));
|
||||
uint8_t nbDays = dataBuffer[10];
|
||||
std::array<SimpleWeatherService::Forecast::Day, 5> days;
|
||||
for (int i = 0; i < nbDays; i++) {
|
||||
days[i] = SimpleWeatherService::Forecast::Day {dataBuffer[11 + (i * 3)],
|
||||
dataBuffer[12 + (i * 3)],
|
||||
dataBuffer[13 + (i * 3)]};
|
||||
days[i] = SimpleWeatherService::Forecast::Day {dataBuffer[11 + (i * 3)], dataBuffer[12 + (i * 3)], dataBuffer[13 + (i * 3)]};
|
||||
}
|
||||
return SimpleWeatherService::Forecast {timestamp, nbDays, days};
|
||||
}
|
||||
|
||||
MessageType GetMessageType(const uint8_t* dataBuffer) {
|
||||
switch (dataBuffer[0]) {
|
||||
case 0: return MessageType::CurrentWeather; break;
|
||||
case 1: return MessageType::Forecast; break;
|
||||
default: return MessageType::Unknown; break;
|
||||
case 0:
|
||||
return MessageType::CurrentWeather;
|
||||
break;
|
||||
case 1:
|
||||
return MessageType::Forecast;
|
||||
break;
|
||||
default:
|
||||
return MessageType::Unknown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,6 @@ int WeatherCallback(uint16_t /*connHandle*/, uint16_t /*attrHandle*/, struct ble
|
|||
}
|
||||
|
||||
SimpleWeatherService::SimpleWeatherService(const DateTime& dateTimeController) : dateTimeController(dateTimeController) {
|
||||
|
||||
}
|
||||
|
||||
void SimpleWeatherService::Init() {
|
||||
|
@ -104,7 +103,11 @@ int SimpleWeatherService::OnCommand(struct ble_gatt_access_ctxt* ctxt) {
|
|||
forecast = CreateForecast(dataBuffer);
|
||||
NRF_LOG_INFO("Forecast : Timestamp : %d", forecast->timestamp);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
NRF_LOG_INFO("\t[%d] Min: %d - Max : %d - Icon : %d", i, forecast->days[i].minTemperature, forecast->days[i].maxTemperature, forecast->days[i].iconId);
|
||||
NRF_LOG_INFO("\t[%d] Min: %d - Max : %d - Icon : %d",
|
||||
i,
|
||||
forecast->days[i].minTemperature,
|
||||
forecast->days[i].maxTemperature,
|
||||
forecast->days[i].iconId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -60,13 +60,21 @@ namespace Pinetime {
|
|||
};
|
||||
|
||||
struct CurrentWeather {
|
||||
CurrentWeather(uint64_t timestamp, uint8_t temperature, uint8_t minTemperature, uint8_t maxTemperature,
|
||||
uint8_t iconId, const char* location)
|
||||
: timestamp{timestamp}, temperature{temperature}, minTemperature{minTemperature}, maxTemperature{maxTemperature},
|
||||
CurrentWeather(uint64_t timestamp,
|
||||
uint8_t temperature,
|
||||
uint8_t minTemperature,
|
||||
uint8_t maxTemperature,
|
||||
uint8_t iconId,
|
||||
const char* location)
|
||||
: timestamp {timestamp},
|
||||
temperature {temperature},
|
||||
minTemperature {minTemperature},
|
||||
maxTemperature {maxTemperature},
|
||||
iconId {iconId} {
|
||||
std::memcpy(this->location, location, 32);
|
||||
this->location[32] = 0;
|
||||
}
|
||||
|
||||
uint64_t timestamp;
|
||||
uint8_t temperature;
|
||||
uint8_t minTemperature;
|
||||
|
@ -81,18 +89,19 @@ namespace Pinetime {
|
|||
struct Forecast {
|
||||
uint64_t timestamp;
|
||||
uint8_t nbDays;
|
||||
|
||||
struct Day {
|
||||
uint8_t minTemperature;
|
||||
uint8_t maxTemperature;
|
||||
uint8_t iconId;
|
||||
};
|
||||
|
||||
std::array<Day, 5> days;
|
||||
};
|
||||
|
||||
std::optional<CurrentWeather> Current() const;
|
||||
std::optional<Forecast> GetForecast() const;
|
||||
|
||||
|
||||
private:
|
||||
// 00050000-78fc-48fe-8e23-433b3a1942d0
|
||||
static constexpr ble_uuid128_t BaseUuid() {
|
||||
|
@ -109,8 +118,7 @@ namespace Pinetime {
|
|||
|
||||
ble_uuid128_t weatherDataCharUuid {CharUuid(0x00, 0x01)};
|
||||
|
||||
const struct ble_gatt_chr_def characteristicDefinition[2] = {
|
||||
{.uuid = &weatherDataCharUuid.u,
|
||||
const struct ble_gatt_chr_def characteristicDefinition[2] = {{.uuid = &weatherDataCharUuid.u,
|
||||
.access_cb = WeatherCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE,
|
||||
|
|
|
@ -122,7 +122,7 @@ void DisplayApp::PushMessage(Display::Messages msg) {
|
|||
void DisplayApp::Register(Pinetime::System::SystemTask* /*systemTask*/) {
|
||||
}
|
||||
|
||||
void DisplayApp::Register(Pinetime::Controllers::WeatherService* /*weatherService*/) {
|
||||
void DisplayApp::Register(Pinetime::Controllers::SimpleWeatherService* /*weatherService*/) {
|
||||
}
|
||||
|
||||
void DisplayApp::Register(Pinetime::Controllers::MusicService* /*musicService*/) {
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Pinetime {
|
|||
class AlarmController;
|
||||
class BrightnessController;
|
||||
class FS;
|
||||
class WeatherService;
|
||||
class SimpleWeatherService;
|
||||
class MusicService;
|
||||
class NavigationService;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace Pinetime {
|
|||
|
||||
void PushMessage(Pinetime::Applications::Display::Messages msg);
|
||||
void Register(Pinetime::System::SystemTask* systemTask);
|
||||
void Register(Pinetime::Controllers::WeatherService* weatherService);
|
||||
void Register(Pinetime::Controllers::SimpleWeatherService* weatherService);
|
||||
void Register(Pinetime::Controllers::MusicService* musicService);
|
||||
void Register(Pinetime::Controllers::NavigationService* NavigationService);
|
||||
|
||||
|
|
|
@ -45,16 +45,36 @@ namespace {
|
|||
|
||||
const char* GetIcon(const Pinetime::Controllers::SimpleWeatherService::Icons icon) {
|
||||
switch (icon) {
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Sun: return Symbols::sun; break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudsSun: return Symbols::cloudSun; break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Clouds: return Symbols::cloud; break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds: return Symbols::cloud; break; // TODO missing symbol
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm: return Symbols::cloud; break; // TODO missing symbol
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Snow: return Symbols::cloud; break; // TODO missing symbol
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy: return Symbols::cloudShowersHeavy; break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudSunRain: return Symbols::cloudSunRain; break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Smog: return Symbols::smog; break;
|
||||
default: return Symbols::ban; break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Sun:
|
||||
return Symbols::sun;
|
||||
break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudsSun:
|
||||
return Symbols::cloudSun;
|
||||
break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Clouds:
|
||||
return Symbols::cloud;
|
||||
break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::BrokenClouds:
|
||||
return Symbols::cloud;
|
||||
break; // TODO missing symbol
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Thunderstorm:
|
||||
return Symbols::cloud;
|
||||
break; // TODO missing symbol
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Snow:
|
||||
return Symbols::cloud;
|
||||
break; // TODO missing symbol
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudShowerHeavy:
|
||||
return Symbols::cloudShowersHeavy;
|
||||
break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::CloudSunRain:
|
||||
return Symbols::cloudSunRain;
|
||||
break;
|
||||
case Pinetime::Controllers::SimpleWeatherService::Icons::Smog:
|
||||
return Symbols::smog;
|
||||
break;
|
||||
default:
|
||||
return Symbols::ban;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue