Class: AnalogPin
Instance Attribute Summary collapse
-
#feedback ⇒ Object
Returns the value of attribute feedback.
-
#in_hi ⇒ Object
Returns the value of attribute in_hi.
-
#in_lo ⇒ Object
Returns the value of attribute in_lo.
-
#out_hi ⇒ Object
Returns the value of attribute out_hi.
-
#out_lo ⇒ Object
Returns the value of attribute out_lo.
-
#pin ⇒ Object
Returns the value of attribute pin.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
-
#window ⇒ Object
Returns the value of attribute window.
Attributes inherited from Base
Instance Method Summary collapse
- #arduino_code ⇒ Object
- #cycle_level_arduino_code ⇒ Object
- #depends_on ⇒ Object
-
#initialize(params) ⇒ AnalogPin
constructor
A new instance of AnalogPin.
- #seconds_to_frames(seconds) ⇒ Object
- #top_level_scope_code ⇒ Object
Methods inherited from Base
#add_arduino_code, #add_cycle_level_scope, #add_top_level_scope, #append_tsortable, #buildit, #param_keys, #resolve_frame_optimized, #top_level_scope_arduino_code
Constructor Details
#initialize(params) ⇒ AnalogPin
Returns a new instance of AnalogPin.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/functions/analog_pin.rb', line 79 def initialize(params) @frame_optimized = true @name = "#{self.class}_#{SecureRandom.uuid.to_s.gsub('-','')}" @pin = params[:pin] @scale = params[:scale] @in_lo = params[:in_lo] @in_hi = params[:in_hi] @out_lo = params[:out_lo] @out_hi = params[:out_hi] @threshold = params[:threshold] @window = params[:window] @feedback = params[:feedback] # buildit end |
Instance Attribute Details
#feedback ⇒ Object
Returns the value of attribute feedback.
110 111 112 |
# File 'lib/functions/analog_pin.rb', line 110 def feedback @feedback end |
#in_hi ⇒ Object
Returns the value of attribute in_hi.
104 105 106 |
# File 'lib/functions/analog_pin.rb', line 104 def in_hi @in_hi end |
#in_lo ⇒ Object
Returns the value of attribute in_lo.
103 104 105 |
# File 'lib/functions/analog_pin.rb', line 103 def in_lo @in_lo end |
#out_hi ⇒ Object
Returns the value of attribute out_hi.
106 107 108 |
# File 'lib/functions/analog_pin.rb', line 106 def out_hi @out_hi end |
#out_lo ⇒ Object
Returns the value of attribute out_lo.
105 106 107 |
# File 'lib/functions/analog_pin.rb', line 105 def out_lo @out_lo end |
#pin ⇒ Object
Returns the value of attribute pin.
100 101 102 |
# File 'lib/functions/analog_pin.rb', line 100 def pin @pin end |
#scale ⇒ Object
Returns the value of attribute scale.
102 103 104 |
# File 'lib/functions/analog_pin.rb', line 102 def scale @scale end |
#threshold ⇒ Object
Returns the value of attribute threshold.
108 109 110 |
# File 'lib/functions/analog_pin.rb', line 108 def threshold @threshold end |
#window ⇒ Object
Returns the value of attribute window.
109 110 111 |
# File 'lib/functions/analog_pin.rb', line 109 def window @window end |
Instance Method Details
#arduino_code ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/functions/analog_pin.rb', line 112 def arduino_code unless @frame_optimized [ %{analog_pin( #{@pin}, #{@name}_scale, #{@name}_in_lo, #{@name}_in_hi, #{@name}_out_lo, #{@name}_out_hi, #{@name}_threshold, #{@name}_window, #{@name}_running_total, #{@name}_current_index, #{seconds_to_frames(@window)}, #{@name}_feedback, #{@name}_storage, #{@name});} ] else [] end end |
#cycle_level_arduino_code ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/functions/analog_pin.rb', line 136 def cycle_level_arduino_code if @frame_optimized [ %{analog_pin( #{@pin}, #{@name}_scale, #{@name}_in_lo, #{@name}_in_hi, #{@name}_out_lo, #{@name}_out_hi, #{@name}_threshold, #{@name}_window, #{@name}_running_total, #{@name}_current_index, #{seconds_to_frames(@window)}, #{@name}_feedback, #{@name}_storage, #{@name});} ] else [] end end |
#depends_on ⇒ Object
96 97 98 |
# File 'lib/functions/analog_pin.rb', line 96 def depends_on [] end |
#seconds_to_frames(seconds) ⇒ Object
182 183 184 |
# File 'lib/functions/analog_pin.rb', line 182 def seconds_to_frames(seconds) (seconds * 30.0).to_i end |
#top_level_scope_code ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/functions/analog_pin.rb', line 160 def top_level_scope_code [ "// pinMode(#{@pin}, INPUT);", "long #{@name}[3];", "byte #{@name}_scale = #{@scale};", "long #{@name}_in_lo = #{@in_lo};", "long #{@name}_in_hi = #{@in_hi};", "long #{@name}_out_lo = #{@out_lo};", "long #{@name}_out_hi = #{@out_hi};", "long #{@name}_threshold = #{@threshold};", "long #{@name}_window[#{seconds_to_frames(@window)}];", "long #{@name}_running_total;", "int #{@name}_current_index;", "long #{@name}_feedback = #{@feedback};", "long #{@name}_storage;" ] end |