Skip to content

Commit 0ace79c

Browse files
pat-rogersjklmnn
authored andcommitted
simplify implementation of Get_Accelerations
1 parent 1b562e7 commit 0ace79c

1 file changed

Lines changed: 11 additions & 29 deletions

File tree

components/src/motion/lis3dsh/lis3dsh.adb

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
------------------------------------------------------------------------------
22
-- --
3-
-- Copyright (C) 2015-2016, AdaCore --
3+
-- Copyright (C) 2015-2026, AdaCore --
44
-- --
55
-- Redistribution and use in source and binary forms, with or without --
66
-- modification, are permitted provided that the following conditions are --
@@ -41,7 +41,6 @@
4141
------------------------------------------------------------------------------
4242

4343
with Ada.Unchecked_Conversion;
44-
with System;
4544
with Interfaces; use Interfaces;
4645

4746
package body LIS3DSH is
@@ -111,16 +110,12 @@ package body LIS3DSH is
111110
Axes : out Axes_Accelerations)
112111
is
113112

114-
Buffer : array (0 .. 5) of UInt8 with Alignment => 2, Size => 48;
115-
Scaled : Float;
113+
type Device_Data is array (0 .. 5) of UInt8 with Alignment => 2, Size => 48;
116114

117-
type Integer16_Pointer is access all Integer_16
118-
with Storage_Size => 0;
115+
Buffer : Device_Data;
119116

120-
function As_Pointer is new Ada.Unchecked_Conversion
121-
(Source => System.Address, Target => Integer16_Pointer);
122-
-- So that we can treat the address of a UInt8 as a pointer to a two-UInt8
123-
-- sequence representing a signed Integer_16 quantity
117+
function As_Axes_Accelerations is new Ada.Unchecked_Conversion
118+
(Source => Device_Data, Target => Axes_Accelerations);
124119

125120
begin
126121
This.Loc_IO_Read (Buffer (0), OUT_X_L);
@@ -130,26 +125,13 @@ package body LIS3DSH is
130125
This.Loc_IO_Read (Buffer (4), OUT_Z_L);
131126
This.Loc_IO_Read (Buffer (5), OUT_Z_H);
132127

133-
Get_X : declare
134-
Raw : Integer_16 renames As_Pointer (Buffer (0)'Address).all;
128+
Scale_Them : declare
129+
Raw : Axes_Accelerations renames As_Axes_Accelerations (Buffer);
135130
begin
136-
Scaled := Float (Raw) * This.Sensitivity;
137-
Axes.X := Axis_Acceleration (Scaled);
138-
end Get_X;
139-
140-
Get_Y : declare
141-
Raw : Integer_16 renames As_Pointer (Buffer (2)'Address).all;
142-
begin
143-
Scaled := Float (Raw) * This.Sensitivity;
144-
Axes.Y := Axis_Acceleration (Scaled);
145-
end Get_Y;
146-
147-
Get_Z : declare
148-
Raw : Integer_16 renames As_Pointer (Buffer (4)'Address).all;
149-
begin
150-
Scaled := Float (Raw) * This.Sensitivity;
151-
Axes.Z := Axis_Acceleration (Scaled);
152-
end Get_Z;
131+
Axes.X := Axis_Acceleration (Float (Raw.X) * This.Sensitivity);
132+
Axes.Y := Axis_Acceleration (Float (Raw.Y) * This.Sensitivity);
133+
Axes.Z := Axis_Acceleration (Float (Raw.Z) * This.Sensitivity);
134+
end Scale_Them;
153135
end Get_Accelerations;
154136

155137
---------------

0 commit comments

Comments
 (0)