Android App für SRCP gesteuerte Modelleisenbahnen
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

142 satır
3.9KB

  1. package de.erich.railcontrol;
  2. import android.widget.Toast;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. public class zug {
  6. int adresse;
  7. int direction;
  8. int speed;
  9. String name;
  10. int maxspeed;
  11. boolean initialized;
  12. boolean firstTime;
  13. int funktion_1;
  14. int funktion_2;
  15. int funktion_3;
  16. int funktion_4;
  17. public zug(int adresse, String name, int maxspeed) {
  18. this.adresse = adresse;
  19. this.name = name;
  20. this.maxspeed = maxspeed;
  21. this.initialized = false;
  22. firstTime = true;
  23. }
  24. public zug() {
  25. this.initialized = false;
  26. firstTime = true;
  27. }
  28. public boolean initZug() {
  29. if(btn_listeners.client == null) {
  30. if(firstTime) {
  31. Toast.makeText(Lok1.btn_richtung.getContext(), "Noch nicht verbunden!", Toast.LENGTH_SHORT).show();
  32. firstTime = false;
  33. }
  34. return false;
  35. }
  36. try {
  37. btn_listeners.client.sendMessage("INIT 1 GL " + this.adresse + " N 1 " + maxspeed +" 4");
  38. initialized = true;
  39. return true;
  40. } catch (IOException e) {
  41. e.printStackTrace();
  42. return false;
  43. }
  44. }
  45. public void setSpeed(int speed) {
  46. if(!(this.initialized)) {
  47. if(!(this.initZug())) {
  48. return;
  49. }
  50. }
  51. try {
  52. btn_listeners.client.sendMessage("SET 1 GL " + this.adresse + " " + this.direction + " " + speed + " " + maxspeed + " " + funktion_1 + " "+ funktion_2 + " "+ funktion_3 + " " + funktion_4);
  53. this.speed = speed;
  54. } catch (IOException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58. public void setDirection(int direction) {
  59. this.direction = direction;
  60. }
  61. public int changeDirection() {
  62. if(!(this.initialized)) {
  63. if(!(this.initZug())) {
  64. return this.direction;
  65. }
  66. }
  67. if(this.direction == 0) {
  68. this.direction = 1;
  69. }
  70. else if(this.direction == 1) {
  71. this.direction = 0;
  72. }
  73. if(this.speed == 0) {
  74. try {
  75. btn_listeners.client.sendMessage("SET 1 GL " + this.adresse + " " + this.direction + " 0 28 " + funktion_1 + " "+ funktion_2 + " "+ funktion_3 + " " + funktion_4);
  76. } catch (IOException e) {
  77. e.printStackTrace();
  78. }
  79. } else {
  80. Lok1.speed.setProgress(0);
  81. }
  82. return this.direction;
  83. }
  84. public void setFunction(int function, int status) {
  85. if(!(this.initialized)) {
  86. if(!(this.initZug())) {
  87. return;
  88. }
  89. }
  90. switch(function) {
  91. case 1:
  92. funktion_1 = status;
  93. break;
  94. case 2:
  95. funktion_2 = status;
  96. break;
  97. case 3:
  98. funktion_3 = status;
  99. break;
  100. case 4:
  101. funktion_4 = status;
  102. break;
  103. }
  104. try {
  105. btn_listeners.client.sendMessage("SET 1 GL " + this.adresse + " " + this.direction + " " + this.speed + " " + maxspeed + " " + funktion_1 + " "+ funktion_2 + " "+ funktion_3 + " " + funktion_4);
  106. } catch (IOException e) {
  107. e.printStackTrace();
  108. }
  109. }
  110. public void printConfiguration(FileWriter outStream) throws IOException {
  111. outStream.write("<Lok\n");
  112. outStream.write("\tname:\t" + name + "\n\tadresse:\t" + adresse + "\n");
  113. outStream.write("\tmaxspeed:\t" + maxspeed + "\n");
  114. outStream.write("/>\n");
  115. }
  116. public void setProperty(String[] words) {
  117. if ( words[1].equalsIgnoreCase("name:")) name = words[2];
  118. else if (words[1].equalsIgnoreCase("adresse:"))
  119. adresse = Integer.parseInt(words[2]);
  120. else if (words[1].equalsIgnoreCase("maxspeed:"))
  121. maxspeed = Integer.parseInt(words[2]);
  122. }
  123. }