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.

AFrame.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * AFrame.java
  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. import java.util.Arrays;
  24. /**
  25. * The representation of a single frame. Contains the data of all 512 LEDs in a
  26. * given time.
  27. *
  28. * @author Thomas Buck
  29. * @author Max Nuding
  30. * @author Felix Bäder
  31. * @version 1.0
  32. */
  33. public class AFrame implements Comparable<AFrame> {
  34. private short[] data = new short[64];
  35. private short duration = 1;
  36. private String name = "Frame";
  37. private int order;
  38. private static int orderIndex = 0;
  39. /**
  40. * Compare this frame to another frame.
  41. * Compares the order in the frame list.
  42. * @return 0 if equal, -1 if this one comes first, 1 if last
  43. */
  44. public int compareTo(AFrame compareFrame) {
  45. if (getOrder() < compareFrame.getOrder()) {
  46. return -1;
  47. } else if (getOrder() == compareFrame.getOrder()) {
  48. return 0;
  49. } else {
  50. return 1;
  51. }
  52. }
  53. /**
  54. * Get index of frame in list of frames.
  55. * @return index
  56. */
  57. public int getOrder() {
  58. return order;
  59. }
  60. /**
  61. * Set index of frame in list of frames.
  62. * @param newOrder new index
  63. */
  64. public void setOrder(int newOrder) {
  65. order = newOrder;
  66. }
  67. /**
  68. * Inserts frane at end of frame list.
  69. */
  70. public AFrame() {
  71. order = orderIndex++;
  72. }
  73. /**
  74. * Gets the Name of this Frame
  75. *
  76. * @return Name of the Frame
  77. */
  78. public String getName() {
  79. return name + " (" + order + ")";
  80. }
  81. /**
  82. * Sets the Name of this Frame
  83. *
  84. * @param s New Name
  85. */
  86. public void setName(String s) {
  87. name = s;
  88. }
  89. /**
  90. * Sets the Data of this Frame
  91. *
  92. * @param d 64 bytes that contain data (8 bit per byte, so 8 LEDs)
  93. */
  94. public void setData(short[] d) {
  95. for (int i = 0; i < 64; i++) {
  96. data[i] = d[i];
  97. }
  98. }
  99. /**
  100. * Gets tha Data of this Frame
  101. *
  102. * @return 64 bytes that contain data (8 bits / LEDs per byte)
  103. */
  104. public short[] getData() {
  105. return data;
  106. }
  107. /**
  108. * Sets the Duration of this Frame
  109. *
  110. * @param t Duration of frame in (( t * (1/24) ) + (1/24)) seconds
  111. */
  112. public void setTime(short t) {
  113. duration = t;
  114. }
  115. /**
  116. * Gets the Duration of this Frame
  117. *
  118. * @return Duration of frame.
  119. * @see AFrame#setTime(short) setTime()
  120. */
  121. public short getTime() {
  122. return duration;
  123. }
  124. /**
  125. * Gets the Data of the Layer you want
  126. *
  127. * @param i Number of Layer you want
  128. * @return 8 byte array with data of selected layer
  129. */
  130. public short[] getLayer(int i) {
  131. return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
  132. }
  133. }