Guest User

Untitled

a guest
May 27th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 5.87 KB | None | 0 0
  1. pragma Task_Dispatching_Policy(FIFO_Within_Priorities);
  2. pragma Locking_Policy(Ceiling_Locking);
  3.  
  4. with Ada.Text_IO;               use Ada.Text_IO;
  5. with Ada.Integer_Text_IO;       use Ada.Integer_Text_IO;
  6. with Pendulum_IO_Sim;           use Pendulum_IO_Sim;
  7. with Chars_8x5;                 use Chars_8x5;
  8. with Low_Level_Types;           use Low_Level_Types;
  9. with Ada.Real_Time;             use Ada.Real_Time;
  10. with Pendulum_State_T;          use Pendulum_State_T;
  11. with System;
  12.  
  13. procedure Pendulum is
  14.         task Pendulum_Input is
  15.                 pragma Priority(System.Priority'Last-1);
  16.         end Pendulum_Input;
  17.  
  18.         task Pendulum_Output is
  19.                 pragma Priority(System.Priority'Last-2);
  20.         end Pendulum_Output;
  21.  
  22.         Column_Count: Constant := 12 * 6;
  23.         Margin: Constant := 10;
  24.         Display_Buffer: Array (Byte range 0..Column_Count-1) of Byte;
  25.         Displayed_Text: String := "`Erasmus VLC";
  26.         Sig_Left_Known: Boolean := False;       -- determines of last A is already set
  27.         Display_Reset: Boolean := False;
  28.         P: Pendulum_State;
  29.  
  30.         -- UTILITIES - not used in final version --
  31.         procedure Print_Time (T: Time) is
  32.                 Sec: Seconds_Count;
  33.                 Hnd: Time_Span;
  34.         begin
  35.                 Split (T, Sec, Hnd);
  36.                 Put_Line (Seconds_Count'Image (Sec mod 100) & "+" & Duration'Image (To_Duration (Hnd)));
  37.         end Print_Time;
  38.         procedure Print_Time_Span (T: Time_Span) is
  39.         begin
  40.                 Put_Line (Duration'Image (To_Duration (T)));
  41.         end Print_Time_Span;
  42.  
  43.         -- END OF UTILITIES --
  44.  
  45. ---------------------------------------------------------------------------------------------------
  46.         task body Pendulum_Input is
  47.                 Next: Time := Clock;
  48.                 Period: Time_Span := Microseconds (10);
  49.                 PS: Pendulum_Signals;
  50.         begin
  51.                 loop
  52.                         P.Test_Inputs;
  53.                         PS := P.Get_Pendulum_Signals;
  54.                         P.Reset_Pendulum_Signals;
  55.                         if (PS.Bar_Fall) then
  56.                                 if (PS.Syn) then
  57.                                         -- falling of the Bar+Syn
  58.                                         P.On_Move_Right;
  59.                                         if (Sig_Left_Known) then Display_Reset := True; end if;
  60.                                 else
  61.                                         if (Sig_Left_Known) then
  62.                                                 P.On_Move_Left;
  63.                                         else
  64.                                                 P.On_First_Move_Left;
  65.                                                 Sig_Left_Known := True;
  66.                                         end if;
  67.                                 end if;
  68.                         end if;
  69.  
  70.                         Next := Next + Period;
  71.                         delay until Next;
  72.                 end loop;
  73.         end Pendulum_Input;
  74.  
  75. ---------------------------------------------------------------------------------------------------
  76.         task body Pendulum_Output is
  77.                 Column_Delay: Duration;
  78.                 Pendulum_Reverse: Time;
  79.                 Next: Time;
  80.         begin
  81.                         while (not Display_Reset) loop
  82.                                 delay 0.001;
  83.                         end loop;
  84.                 loop
  85.                         Column_Delay := To_Duration (P.Get_Cycle_Length / (2*(2*Margin + Column_Count)));
  86.                         Set_Leds (0);
  87.                         Pendulum_Reverse := P.Get_Start_Drawing + P.Get_Cycle_Length/2;
  88.                         delay until P.Get_Start_Drawing;
  89.                         Display_Reset := False;
  90.                         -- skip left margin
  91.                         Set_Leds (0);
  92.                         delay until (P.Get_Start_Drawing + To_Time_Span (Column_Delay)*Margin);
  93.  
  94.                         -- draw the image (pendulum going right
  95.                         Next := Clock;
  96.                         for Column in 0..Column_Count-1 loop
  97.                                 Set_Leds ( Display_Buffer (Byte (Column)) );
  98.                                 Next := Next + To_Time_Span (Column_Delay);
  99.                                 delay until Next;
  100.                         end loop;
  101.  
  102.                         -- skip right margin
  103.                         Set_Leds (0);
  104.                         --delay Column_Delay*(2*Margin-1);
  105.                         delay until Pendulum_Reverse;
  106.                         delay until (Pendulum_Reverse + To_Time_Span (Column_Delay) * Margin);
  107.  
  108.                         -- draw the image (pendulum going left)
  109.                         Next := Clock;
  110.                         for Column in 0..Column_Count-1 loop
  111.                                 Set_Leds ( Display_Buffer (Byte (Column_Count-Column-1)) );
  112.                                 Next := Next + To_Time_Span (Column_Delay);
  113.                                 delay until Next;
  114.                         end loop;
  115.                         if (not Display_Reset) then
  116.                                 Reset_Leds;
  117.                                 while (not Display_Reset) loop
  118.                                         delay 0.0001;
  119.                                 end loop;
  120.                                 Next := Clock + To_Time_Span (Column_Delay)*Margin;
  121.                                 delay until Next;
  122.                         end if;
  123.  
  124.                 end loop;
  125.         end Pendulum_Output;
  126.  
  127. ---------------------------------------------------------------------------------------------------
  128. begin
  129.         for i in 0..11 loop
  130.                 for j in 0..4 loop
  131.                         Display_Buffer (Byte(i*6+j)) := Char_Map (Displayed_Text (i+1), j);
  132.                 end loop;
  133.                 Display_Buffer (Byte (i*6+5)) := 0;
  134.         end loop;
  135. end Pendulum;
Add Comment
Please, Sign In to add comment