Various projects using Raspberry Pi
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.

145 lines
3.9 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. with Ada.Text_IO;
  2. with bcm2835_h;
  3. with st7565lcd;
  4. with Interfaces; use Interfaces;
  5. with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO;
  6. use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO;
  7. with Ada.Command_Line; use Ada.Command_Line;
  8. procedure raspilcd is
  9. -- shorter names for packages
  10. package IO renames Ada.Text_IO;
  11. package LCD renames st7565lcd;
  12. package IOS renames Ada.Streams.Stream_IO;
  13. -- stream.io definitions
  14. My_File : IOS.FILE_TYPE;
  15. My_File_Access : IOS.STREAM_ACCESS;
  16. -- picture data
  17. picture_header : LCD.t_bmp_header;
  18. color_mask : LCD.t_color_mask;
  19. picture_data : LCD.t_bmp_array (0 .. 128 * 64 - 1);
  20. -- lcd pixel array
  21. lcd_data : LCD.t_lcd_array;
  22. -- exception handling
  23. tool_info : string := "raspi-lcd version 0.1, (c) 2014 by tmeissner";
  24. usage : string := "usage: ./raspitest BMP-FILE (as root)";
  25. bmp_error : string := "error: malformed BMP-FILE (valid: 128x64, no compression, 32bpp)";
  26. cli_exception : exception;
  27. bmp_exception : exception;
  28. begin
  29. -- no picture given
  30. if Argument_Count /= 1 then
  31. raise cli_exception;
  32. end if;
  33. -- open picture file
  34. declare
  35. filename : string := Argument (1);
  36. begin
  37. IOS.Open(My_File, In_File, filename);
  38. My_File_Access := IOS.Stream(My_File);
  39. end;
  40. -- read bmp header
  41. LCD.t_bmp_header'Read(My_File_Access, picture_header);
  42. --Put_Line("Width: " & Integer'Image(picture_header.biWidth));
  43. --Put_Line("Height: " & Integer'Image(picture_header.biHeight));
  44. --Put_Line("Color Depth: " & Integer'Image(Integer(picture_header.biBitCount)));
  45. --Put_Line("Compression: " & Integer'Image(Integer(picture_header.biCompression)));
  46. -- check for valid bmp format
  47. if (abs picture_header.biHeight /= 64 or picture_header.biWidth /= 128 or
  48. (picture_header.biCompression /= 0 and picture_header.biCompression /= 3) or
  49. picture_header.biBitCount /= 32) then
  50. raise bmp_exception;
  51. end if;
  52. -- get color map if existing
  53. if picture_header.biCompression = 3 then
  54. LCD.t_color_mask'Read(My_File_Access, color_mask);
  55. end if;
  56. -- read in image data
  57. if picture_header.biHeight < 0 then
  58. -- top-down pixel matrix
  59. for index in picture_data'range loop
  60. if not IOS.End_Of_File(My_File) then
  61. LCD.t_byte_array'Read(My_File_Access, picture_data(index));
  62. end if;
  63. end loop;
  64. else
  65. -- bottom-top pixel matrix
  66. for row in reverse 0 .. 63 loop
  67. for column in 0 .. 127 loop
  68. if not IOS.End_Of_File(My_File) then
  69. LCD.t_byte_array'Read(My_File_Access, picture_data(row * 128 + column));
  70. end if;
  71. end loop;
  72. end loop;
  73. end if;
  74. -- close picture file
  75. Ada.Streams.Stream_IO.Close(My_File);
  76. -- convert bmp to lcd matrix
  77. lcd_data := LCD.bmp_to_lcd(bmp => picture_data, color_mask => color_mask);
  78. -- load bcm2835 lib
  79. -- print picture and some text on lcd
  80. if integer(bcm2835_h.bcm2835_init) = 0 then
  81. IO.Put_Line("Error while initializing BCM2835 library");
  82. else
  83. LCD.io_init;
  84. LCD.lcd_init;
  85. LCD.lcd_picture(xpos => 0, ypos => 0, picture => lcd_data);
  86. bcm2835_h.bcm2835_delay(5000);
  87. LCD.lcd_clear;
  88. LCD.lcd_ascii57_string(xpos => 0, ypos => 0, data => "raspiFPGA 0.1");
  89. LCD.lcd_ascii57_string(xpos => 0, ypos => 1, data => "(c) raspiDEV 2013");
  90. -- close library
  91. if integer(bcm2835_h.bcm2835_close) = 0 then
  92. IO.Put_Line("Error while closing BCM2835 library");
  93. end if;
  94. end if;
  95. -- exception handling
  96. exception
  97. when e: cli_exception =>
  98. put_line(tool_info);
  99. put_line(usage);
  100. when e: bmp_exception =>
  101. put_line(tool_info);
  102. put_line(bmp_error);
  103. end raspilcd;