Advertisement
Guest User

Untitled

a guest
May 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. JNIEXPORT jbyte JNICALL Java_main_java_DrawerTest_CabinetLibrary_CabinetLibrary_nativeReInitializeDrawerConfiguration(JNIEnv *env, jobject obj)
  2. {
  3. state = nullptr;
  4. drawerController = nullptr;
  5. wiringPiWrapper = nullptr;
  6. interruptHandler = nullptr;
  7.  
  8. if (state == nullptr) {
  9. state = new CabinetState();
  10. if (state == nullptr) {
  11. TINYLOG_ERROR("JNI_OnLoad could not get memory for CabinetState!");
  12. return -1;
  13. }
  14. }
  15.  
  16. if (state == nullptr) {
  17. TINYLOG_ERROR("JNI not initialized correctly");
  18. return -1;
  19. }
  20.  
  21. GPIO_Init();
  22.  
  23. ConfigurationManager configurationManager;
  24. if(configurationManager.readConfigurationFromFile(state->cabinetConfiguration))
  25. {
  26. configurationManager.writeDefaultConfigurationFile(state->cabinetConfiguration);
  27. }
  28.  
  29. state->i2cMux = new PCA9548(0x70);
  30. state->gpioExt1 = new PCA9505(0x20);
  31. state->gpioExt2 = new PCA9505(0x21);
  32. state->gpioExt3 = new PCA9505(0x22);
  33. state->storageGpioExt1 = new PCA9505(0x24);
  34. state->storageGpioExt2 = new PCA9538(0x73);
  35. state->mainGpioExt = new TCA6424(0x23);
  36. state->tempVoltageController = new TempVoltController(0x4c);
  37. state->tempVoltageController->configure(state->i2cLock);
  38.  
  39. if (drawerController == nullptr) {
  40. drawerController = new DrawerController();
  41. if (drawerController == nullptr) {
  42. TINYLOG_ERROR("JNI_OnLoad could not get memory for DrawerController!");
  43. return -1;
  44. }
  45. drawerController->initializeDrawers(state);
  46. DRAWER_CONFIGURATION_STATUS status = drawerController->initializeStorageConfigurations(state);
  47. TINYLOG_DEBUG("initializeStorageConfiguration status = " + to_string(int(status)));
  48. }
  49.  
  50. if (wiringPiWrapper == nullptr) {
  51. wiringPiWrapper = new WiringPiWrapper();
  52. if (wiringPiWrapper == nullptr) {
  53. TINYLOG_ERROR("JNI_OnLoad could not get memory for wiringPiWrapper!");
  54. return -1;
  55. }
  56. wiringPiWrapper->initBuzzer();
  57. }
  58. if(interruptHandler == nullptr)
  59. {
  60. interruptHandler = new InterruptHandler();
  61. if (interruptHandler == nullptr) {
  62. TINYLOG_ERROR("JNI_OnLoad could not get memory for InterruptHandler!");
  63. return -1;
  64. }
  65. interruptHandler->startListening(state);
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement