From db3357a89a61214acf7eb3653d36924f6367cdf1 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Sun, 26 Jan 2014 20:58:30 +0100 Subject: [PATCH] more exceptions; code simplified because of moving bmp-image read and check into new procedure read_bmp() --- st7565-lcd/raspilcd.adb | 107 ++++++++++------------------------------ 1 file changed, 27 insertions(+), 80 deletions(-) diff --git a/st7565-lcd/raspilcd.adb b/st7565-lcd/raspilcd.adb index b403e25..5bcf1a1 100644 --- a/st7565-lcd/raspilcd.adb +++ b/st7565-lcd/raspilcd.adb @@ -1,29 +1,15 @@ --- raspilcd, a simple tool to display bmp pictures & text on a ST7565 LCD --- Copyright (C) 2014 Torsten Meissner --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation, either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see http://www.gnu.org/licenses/. - - - with Ada.Text_IO; with bcm2835_h; with st7565lcd; -with Interfaces; use Interfaces; -with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO; -use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO; -with Ada.Command_Line; use Ada.Command_Line; +with Interfaces; +use Interfaces; +with Ada.Text_IO; +use Ada.Text_IO; +with Ada.Streams.Stream_IO; +with Ada.Command_Line; +use Ada.Command_Line; + procedure raspilcd is @@ -39,19 +25,13 @@ procedure raspilcd is My_File_Access : IOS.STREAM_ACCESS; -- picture data - picture_header : LCD.t_bmp_header; - color_mask : LCD.t_color_mask; - picture_data : LCD.t_bmp_array (0 .. 128 * 64 - 1); + bmp_picture : LCD.t_bmp_picture; -- lcd pixel array lcd_data : LCD.t_lcd_array; -- exception handling - tool_info : string := "raspi-lcd version 0.1, (c) 2014 by tmeissner"; - usage : string := "usage: ./raspitest BMP-FILE (as root)"; - bmp_error : string := "error: malformed BMP-FILE (valid: 128x64, no compression, 32bpp)"; cli_exception : exception; - bmp_exception : exception; begin @@ -64,61 +44,25 @@ begin -- open picture file declare - filename : string := Argument (1); + filename : string := Argument(1); begin - IOS.Open(My_File, In_File, filename); + IOS.Open(My_File, IOS.In_File, filename); My_File_Access := IOS.Stream(My_File); end; - - -- read bmp header - LCD.t_bmp_header'Read(My_File_Access, picture_header); + -- read in picture + LCD.read_bmp(file => My_File, file_access => My_File_Access, bmp_picture => bmp_picture); --Put_Line("Width: " & Integer'Image(picture_header.biWidth)); --Put_Line("Height: " & Integer'Image(picture_header.biHeight)); --Put_Line("Color Depth: " & Integer'Image(Integer(picture_header.biBitCount))); --Put_Line("Compression: " & Integer'Image(Integer(picture_header.biCompression))); - -- check for valid bmp format - if (abs picture_header.biHeight /= 64 or picture_header.biWidth /= 128 or - (picture_header.biCompression /= 0 and picture_header.biCompression /= 3) or - picture_header.biBitCount /= 32) then - raise bmp_exception; - end if; - - -- get color map if existing - if picture_header.biCompression = 3 then - LCD.t_color_mask'Read(My_File_Access, color_mask); - end if; - - -- read in image data - if picture_header.biHeight < 0 then - - -- top-down pixel matrix - for index in picture_data'range loop - if not IOS.End_Of_File(My_File) then - LCD.t_byte_array'Read(My_File_Access, picture_data(index)); - end if; - end loop; - - else - - -- bottom-top pixel matrix - for row in reverse 0 .. 63 loop - for column in 0 .. 127 loop - if not IOS.End_Of_File(My_File) then - LCD.t_byte_array'Read(My_File_Access, picture_data(row * 128 + column)); - end if; - end loop; - end loop; - - end if; - -- close picture file Ada.Streams.Stream_IO.Close(My_File); -- convert bmp to lcd matrix - lcd_data := LCD.bmp_to_lcd(bmp => picture_data, color_mask => color_mask); + lcd_data := LCD.bmp_to_lcd(bmp_picture); -- load bcm2835 lib @@ -135,12 +79,12 @@ begin LCD.lcd_picture(xpos => 0, ypos => 0, picture => lcd_data); - bcm2835_h.bcm2835_delay(5000); + --bcm2835_h.bcm2835_delay(5000); - LCD.lcd_clear; + --LCD.lcd_clear; - LCD.lcd_ascii57_string(xpos => 0, ypos => 0, data => "raspiFPGA 0.1"); - LCD.lcd_ascii57_string(xpos => 0, ypos => 1, data => "(c) raspiDEV 2013"); + --LCD.lcd_ascii57_string(xpos => 0, ypos => 0, data => "raspiFPGA 0.1"); + --LCD.lcd_ascii57_string(xpos => 0, ypos => 1, data => "(c) raspiDEV 2013"); -- close library if integer(bcm2835_h.bcm2835_close) = 0 then @@ -152,12 +96,15 @@ begin -- exception handling exception - when e: cli_exception => - put_line(tool_info); - put_line(usage); - when e: bmp_exception => - put_line(tool_info); - put_line(bmp_error); + when cli_exception => + put_line(LCD.exception_head); + put_line("usage: ./raspitest BMP-FILE (as root)"); + when LCD.bmp_exception => + put_line(LCD.exception_head); + put_line("error: malformed BMP-FILE (valid: 128x64, no compression, 32bpp)"); + when LCD.mask_exception => + put_line(LCD.exception_head); + put_line("error: malformed BMP color mask"); end raspilcd;