std::string SoundSensor::getData(mcp3302 a2d) { int value = obtainData(a2d); while (value == 0) value = obtainData(a2d); double vOut = value * 4.9 / 4096.0; double sound_dB = 20 * log10(vOut * 191) + 26; std::string dataString; std::stringstream ss; ss << sound_dB; ss >> dataString; return dataString; }
bool OsmAnd::MapRendererRasterMapLayerResource::obtainData(bool& dataAvailable, const IQueryController* queryController) { bool ok = false; // Get source of tile std::shared_ptr<IMapDataProvider> provider_; if (const auto link_ = link.lock()) ok = resourcesManager->obtainProviderFor(static_cast<MapRendererBaseResourcesCollection*>(static_cast<MapRendererTiledResourcesCollection*>(&link_->collection)), provider_); if (!ok) return false; const auto provider = std::static_pointer_cast<IMapTiledDataProvider>(provider_); // Obtain tile from provider std::shared_ptr<IMapTiledDataProvider::Data> tiledData; const auto requestSucceeded = provider->obtainData(tileId, zoom, tiledData, nullptr, queryController); if (!requestSucceeded) return false; dataAvailable = static_cast<bool>(tiledData); // Store data if (dataAvailable) _sourceData = std::static_pointer_cast<IRasterMapLayerProvider::Data>(tiledData); // Convert data if such is present if (_sourceData) { _sourceData->bitmap = resourcesManager->adjustBitmapToConfiguration( _sourceData->bitmap, _sourceData->alphaChannelPresence); } return true; }
bool OsmAnd::MapRendererElevationDataResource::obtainData(bool& dataAvailable, const IQueryController* queryController) { bool ok = false; // Get source of tile std::shared_ptr<IMapDataProvider> provider_; if (const auto link_ = link.lock()) ok = resourcesManager->obtainProviderFor(static_cast<MapRendererBaseResourcesCollection*>(static_cast<MapRendererTiledResourcesCollection*>(&link_->collection)), provider_); if (!ok) return false; const auto provider = std::static_pointer_cast<IMapTiledDataProvider>(provider_); // Obtain tile from provider std::shared_ptr<IMapTiledDataProvider::Data> tile; const auto requestSucceeded = provider->obtainData(tileId, zoom, tile, queryController); if (!requestSucceeded) return false; dataAvailable = static_cast<bool>(tile); // Store data if (dataAvailable) _sourceData = std::static_pointer_cast<IMapElevationDataProvider::Data>(tile); return true; }
bool OsmAnd::MapRendererKeyedSymbolsResource::obtainData(bool& dataAvailable, const IQueryController* queryController) { // Obtain collection link and maintain it const auto link_ = link.lock(); if (!link_) return false; const auto collection = static_cast<MapRendererKeyedResourcesCollection*>(&link_->collection); // Get source std::shared_ptr<IMapDataProvider> provider_; bool ok = resourcesManager->obtainProviderFor(static_cast<MapRendererBaseResourcesCollection*>(collection), provider_); if (!ok) return false; const auto provider = std::static_pointer_cast<IMapKeyedDataProvider>(provider_); // Obtain source data from provider std::shared_ptr<IMapKeyedDataProvider::Data> keyedData; const auto requestSucceeded = provider->obtainData(key, keyedData); if (!requestSucceeded) return false; // Store data dataAvailable = static_cast<bool>(keyedData); if (dataAvailable) _sourceData = std::static_pointer_cast<IMapKeyedSymbolsProvider::Data>(keyedData); // Process data if (!dataAvailable) return true; // Convert data for (const auto& mapSymbol : constOf(_sourceData->symbolsGroup->symbols)) { const auto rasterMapSymbol = std::dynamic_pointer_cast<RasterMapSymbol>(mapSymbol); if (!rasterMapSymbol) continue; rasterMapSymbol->bitmap = resourcesManager->adjustBitmapToConfiguration( rasterMapSymbol->bitmap, AlphaChannelPresence::Present); } // Register all obtained symbols _mapSymbolsGroup = _sourceData->symbolsGroup; const auto self = shared_from_this(); QList< PublishOrUnpublishMapSymbol > mapSymbolsToPublish; mapSymbolsToPublish.reserve(_mapSymbolsGroup->symbols.size()); for (const auto& symbol : constOf(_mapSymbolsGroup->symbols)) { PublishOrUnpublishMapSymbol mapSymbolToPublish = { _mapSymbolsGroup, std::static_pointer_cast<const MapSymbol>(symbol), self }; mapSymbolsToPublish.push_back(mapSymbolToPublish); } resourcesManager->batchPublishMapSymbols(mapSymbolsToPublish); return true; }
bool OsmAnd::BinaryMapRasterBitmapTileProvider_P::obtainData( const TileId tileId, const ZoomLevel zoom, std::shared_ptr<MapTiledData>& outTiledData, const IQueryController* const queryController) { return obtainData(tileId, zoom, outTiledData, nullptr, queryController); }
bool OsmAnd::IMapObjectsProvider::obtainData( const TileId tileId, const ZoomLevel zoom, std::shared_ptr<IMapTiledDataProvider::Data>& outTiledData, std::shared_ptr<Metric>* pOutMetric /*= nullptr*/, const IQueryController* const queryController /*= nullptr*/) { std::shared_ptr<Data> tiledData; const auto result = obtainData(tileId, zoom, tiledData, pOutMetric, queryController); outTiledData = tiledData; return result; }
bool OsmAnd::IMapTiledSymbolsProvider::obtainData( const TileId tileId, const ZoomLevel zoom, std::shared_ptr<MapTiledData>& outTiledData, const IQueryController* const queryController /*= nullptr*/) { std::shared_ptr<TiledMapSymbolsData> tiledMapSymbolsData; const auto result = obtainData(tileId, zoom, tiledMapSymbolsData, nullptr, queryController); outTiledData = tiledMapSymbolsData; return result; }
/** * \brief Take measurement of the humidity of environment * * \return String of the measured relative humidity * * \details This function will attempt to measure the humidity and return in string format. * The measurement unit is in percentage, from 0 up to 100 percentage. */ std::string HumiditySensor::getData() { //float humidity = 50; //int temperature; //while (!obtainData()); //humidity = (float)(DHT22_value[0] * 256 + DHT22_value[1]) / 10.0; //printf("Humidity: %.2f%\n", humidity); //temperature = (DHT22_value[2] & 0x7F) * 256 + DHT22_value[3]; //wiringPiSetup(); obtainData(); std::string dataString; std::stringstream ss; ss << humidity; ss >> dataString; return dataString; }
bool OsmAnd::MapRendererTiledSymbolsResource::obtainData(bool& dataAvailable, const IQueryController* queryController) { // Obtain collection link and maintain it const auto link_ = link.lock(); if (!link_) return false; const auto collection = static_cast<MapRendererTiledSymbolsResourcesCollection*>(&link_->collection); // Get source of tile std::shared_ptr<IMapDataProvider> provider_; bool ok = resourcesManager->obtainProviderFor(static_cast<MapRendererBaseResourcesCollection*>(collection), provider_); if (!ok) return false; const auto provider = std::static_pointer_cast<IMapTiledSymbolsProvider>(provider_); auto& sharedGroupsResources = collection->_sharedGroupsResources[zoom]; // Obtain tile from provider QList< std::shared_ptr<SharedGroupResources> > referencedSharedGroupsResources; QList< proper::shared_future< std::shared_ptr<SharedGroupResources> > > futureReferencedSharedGroupsResources; QSet< uint64_t > loadedSharedGroups; std::shared_ptr<TiledMapSymbolsData> tile; const auto requestSucceeded = provider->obtainData(tileId, zoom, tile, [this, provider, &sharedGroupsResources, &referencedSharedGroupsResources, &futureReferencedSharedGroupsResources, &loadedSharedGroups] (const IMapTiledSymbolsProvider*, const std::shared_ptr<const MapSymbolsGroup>& symbolsGroup_) -> bool { // If map symbols group is not shareable, just accept it const auto symbolsGroup = std::dynamic_pointer_cast<const IMapSymbolsGroupWithUniqueId>(symbolsGroup_); if (!symbolsGroup || !symbolsGroup->isSharableById()) return true; // Check if this shared symbol is already available, or mark it as pending std::shared_ptr<SharedGroupResources> sharedGroupResources; proper::shared_future< std::shared_ptr<SharedGroupResources> > futureSharedGroupResources; if (sharedGroupsResources.obtainReferenceOrFutureReferenceOrMakePromise(symbolsGroup->getId(), sharedGroupResources, futureSharedGroupResources)) { if (static_cast<bool>(sharedGroupResources)) { referencedSharedGroupsResources.push_back(qMove(sharedGroupResources)); #if OSMAND_LOG_SHARED_MAP_SYMBOLS_GROUPS_LIFECYCLE LogPrintf(LogSeverityLevel::Debug, "Shared GroupResources(%p) for %s referenced from %p (%dx%d@%d)", sharedGroupResources.get(), qPrintable(symbolsGroup->getDebugTitle()), this, tileId.x, tileId.y, zoom); #endif // OSMAND_LOG_SHARED_MAP_SYMBOLS_GROUPS_LIFECYCLE } else futureReferencedSharedGroupsResources.push_back(qMove(futureSharedGroupResources)); return false; } // Or load this shared group loadedSharedGroups.insert(symbolsGroup->getId()); return true; }); if (!requestSucceeded) return false; // Store data _sourceData = tile; dataAvailable = static_cast<bool>(tile); // Process data if (!dataAvailable) return true; // Convert data for (const auto& symbolsGroup : constOf(_sourceData->symbolsGroups)) { for (const auto& mapSymbol : constOf(symbolsGroup->symbols)) { const auto rasterMapSymbol = std::dynamic_pointer_cast<RasterMapSymbol>(mapSymbol); if (!rasterMapSymbol) continue; rasterMapSymbol->bitmap = resourcesManager->adjustBitmapToConfiguration( rasterMapSymbol->bitmap, AlphaChannelData::Present); } } // Move referenced shared groups _referencedSharedGroupsResources = referencedSharedGroupsResources; // tile->symbolsGroups contains groups that derived from unique symbols, or loaded shared groups for (const auto& symbolsGroup : constOf(_sourceData->symbolsGroups)) { const auto symbolsGroupWithId = std::dynamic_pointer_cast<const IMapSymbolsGroupWithUniqueId>(symbolsGroup); if (symbolsGroupWithId && symbolsGroupWithId->isSharableById()) { // Check if this map symbols group is loaded as shared (even if it's sharable) if (!loadedSharedGroups.contains(symbolsGroupWithId->getId())) { // Create GroupResources instance and add it to unique group resources const std::shared_ptr<GroupResources> groupResources(new GroupResources(symbolsGroup)); _uniqueGroupsResources.push_back(qMove(groupResources)); continue; } // Otherwise insert it as shared group const std::shared_ptr<SharedGroupResources> groupResources(new SharedGroupResources(symbolsGroup)); sharedGroupsResources.fulfilPromiseAndReference(symbolsGroupWithId->getId(), groupResources); _referencedSharedGroupsResources.push_back(qMove(groupResources)); #if OSMAND_LOG_SHARED_MAP_SYMBOLS_GROUPS_LIFECYCLE LogPrintf(LogSeverityLevel::Debug, "Shared GroupResources(%p) for %s allocated and referenced from %p (%dx%d@%d): %" PRIu64 " ref(s)", groupResources.get(), qPrintable(symbolsGroup->getDebugTitle()), this, tileId.x, tileId.y, zoom, sharedGroupsResources.getReferencesCount(symbolsGroupWithId->getId())); #endif // OSMAND_LOG_SHARED_MAP_SYMBOLS_GROUPS_LIFECYCLE } else { // Create GroupResources instance and add it to unique group resources const std::shared_ptr<GroupResources> groupResources(new GroupResources(symbolsGroup)); _uniqueGroupsResources.push_back(qMove(groupResources)); } } // Wait for future referenced shared groups for (auto& futureGroup : futureReferencedSharedGroupsResources) { auto groupResources = futureGroup.get(); _referencedSharedGroupsResources.push_back(qMove(groupResources)); #if OSMAND_LOG_SHARED_MAP_SYMBOLS_GROUPS_LIFECYCLE const auto symbolsGroupWithId = std::static_pointer_cast<const IMapSymbolsGroupWithUniqueId>(groupResources->group); LogPrintf(LogSeverityLevel::Debug, "Shared GroupResources(%p) for %s referenced from %p (%dx%d@%d): %" PRIu64 " ref(s)", groupResources.get(), qPrintable(symbolsGroup->getDebugTitle()), this, tileId.x, tileId.y, zoom, sharedGroupsResources.getReferencesCount(symbolsGroupWithId->getId())); #endif // OSMAND_LOG_SHARED_MAP_SYMBOLS_GROUPS_LIFECYCLE } // Register all obtained symbols const auto& self = shared_from_this(); for (const auto& groupResources : constOf(_uniqueGroupsResources)) { const auto& symbolsGroup = groupResources->group; auto& publishedMapSymbols = _publishedMapSymbolsByGroup[symbolsGroup]; for (const auto& mapSymbol : constOf(symbolsGroup->symbols)) { resourcesManager->publishMapSymbol(symbolsGroup, mapSymbol, self); publishedMapSymbols.push_back(mapSymbol); } } for (const auto& groupResources : constOf(_referencedSharedGroupsResources)) { const auto& symbolsGroup = groupResources->group; auto& publishedMapSymbols = _publishedMapSymbolsByGroup[symbolsGroup]; for (const auto& mapSymbol : constOf(symbolsGroup->symbols)) { resourcesManager->publishMapSymbol(symbolsGroup, mapSymbol, self); publishedMapSymbols.push_back(mapSymbol); } } // Since there's a copy of references to map symbols groups and symbols themselves, // it's safe to consume all the data here _sourceData->releaseConsumableContent(); return true; }