Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serialHelper.c 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * unixHelper.c
  3. *
  4. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  5. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  6. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  7. *
  8. * This file is part of LED-Cube.
  9. *
  10. * LED-Cube is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * LED-Cube is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <jni.h>
  26. #include "serialInterface.h"
  27. #ifdef winHelper
  28. #include "helper/winSerial.c"
  29. #else
  30. #include "helper/unixSerial.c"
  31. #endif
  32. JNIEXPORT jstring JNICALL Java_HelperUtility_getPorts(JNIEnv *env, jclass class) {
  33. char **ports = getSerialPorts();
  34. char *string = NULL;
  35. int length = 0, leng2 = 0, lengthabs = 0;
  36. // printf("JNI: Got serial ports...\n");
  37. // Count how much memory we need for string of all ports, with \n in between
  38. while (ports[length] != NULL) {
  39. // printf("JNI: Starting count... (%d at %p)\n", length, (void *)ports[length]);
  40. while (ports[length][leng2] != '\0') {
  41. leng2++;
  42. }
  43. // printf("JNI: Counted %s\n", ports[length]);
  44. lengthabs += leng2;
  45. leng2 = 0;
  46. length++;
  47. }
  48. length += lengthabs;
  49. // printf("JNI: Counted serial ports...\n");
  50. string = (char *)malloc((length + 1) * sizeof(char));
  51. if (string == NULL) {
  52. // printf("JNI: Not enough memory!\n");
  53. return (*env)->NewStringUTF(env, NULL);
  54. }
  55. length = 0;
  56. lengthabs = 0;
  57. while (ports[length] != NULL) {
  58. leng2 = 0;
  59. while (ports[length][leng2] != '\0') {
  60. string[lengthabs++] = ports[length][leng2++];
  61. }
  62. string[lengthabs++] = '\n';
  63. length++;
  64. }
  65. string[lengthabs] = '\0';
  66. jstring ret = (*env)->NewStringUTF(env, string);
  67. return ret;
  68. }
  69. JNIEXPORT jshortArray JNICALL Java_HelperUtility_readData(JNIEnv *env, jclass class, jint length) {
  70. return NULL;
  71. }
  72. JNIEXPORT void JNICALL Java_HelperUtility_writeData(JNIEnv *env, jclass class, jshortArray data, jint length) {
  73. return;
  74. }