Simple single-color 8x8x8 LED Cube with AVRs
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * mem.c - HardwareEmulator
  3. * frame is represented as 65 bytes.
  4. * 0 - 63: frame data
  5. * 64: duration, 0 => 1/24th second
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "mem.h"
  11. char *mem = NULL;
  12. int frameCount = 0;
  13. // return != 0 if error
  14. int addFrame(char *frame) {
  15. char *newMem;
  16. if (mem != NULL) {
  17. newMem = (char *)malloc(65 * (frameCount + 1));
  18. if (newMem == NULL) {
  19. return 1;
  20. }
  21. memcpy(newMem, mem, 65 * frameCount); // Copy old frames
  22. free(mem);
  23. } else {
  24. frameCount = 0;
  25. newMem = (char *)malloc(65 * (frameCount + 1));
  26. if (newMem == NULL) {
  27. return 1;
  28. }
  29. }
  30. memcpy((newMem + (65 * frameCount)), frame, 65); // Add new frame
  31. frameCount++;
  32. mem = newMem;
  33. return 0;
  34. }
  35. // returns NULL if error
  36. char *getFrame(int index) {
  37. if (index >= frameCount) {
  38. return NULL;
  39. } else if (mem == NULL) {
  40. return NULL;
  41. } else {
  42. return (mem + (65 * index));
  43. }
  44. }
  45. int framesStored() {
  46. return frameCount;
  47. }
  48. void clearMemory() {
  49. free(mem);
  50. mem = NULL;
  51. frameCount = 0;
  52. }