avrada_examples_1.0.1_72780c76/DHT/dht-images.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---------------------------------------------------------------------------
-- The AVR-Ada Library is free software;  you can redistribute it and/or --
-- modify it under terms of the  GNU General Public License as published --
-- by  the  Free Software  Foundation;  either  version 2, or  (at  your --
-- option) any later version.  The AVR-Ada Library 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.         --
--                                                                       --
-- As a special exception, if other files instantiate generics from this --
-- unit,  or  you  link  this  unit  with  other  files  to  produce  an --
-- executable   this  unit  does  not  by  itself  cause  the  resulting --
-- executable to  be  covered by the  GNU General  Public License.  This --
-- exception does  not  however  invalidate  any  other reasons why  the --
-- executable file might be covered by the GNU Public License.           --
---------------------------------------------------------------------------

with Ada.Unchecked_Conversion;
with Interfaces;                   use Interfaces;
with AVR.Strings;                  use AVR.Strings;
with AVR.Int_Img;                  use AVR.Int_Img;

package body DHT.Images is

   --  temperature range is -40.0 .. 125.0, humidity range is 0.0
   --  .. 100.0.  Both functions return a right adjusted textual
   --  representation with one decimal digit.

   function Image (Value : DHT_Temperature) return AStr5
   is
      function To_H is
         new Ada.Unchecked_Conversion (Source => DHT_Temperature,
                                       Target => DHT_Humidity);
   begin
      return Image(To_H(Value));
   end Image;


   function Image (Value : DHT_Humidity) return AStr5
   is
      function "+" is
         new Ada.Unchecked_Conversion (Source => DHT_Humidity,
                                       Target => Unsigned_16);
      Result : AStr5;
      Val_U16 : constant Unsigned_16 := +Value;
   begin
      U16_Img_Right (Val_U16, Result);
      for I in Unsigned_8'(2) .. 4 loop
         Result(I-1) := Result(I);
      end loop;
      Result(4) := '.';
      return Result;
   end Image;

end DHT.Images;