Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JNIEXPORT jbyte JNICALL Java_main_java_DrawerTest_CabinetLibrary_CabinetLibrary_nativeReInitializeDrawerConfiguration(JNIEnv *env, jobject obj)
- {
- state = nullptr;
- drawerController = nullptr;
- wiringPiWrapper = nullptr;
- interruptHandler = nullptr;
- if (state == nullptr) {
- state = new CabinetState();
- if (state == nullptr) {
- TINYLOG_ERROR("JNI_OnLoad could not get memory for CabinetState!");
- return -1;
- }
- }
- if (state == nullptr) {
- TINYLOG_ERROR("JNI not initialized correctly");
- return -1;
- }
- GPIO_Init();
- ConfigurationManager configurationManager;
- if(configurationManager.readConfigurationFromFile(state->cabinetConfiguration))
- {
- configurationManager.writeDefaultConfigurationFile(state->cabinetConfiguration);
- }
- state->i2cMux = new PCA9548(0x70);
- state->gpioExt1 = new PCA9505(0x20);
- state->gpioExt2 = new PCA9505(0x21);
- state->gpioExt3 = new PCA9505(0x22);
- state->storageGpioExt1 = new PCA9505(0x24);
- state->storageGpioExt2 = new PCA9538(0x73);
- state->mainGpioExt = new TCA6424(0x23);
- state->tempVoltageController = new TempVoltController(0x4c);
- state->tempVoltageController->configure(state->i2cLock);
- if (drawerController == nullptr) {
- drawerController = new DrawerController();
- if (drawerController == nullptr) {
- TINYLOG_ERROR("JNI_OnLoad could not get memory for DrawerController!");
- return -1;
- }
- drawerController->initializeDrawers(state);
- DRAWER_CONFIGURATION_STATUS status = drawerController->initializeStorageConfigurations(state);
- TINYLOG_DEBUG("initializeStorageConfiguration status = " + to_string(int(status)));
- }
- if (wiringPiWrapper == nullptr) {
- wiringPiWrapper = new WiringPiWrapper();
- if (wiringPiWrapper == nullptr) {
- TINYLOG_ERROR("JNI_OnLoad could not get memory for wiringPiWrapper!");
- return -1;
- }
- wiringPiWrapper->initBuzzer();
- }
- if(interruptHandler == nullptr)
- {
- interruptHandler = new InterruptHandler();
- if (interruptHandler == nullptr) {
- TINYLOG_ERROR("JNI_OnLoad could not get memory for InterruptHandler!");
- return -1;
- }
- interruptHandler->startListening(state);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement