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.

131 lines
3.8 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. -- raspilcd, a simple tool to display bmp pictures & text on a ST7565 LCD
  2. -- Copyright (C) 2014 Torsten Meissner
  3. --
  4. -- This program is free software: you can redistribute it and/or modify
  5. -- it under the terms of the GNU General Public License as published by
  6. -- the Free Software Foundation, either version 3 of the License, or
  7. -- (at your option) any later version.
  8. --
  9. -- This program is distributed in the hope that it will be useful,
  10. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. -- GNU General Public License for more details.
  13. --
  14. -- You should have received a copy of the GNU General Public License
  15. -- along with this program. If not, see http://www.gnu.org/licenses/.
  16. with bcm2835_h;
  17. with st7565lcd;
  18. with Interfaces;
  19. use Interfaces;
  20. with Ada.Text_IO;
  21. use Ada.Text_IO;
  22. with Ada.Streams.Stream_IO;
  23. with Ada.Command_Line;
  24. use Ada.Command_Line;
  25. procedure raspilcd is
  26. -- shorter names for packages
  27. package LCD renames st7565lcd;
  28. package IOS renames Ada.Streams.Stream_IO;
  29. -- stream.io definitions
  30. My_File : IOS.FILE_TYPE;
  31. My_File_Access : IOS.STREAM_ACCESS;
  32. -- picture data
  33. bmp_picture : LCD.t_bmp_picture;
  34. -- lcd pixel array
  35. lcd_data : LCD.t_lcd_array;
  36. -- exception handling
  37. cli_exception : exception;
  38. begin
  39. -- command line argument error
  40. if Argument_Count = 0 or Argument_Count > 2 or
  41. (Argument_Count = 1 and Argument(1) = "-i") or
  42. (Argument_Count = 2 and Argument(1) /= "-i") then
  43. raise cli_exception;
  44. end if;
  45. -- open picture file
  46. declare
  47. filename : string := Argument(Argument_Count);
  48. begin
  49. IOS.Open(My_File, IOS.In_File, filename);
  50. My_File_Access := IOS.Stream(My_File);
  51. end;
  52. -- read in picture
  53. LCD.read_bmp(file => My_File, file_access => My_File_Access, bmp_picture => bmp_picture);
  54. -- print bmp header info
  55. if Argument(1) = "-i" then
  56. put_Line(" width: " & Integer'Image(bmp_picture.header.biWidth));
  57. put_Line(" height: " & Integer'Image(bmp_picture.header.biHeight));
  58. put_Line(" color depth: " & Integer'Image(Integer(bmp_picture.header.biBitCount)));
  59. put_Line(" compression: " & Integer'Image(Integer(bmp_picture.header.biCompression)));
  60. end if;
  61. -- close picture file
  62. Ada.Streams.Stream_IO.Close(My_File);
  63. -- convert bmp to lcd matrix
  64. lcd_data := LCD.bmp_to_lcd(bmp_picture);
  65. -- load bcm2835 lib
  66. -- print picture and some text on lcd
  67. if integer(bcm2835_h.bcm2835_init) /= 0 then
  68. LCD.io_init;
  69. LCD.lcd_init;
  70. LCD.lcd_picture(xpos => 0, ypos => 0, picture => lcd_data);
  71. --bcm2835_h.bcm2835_delay(5000);
  72. --LCD.lcd_clear;
  73. --LCD.lcd_ascii57_string(xpos => 0, ypos => 0, data => "raspiFPGA 0.1");
  74. --LCD.lcd_ascii57_string(xpos => 0, ypos => 1, data => "(c) raspiDEV 2013");
  75. -- close library
  76. if integer(bcm2835_h.bcm2835_close) = 0 then
  77. put_line("Error while closing BCM2835 library");
  78. end if;
  79. end if;
  80. -- exception handling
  81. exception
  82. when cli_exception | CONSTRAINT_ERROR =>
  83. put_line(LCD.exception_head);
  84. put_line("usage: ./raspilcd [option] BMP-FILE (as root)");
  85. put_line(" -i: show bmp info");
  86. when LCD.bmp_exception =>
  87. put_line(LCD.exception_head);
  88. put_line("error: malformed BMP-FILE (valid: 128x64, no compression, 32bpp)");
  89. when LCD.mask_exception =>
  90. put_line(LCD.exception_head);
  91. put_line("error: malformed BMP color mask");
  92. when NAME_ERROR =>
  93. put_line(LCD.exception_head);
  94. put_line("error: Could not find bmp file");
  95. end raspilcd;