HDLRuby 3.3.3 → 3.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fc400e683cbefc6a77e8e6c4394f67e88df74fccd3bcb4ba420f6babc2542c8
4
- data.tar.gz: e4619579f4ef6703c38cb1ee5cc95197b37b929eb630f93497a4b7bde0a4955f
3
+ metadata.gz: 160a8c6607e6dd20282a50fa26e0d472e055992ebce5f7cdf62d39e8c6bf7db5
4
+ data.tar.gz: 2c44f4edc3e4fdd76d64c2cb349f7083a255b68b1a18c6f41bef77c6d82138ab
5
5
  SHA512:
6
- metadata.gz: 581b6f3029bc63108c0408495dcebaf6305f61697099985c7b2f043f3250d377e5640f0db7305f62ed2a4430f60f6dfc85495a382e84f89a1d595ac5519cebaa
7
- data.tar.gz: 1821cb1ee95bb0abfdfd8d99318b1a5a103baabc3c3d3c58e50cd965f54059d0636b3cd352f1c9e726c7c04d3282f06820896cc9cf74e92b6e7a721bcd254560
6
+ metadata.gz: 234d4901bc7ae389c1e0893ad19a7a2aff93c2bc2851066a80ce07b778787a1fa25950af60dd30d32d7e77a8804f0ef4dbc2c43bdf2f026f7b725cd15a943c84
7
+ data.tar.gz: 774369895db9a9f30b7a85061aba5190d3e45f962f6ca28e2cee7fe77d7c02c049570dd6e2a0f730640f687bc8069f19e433ea6d4bb2f79b6cb7875a6ef423a4
@@ -63,7 +63,8 @@ module HDLRuby::High::Std
63
63
  end
64
64
 
65
65
  ## Class describing a digit display.
66
- DIGIT = Struct.new(:id, :size, :hread) do
66
+ # Need to know the data type since signed is supported.
67
+ DIGIT = Struct.new(:id, :size, :type, :hread) do
67
68
  def to_html
68
69
  return '<div class="digitset" id=' + self.id.to_s +
69
70
  ' data-width="' + self.size.to_s + '" data-value="0" >' +
@@ -559,6 +560,9 @@ Content-Type: text/html
559
560
  const cartouche = document.getElementById("cartouche");
560
561
  const panel = document.getElementById("panel");
561
562
 
563
+ // The current time stamp.
564
+ var time_stamp = 0;
565
+
562
566
  // The input and output elements' ids.
563
567
  const input_ids = [];
564
568
  const output_ids = [];
@@ -689,7 +693,7 @@ Content-Type: text/html
689
693
  function digitset_update(digitset,value) {
690
694
  // Update the digiset value.
691
695
  digitset.dataset.value = value;
692
- // Unsigned case.
696
+ // Update its display.
693
697
  const num = digitset.dataset.width;
694
698
  digitset.lastElementChild.innerHTML = String(value).padStart(num,"\u00A0");
695
699
  }
@@ -704,7 +708,9 @@ Content-Type: text/html
704
708
  }
705
709
 
706
710
  // Update an oscilloscope.
707
- function scope_update(scope,value) {
711
+ function scope_update(scope,value,new_time_stamp) {
712
+ // Compute the advance in time.
713
+ let diff_time_stamp = new_time_stamp - time_stamp;
708
714
  // Get the canvas.
709
715
  const canvas = scope.lastElementChild;
710
716
  // Shall we set up its size?
@@ -775,21 +781,21 @@ Content-Type: text/html
775
781
  // Draw a line to the new position.
776
782
  cxt.beginPath();
777
783
  cxt.moveTo(toPx(pos), toPy(previous));
778
- cxt.lineTo(toPx(pos+1), toPy(value));
784
+ cxt.lineTo(toPx(pos+diff_time_stamp), toPy(value));
779
785
  cxt.stroke();
780
786
  /* Update the values. */
781
787
  scope.dataset.previous = value;
782
- scope.dataset.pos = pos + 1;
788
+ scope.dataset.pos = pos + diff_time_stamp;
783
789
  }
784
790
  }
785
791
 
786
792
  // Update a general display element.
787
- function element_update(element,value) {
793
+ function element_update(element,value,new_time_stamp) {
788
794
  if(element.classList.contains('ledset')) { ledset_update(element,value); }
789
795
  if(element.classList.contains('digitset')){ digitset_update(element,value); }
790
796
  if(element.classList.contains('signedset')){signedset_update(element,value);}
791
797
  if(element.classList.contains('hexaset')) { hexaset_update(element,value); }
792
- if(element.classList.contains('scope')) { scope_update(element,value); }
798
+ if(element.classList.contains('scope')) { scope_update(element,value,new_time_stamp); }
793
799
  }
794
800
 
795
801
 
@@ -799,19 +805,25 @@ Content-Type: text/html
799
805
  xhttp.onreadystatechange = function() {
800
806
  // console.log("response=" + this.responseText);
801
807
  if (this.readyState == 4 && this.status == 200) {
802
- if (/[0-9]+:[0-9]/.test(this.responseText)) {
808
+ if (/^[0-9]+;[0-9]+:-?[0-9]/.test(this.responseText)) {
803
809
  // There is a real response.
804
810
  // Update the interface with the answer.
805
811
  const commands = this.responseText.split(';');
812
+ // Get the new time stamp.
813
+ let new_time_stamp = commands.shift();
814
+ // console.log("new_time_stamp=" + new_time_stamp);
815
+ // Process the other commands.
806
816
  for(command of commands) {
807
817
  const toks = command.split(':');
808
- element_update(document.getElementById(toks[0]),toks[1]);
818
+ element_update(document.getElementById(toks[0]),toks[1],new_time_stamp);
809
819
  }
820
+ // Update the time stamp
821
+ time_stamp = new_time_stamp
810
822
  }
811
823
  }
812
824
  };
813
825
  // Builds the action from the state of the input elements.
814
- act = '';
826
+ let act = '';
815
827
  for(id of input_ids) {
816
828
  act += id + ':' + document.getElementById(id).dataset.value + ';';
817
829
  }
@@ -824,8 +836,9 @@ Content-Type: text/html
824
836
  // First call of synchronisation.
825
837
  hruby_sync();
826
838
 
827
- // Then periodic synchronize.
828
- setInterval(function() { hruby_sync(); }, 100);
839
+ // Moved to the Ruby constructor to allow setting the time intervals.
840
+ // // Then periodic synchronize.
841
+ // setInterval(function() { hruby_sync(); }, 100);
829
842
 
830
843
  </script>
831
844
 
@@ -850,9 +863,14 @@ HTMLRESPONSE
850
863
 
851
864
  # Create a new board named +name+ accessible on HTTP port +http_port+
852
865
  # and whose content is describe in +hdlruby_block+.
853
- def initialize(name, http_port = 8000, &hdlruby_block)
866
+ def initialize(name, http_port: 8000, refresh_rate: 100,
867
+ &hdlruby_block)
854
868
  # Set the name.
855
869
  @name = name.to_s
870
+ # Set the refresh rate.
871
+ @refresh_rate = refresh_rate.to_i
872
+ # Tell the interface is to be built.
873
+ @first = true
856
874
  # Check and set the port.
857
875
  http_port = http_port.to_i
858
876
  if (@@http_ports.include?(http_port)) then
@@ -869,13 +887,17 @@ HTMLRESPONSE
869
887
  # Initialize the list of board elements to empty.
870
888
  @elements = []
871
889
  @out_elements = []
890
+ # Initialize the time stamp.
891
+ @time_stamp = 0
872
892
  # And build the board.
873
893
  # Create the namespace for the program.
874
894
  @namespace = Namespace.new(self)
875
895
  # Build the program object.
876
896
  High.space_push(@namespace)
877
897
  pr = nil
878
- High.top_user.instance_eval { pr = program(:ruby, @name.to_sym) {} }
898
+ High.top_user.instance_eval do
899
+ pr = program(:ruby, @name.to_sym) { }
900
+ end
879
901
  @program = pr
880
902
  # Fill it.
881
903
  High.top_user.instance_eval(&hdlruby_block)
@@ -936,6 +958,7 @@ HTMLRESPONSE
936
958
  # Createthe ui component.
937
959
  @elements << DIGIT.new(@elements.size,
938
960
  Math.log10(2**hport[1].type.width - 1).to_i + (sign ? 2 : 1),
961
+ hport[1].type,
939
962
  hport[0])
940
963
  @out_elements << @elements[-1]
941
964
  end
@@ -1018,9 +1041,13 @@ HTMLRESPONSE
1018
1041
  # Generate a response to a request to the server.
1019
1042
  def make_response(request)
1020
1043
  # puts "request=#{request}"
1021
- if (request.empty?) then
1044
+ if (@first) then
1045
+ @first = false
1022
1046
  # First or re-connection, generate the UI.
1023
- return UI_header + "\n<script>\n" +
1047
+ return UI_header +
1048
+ "\n<script>\n" +
1049
+ "// Then periodic synchronize.\n" +
1050
+ "setInterval(function() { hruby_sync(); }, #{@refresh_rate});\n" +
1024
1051
  "set_cartouche('#{@name}');\n" +
1025
1052
  @elements.map do |elem|
1026
1053
  "add_element('#{elem.to_html}');"
@@ -1030,11 +1057,13 @@ HTMLRESPONSE
1030
1057
  # This should be an AJAX request, process it.
1031
1058
  commands = request.split(";")
1032
1059
  commands.each do |command|
1060
+ next unless command.include?(":")
1033
1061
  id, val = command.split(":").map {|t| t.to_i}
1034
1062
  self.update_port(id,val)
1035
1063
  end
1036
1064
  # And generate the response: an update of each board output element.
1037
- return UI_response + @out_elements.each.map do |e|
1065
+ return UI_response + "#{@time_stamp};" +
1066
+ @out_elements.each.map do |e|
1038
1067
  # puts "resp=" + "#{e.id}:#{RubyHDL.send(e.hread)}"
1039
1068
  "#{e.id}:#{RubyHDL.send(e.hread)}"
1040
1069
  end.join(";")
@@ -1057,6 +1086,8 @@ HTMLRESPONSE
1057
1086
  session.print self.make_response(path[1..-1])
1058
1087
  # And tell the ui has been connected.
1059
1088
  @connected = true
1089
+ # Then advance the time stamp.
1090
+ @time_stamp += 1
1060
1091
  else
1061
1092
  session.print 'Connection Refuse'
1062
1093
  end
@@ -1072,8 +1103,11 @@ HTMLRESPONSE
1072
1103
 
1073
1104
  # Create a new board named +name+ accessible on HTTP port +http_port+
1074
1105
  # and whose content is describe in +block+.
1075
- def board(name, http_port = 8000, &block)
1076
- return Board.new(name,http_port,&block)
1106
+ def board(name, http_port: 8000, refresh_rate: 100, &block)
1107
+ # puts "name=#{name} http_port=#{http_port} refresh_rate=#{refresh_rate} block=#{block}"
1108
+ return Board.new(name,
1109
+ http_port: http_port, refresh_rate: refresh_rate,
1110
+ &block)
1077
1111
  end
1078
1112
 
1079
1113
  end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "3.3.3"
2
+ VERSION = "3.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HDLRuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.3
4
+ version: 3.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-27 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -476,7 +476,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
476
476
  - !ruby/object:Gem::Version
477
477
  version: '0'
478
478
  requirements: []
479
- rubygems_version: 3.5.13
479
+ rubygems_version: 3.5.17
480
480
  signing_key:
481
481
  specification_version: 4
482
482
  summary: HDLRuby is a library for describing and simulating digital electronic systems.