Browse Source

new cli option -i to print bmp file info

T. Meissner 6 years ago
parent
commit
9be8fc37aa
2 changed files with 22 additions and 19 deletions
  1. 21
    18
      st7565-lcd/raspilcd.adb
  2. 1
    1
      st7565-lcd/st7565lcd.ads

+ 21
- 18
st7565-lcd/raspilcd.adb View File

@@ -16,7 +16,6 @@
16 16
 
17 17
 
18 18
 
19
-with Ada.Text_IO;
20 19
 with bcm2835_h;
21 20
 with st7565lcd;
22 21
 
@@ -34,7 +33,6 @@ procedure raspilcd is
34 33
 
35 34
 
36 35
     -- shorter names for packages
37
-    package IO  renames Ada.Text_IO;
38 36
     package LCD renames st7565lcd;
39 37
     package IOS renames Ada.Streams.Stream_IO;
40 38
 
@@ -49,20 +47,22 @@ procedure raspilcd is
49 47
     lcd_data : LCD.t_lcd_array;
50 48
 
51 49
     -- exception handling
52
-    cli_exception : exception;
50
+    cli_exception     : exception;
53 51
 
54 52
 
55 53
 begin
56 54
 
57 55
 
58
-    -- no picture given
59
-    if Argument_Count /= 1 then
56
+    -- command line argument error
57
+    if Argument_Count = 0 or Argument_Count > 2 or
58
+       (Argument_Count = 1 and Argument(1)  = "-i") or
59
+       (Argument_Count = 2 and Argument(1) /= "-i")  then
60 60
         raise cli_exception;
61 61
     end if;
62 62
 
63 63
     -- open picture file
64 64
     declare
65
-        filename : string := Argument(1);
65
+        filename : string := Argument(Argument_Count);
66 66
     begin
67 67
         IOS.Open(My_File, IOS.In_File, filename);
68 68
         My_File_Access := IOS.Stream(My_File);
@@ -71,10 +71,13 @@ begin
71 71
     -- read in picture
72 72
     LCD.read_bmp(file => My_File, file_access => My_File_Access, bmp_picture => bmp_picture);
73 73
 
74
-    --Put_Line("Width:       " & Integer'Image(picture_header.biWidth));
75
-    --Put_Line("Height:      " & Integer'Image(picture_header.biHeight));
76
-    --Put_Line("Color Depth: " & Integer'Image(Integer(picture_header.biBitCount)));
77
-    --Put_Line("Compression: " & Integer'Image(Integer(picture_header.biCompression)));
74
+    -- print bmp header info
75
+    if Argument(1) = "-i" then
76
+        put_Line("  width:       " & Integer'Image(bmp_picture.header.biWidth));
77
+        put_Line("  height:      " & Integer'Image(bmp_picture.header.biHeight));
78
+        put_Line("  color depth: " & Integer'Image(Integer(bmp_picture.header.biBitCount)));
79
+        put_Line("  compression: " & Integer'Image(Integer(bmp_picture.header.biCompression)));
80
+    end if;
78 81
 
79 82
     -- close picture file
80 83
     Ada.Streams.Stream_IO.Close(My_File);
@@ -85,11 +88,7 @@ begin
85 88
 
86 89
     -- load bcm2835 lib
87 90
     -- print picture and some text on lcd
88
-    if integer(bcm2835_h.bcm2835_init) = 0 then
89
-
90
-        IO.Put_Line("Error while initializing BCM2835 library");
91
-    
92
-    else
91
+    if integer(bcm2835_h.bcm2835_init) /= 0 then
93 92
 
94 93
         LCD.io_init;
95 94
  
@@ -106,7 +105,7 @@ begin
106 105
 
107 106
         -- close library
108 107
         if integer(bcm2835_h.bcm2835_close) = 0 then
109
-            IO.Put_Line("Error while closing BCM2835 library");
108
+            put_line("Error while closing BCM2835 library");
110 109
         end if;
111 110
 
112 111
     end if;
@@ -114,15 +113,19 @@ begin
114 113
 
115 114
     -- exception handling
116 115
     exception
117
-        when cli_exception =>
116
+        when cli_exception | CONSTRAINT_ERROR =>
118 117
             put_line(LCD.exception_head);
119
-            put_line("usage: ./raspitest BMP-FILE (as root)");
118
+            put_line("usage: ./raspilcd [option] BMP-FILE (as root)");
119
+            put_line("   -i: show bmp info");
120 120
         when LCD.bmp_exception =>
121 121
             put_line(LCD.exception_head);
122 122
             put_line("error: malformed BMP-FILE (valid: 128x64, no compression, 32bpp)");
123 123
         when LCD.mask_exception =>
124 124
             put_line(LCD.exception_head);
125 125
             put_line("error: malformed BMP color mask");
126
+        when NAME_ERROR =>
127
+            put_line(LCD.exception_head);
128
+            put_line("error: Could not find bmp file");
126 129
 
127 130
 
128 131
 end raspilcd;

+ 1
- 1
st7565-lcd/st7565lcd.ads View File

@@ -274,7 +274,7 @@ package st7565lcd is
274 274
     mask_exception : exception;
275 275
     bmp_exception  : exception;
276 276
 
277
-    exception_head : string := "raspi-lcd version 0.1, (c) 2014 by tmeissner";
277
+    exception_head : string := "raspilcd version 0.1.1, (c) 2014 by tmeissner";
278 278
 
279 279
 
280 280
     -- procedure declarations