void EddystoneService::setupConfigService(void) { lockStateChar = new ReadOnlyGattCharacteristic<bool>(UUID_LOCK_STATE_CHAR, &lockState); lockChar = new WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(Lock_t)>(UUID_LOCK_CHAR, lock); unlockChar = new WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(Lock_t)>(UUID_UNLOCK_CHAR, unlock); urlDataChar = new GattCharacteristic(UUID_URL_DATA_CHAR, urlFrame.getEncodedURLData(), 0, URL_DATA_MAX, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE); flagsChar = new ReadWriteGattCharacteristic<uint8_t>(UUID_FLAGS_CHAR, &flags); advPowerLevelsChar = new ReadWriteArrayGattCharacteristic<int8_t, sizeof(PowerLevels_t)>(UUID_ADV_POWER_LEVELS_CHAR, advPowerLevels); txPowerModeChar = new ReadWriteGattCharacteristic<uint8_t>(UUID_TX_POWER_MODE_CHAR, &txPowerMode); beaconPeriodChar = new ReadWriteGattCharacteristic<uint16_t>(UUID_BEACON_PERIOD_CHAR, &urlFramePeriod); resetChar = new WriteOnlyGattCharacteristic<bool>(UUID_RESET_CHAR, &resetFlag); lockChar->setWriteAuthorizationCallback(this, &EddystoneService::lockAuthorizationCallback); unlockChar->setWriteAuthorizationCallback(this, &EddystoneService::unlockAuthorizationCallback); urlDataChar->setWriteAuthorizationCallback(this, &EddystoneService::urlDataWriteAuthorizationCallback); flagsChar->setWriteAuthorizationCallback(this, &EddystoneService::basicAuthorizationCallback<uint8_t>); advPowerLevelsChar->setWriteAuthorizationCallback(this, &EddystoneService::basicAuthorizationCallback<PowerLevels_t>); txPowerModeChar->setWriteAuthorizationCallback(this, &EddystoneService::powerModeAuthorizationCallback); beaconPeriodChar->setWriteAuthorizationCallback(this, &EddystoneService::basicAuthorizationCallback<uint16_t>); resetChar->setWriteAuthorizationCallback(this, &EddystoneService::basicAuthorizationCallback<bool>); charTable[0] = lockStateChar; charTable[1] = lockChar; charTable[2] = unlockChar; charTable[3] = urlDataChar; charTable[4] = flagsChar; charTable[5] = advPowerLevelsChar; charTable[6] = txPowerModeChar; charTable[7] = beaconPeriodChar; charTable[8] = resetChar; GattService configService(UUID_URL_BEACON_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); ble.gattServer().addService(configService); ble.gattServer().onDataWritten(this, &EddystoneService::onDataWrittenCallback); updateCharacteristicValues(); setupEddystoneConfigAdvertisements(); }
/** Configures the application - returns false if the user chooses to abandon configuration. */ Ogre::Root* OgreSetup::configure(void) { ConfigService& configService(EmberServices::getSingleton().getConfigService()); createOgreSystem(); #ifndef BUILD_WEBEMBER bool success = false; bool suppressConfig = false; if (configService.itemExists("ogre", "suppressconfigdialog")) { suppressConfig = static_cast<bool>(configService.getValue("ogre", "suppressconfigdialog")); } try { success = mRoot->restoreConfig(); if (!success || !suppressConfig) { success = showConfigurationDialog(); } } catch (const std::exception& ex) { S_LOG_WARNING("Error when showing config dialog. Will try to remove ogre.cfg file and retry." << ex); unlink((EmberServices::getSingleton().getConfigService().getHomeDirectory() + "/ogre.cfg").c_str()); try { success = mRoot->showConfigDialog(); } catch (const std::exception& ex) { S_LOG_CRITICAL("Could not configure Ogre. Will shut down." << ex); } } if (!success) { return false; } mRenderWindow = mRoot->initialise(true, "Ember"); #else //BUILD_WEBEMBER == true //In webember we will disable the config dialog. //Also we will use fixed resolution and windowed mode. try { mRoot->restoreConfig(); } catch (const std::exception& ex) { //this isn't a problem, we will set the needed functions manually. } Ogre::RenderSystem* renderer = mRoot->getRenderSystem(); #ifdef _WIN32 //on windows, the default renderer is directX, we will force OpenGL. renderer = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); if (renderer != NULL) { mRoot->setRenderSystem(renderer); } else { S_LOG_WARNING("OpenGL RenderSystem not found. Starting with default RenderSystem."); renderer = mRoot->getRenderSystem(); } #endif // _WIN32 renderer->setConfigOption("Video Mode", "800 x 600"); renderer->setConfigOption("Full Screen", "no"); mRoot->initialise(false, "Ember"); Ogre::NameValuePairList options; if (configService.itemExists("ogre", "windowhandle")) { //set the owner window std::string windowhandle = configService.getValue("ogre", "windowhandle"); options["parentWindowHandle"] = windowhandle; //put it in the top left corner options["top"] = "0"; options["left"] = "0"; } mRenderWindow = mRoot->createRenderWindow("Ember",800,600,false,&options); #endif // BUILD_WEBEMBER #ifdef _WIN32 //do some FPU fiddling, since we need the correct settings for stuff like mercator (which uses fractals etc.) to work _fpreset(); _controlfp(_PC_64, _MCW_PC); _controlfp(_RC_NEAR , _MCW_RC); #endif mRenderWindow->setActive(true); mRenderWindow->setAutoUpdated(true); mRenderWindow->setVisible(true); setStandardValues(); // Create new scene manager factory mSceneManagerFactory = new EmberPagingSceneManagerFactory(); // Register our factory mRoot->addSceneManagerFactory(mSceneManagerFactory); return mRoot; }
/** Configures the application - returns false if the user chooses to abandon configuration. */ Ogre::Root* OgreSetup::configure() { delete mConfigListenerContainer; mConfigListenerContainer = new ConfigListenerContainer(); mConfigListenerContainer->registerConfigListener("ogre", "loglevel", sigc::mem_fun(*this, &OgreSetup::Config_ogreLogChanged), true); ConfigService& configService(EmberServices::getSingleton().getConfigService()); createOgreSystem(); #ifndef BUILD_WEBEMBER bool success = false; bool suppressConfig = false; if (configService.itemExists("ogre", "suppressconfigdialog")) { suppressConfig = static_cast<bool>(configService.getValue("ogre", "suppressconfigdialog")); } try { success = mRoot->restoreConfig(); if (!success || !suppressConfig) { success = showConfigurationDialog(); } } catch (const std::exception& ex) { S_LOG_WARNING("Error when showing config dialog. Will try to remove ogre.cfg file and retry." << ex); unlink((EmberServices::getSingleton().getConfigService().getHomeDirectory(BaseDirType_CONFIG) + "ogre.cfg").c_str()); try { Ogre::ConfigDialog* dlg = OGRE_NEW Ogre::ConfigDialog(); success = mRoot->showConfigDialog(dlg); OGRE_DELETE dlg; } catch (const std::exception& ex) { S_LOG_CRITICAL("Could not configure Ogre. Will shut down." << ex); } } if (!success) { return nullptr; } // we start by trying to figure out what kind of resolution the user has selected, and whether full screen should be used or not unsigned int height = 768, width = 1024; bool fullscreen = false; parseWindowGeometry(mRoot->getRenderSystem()->getConfigOptions(), width, height, fullscreen); bool handleOpenGL = false; #ifdef __APPLE__ handleOpenGL = true; #endif std::string windowId = Input::getSingleton().createWindow(width, height, fullscreen, true, true, handleOpenGL); mRoot->initialise(false, "Ember"); Ogre::NameValuePairList misc; #ifdef __APPLE__ misc["currentGLContext"] = Ogre::String("true"); misc["macAPI"] = Ogre::String("cocoa"); #else //We should use "externalWindowHandle" on Windows, and "parentWindowHandle" on Linux. #ifdef _WIN32 misc["externalWindowHandle"] = windowId; #else misc["parentWindowHandle"] = windowId; #endif #endif mRenderWindow = mRoot->createRenderWindow("MainWindow", width, height, fullscreen, &misc); Input::getSingleton().EventSizeChanged.connect(sigc::mem_fun(*this, &OgreSetup::input_SizeChanged)); registerOpenGLContextFix(); if (mSaveShadersToCache) { Ogre::GpuProgramManager::getSingleton().setSaveMicrocodesToCache(true); std::string cacheFilePath = configService.getHomeDirectory(BaseDirType_CACHE) + "/gpu-" VERSION ".cache"; if (std::ifstream(cacheFilePath).good()) { try { auto cacheStream = mRoot->openFileStream(cacheFilePath); if (cacheStream) { Ogre::GpuProgramManager::getSingleton().loadMicrocodeCache(cacheStream); } } catch (...) { S_LOG_WARNING("Error when trying to open GPU cache file."); } } } #else //BUILD_WEBEMBER == true //In webember we will disable the config dialog. //Also we will use fixed resolution and windowed mode. try { mRoot->restoreConfig(); } catch (const std::exception& ex) { //this isn't a problem, we will set the needed functions manually. } Ogre::RenderSystem* renderer = mRoot->getRenderSystem(); #ifdef _WIN32 //on windows, the default renderer is directX, we will force OpenGL. Ogre::RenderSystem* renderer = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem"); if(renderer != nullptr) { mRoot->setRenderSystem(renderer); } else { S_LOG_WARNING("OpenGL RenderSystem not found. Starting with default RenderSystem."); renderer = mRoot->getRenderSystem(); } #endif // _WIN32 renderer->setConfigOption("Video Mode", "800 x 600"); renderer->setConfigOption("Full Screen", "no"); mRoot->initialise(false, "Ember"); Ogre::NameValuePairList options; if (configService.itemExists("ogre", "windowhandle")) { //set the owner window std::string windowhandle = configService.getValue("ogre", "windowhandle"); options["parentWindowHandle"] = windowhandle; //put it in the top left corner options["top"] = "0"; options["left"] = "0"; } mRenderWindow = mRoot->createRenderWindow("Ember",800,600,false,&options); mOgreWindowProvider = new OgreWindowProvider(*mRenderWindow); Input::getSingleton().attach(mOgreWindowProvider); #endif // BUILD_WEBEMBER mRenderWindow->setActive(true); mRenderWindow->setAutoUpdated(true); mRenderWindow->setVisible(true); setStandardValues(); mConfigListenerContainer->registerConfigListener("ogre", "profiler", [&](const std::string& section, const std::string& key, varconf::Variable& variable) { if (variable.is_bool()) { auto* profiler = Ogre::Profiler::getSingletonPtr(); if (profiler) { if ((bool) variable) { auto& resourceGroupMgr = Ogre::ResourceGroupManager::getSingleton(); if (!resourceGroupMgr.resourceGroupExists("Profiler")) { resourceGroupMgr.addResourceLocation(OGRE_MEDIA_DIR"/packs/profiler.zip", "Zip", "Profiler", true); resourceGroupMgr.addResourceLocation(OGRE_MEDIA_DIR"/packs/SdkTrays.zip", "Zip", "Profiler", true); resourceGroupMgr.initialiseResourceGroup("Profiler"); } } if (profiler->getEnabled() != (bool) variable) { profiler->reset(); profiler->setEnabled((bool) variable); } } } }); // Create new scene manager factory //mSceneManagerFactory = new EmberPagingSceneManagerFactory(); //// Register our factory //mRoot->addSceneManagerFactory(mSceneManagerFactory); return mRoot; }