Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. // Pawel Miron , Mateusz Bucko, projekt 1
  2.  
  3. byte handle = 0; // file handle
  4. #define FILE_NAME "scannerdata15.dat"
  5. // The file size is made small so it will fill up quickly.
  6. #define FILE_SIZE 10024
  7.  
  8. void rtn_code_out(const unsigned int code)
  9. {
  10. TextOut(0, LCD_LINE2, "code ");
  11. TextOut(50, LCD_LINE2, FormatNum("%04x", code));
  12. }
  13.  
  14. void shutdown(const int delay)
  15. {
  16. if (handle) CloseFile(handle);
  17. // Get user's attention.
  18. //PlayTone(TONE_C5, SEC_1);
  19. // Give the user time to read screen messages.
  20. Wait(200);
  21. Stop(true);
  22. }
  23.  
  24. void open_for_write()
  25. {
  26. unsigned int file_size = FILE_SIZE;
  27. handle = 0;
  28. // Start with the assumptions the file doesn't exist and needs to be created.
  29. unsigned int rtn_code = CreateFile(FILE_NAME, file_size, handle);
  30. // If the file already exists, open it with the intent of adding to the data
  31. // that is already there.
  32. if (rtn_code == LDR_FILEEXISTS)
  33. rtn_code = OpenFileAppend(FILE_NAME, file_size, handle);
  34. // Return code handling
  35. switch (rtn_code)
  36. {
  37. case LDR_SUCCESS:
  38. return;
  39. case LDR_FILEISFULL:
  40. TextOut(0, LCD_LINE1, "file is full ");
  41. break;
  42. default:
  43. // Unanticipated exception.
  44. TextOut(0, LCD_LINE1, "write open ");
  45. rtn_code_out(rtn_code);
  46. break;
  47. }
  48. }
  49.  
  50. void write_recd(const int recd)
  51. {
  52. unsigned int cnt = 8;
  53. string str = NumToStr(recd);
  54. unsigned int rtn_code = WriteLnString(handle, str, cnt);
  55. // Return code handling
  56. if (rtn_code != LDR_SUCCESS)
  57. {
  58. switch (rtn_code)
  59. {
  60. case LDR_EOFEXPECTED:
  61. TextOut(0, LCD_LINE1, "no more space ");
  62. break;
  63. default:
  64. // Unanticipated exception.
  65. TextOut(0, LCD_LINE1, "write failed ");
  66. rtn_code_out(rtn_code);
  67. break;
  68. }
  69. shutdown(SEC_8);
  70. }
  71. }
  72.  
  73. void clearLcd() {
  74. ClearLine(LCD_LINE3);
  75. ClearLine(LCD_LINE4);
  76. ClearLine(LCD_LINE5);
  77. ClearLine(LCD_LINE6);
  78. }
  79. int lastLastValue = 0;
  80. int lastValue = 0;
  81. int numberOfLines = 0;
  82. int growing = 0;
  83. void scan() {
  84. clearLcd();
  85. int raw[4];
  86. int ex[4];
  87. int raw2[4];
  88. int norm[4];
  89. int scaled[4];
  90. ReadSensorColorRaw(IN_1, raw); // 0, 1024
  91. ReadSensorColorEx(IN_1, ex, raw2, norm, scaled);
  92. if(lastValue - norm[0] > 10 || lastValue - norm[0] < -10) {
  93. lastLastValue = lastValue;
  94. lastValue = norm[0];
  95. }
  96. if (growing == 0) {
  97. if (lastValue< lastLastValue) {
  98. growing=1;
  99. numberOfLines++;
  100. }
  101. } else {
  102. if (lastValue> lastLastValue) {
  103. growing=0;
  104. numberOfLines++;
  105. }
  106. }
  107. TextOut(0, LCD_LINE6, "L"); //ight intensity
  108. NumOut(50, LCD_LINE6,lastValue);
  109. write_recd(lastValue);
  110. write_recd(numberOfLines);
  111. //TextOut(0, LCD_LINE6, "L"); //ight intensity
  112. //NumOut(50, LCD_LINE6,norm[0]);
  113. //write_recd(norm[0]);
  114. }
  115.  
  116. task engine() {
  117. while(true) {
  118. //RotateMotor(OUT_A, 10, 5);
  119. OnFwd(OUT_A, 10);
  120. }
  121. }
  122.  
  123. task scanner() {
  124. while(true) {
  125. scan();
  126. //Wait(1000);
  127. }
  128. }
  129.  
  130. //135 pomiarow / 1s
  131. task timer() {
  132. long time = CurrentTick();
  133. long endt = 12000;
  134. while(CurrentTick() - time < endt);
  135. shutdown(SEC_8);
  136. }
  137.  
  138. task main()
  139. {
  140. open_for_write();
  141. //SetSensor(IN_1, SENSOR_COLORFULL); // rgb
  142.  
  143. SetSensorColorFull(IN_1);
  144.  
  145. Precedes(engine, scanner, timer);
  146. TextOut(0, LCD_LINE1, "Linie");
  147. NumOut(50, LCD_LINE2, numberOfLines);
  148. //Wait(20000);
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement