Class: AnalogPin

Inherits:
Base
  • Object
show all
Defined in:
lib/functions/analog_pin.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#frame_optimized, #name

Instance Method Summary collapse

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

#feedbackObject

Returns the value of attribute feedback.



110
111
112
# File 'lib/functions/analog_pin.rb', line 110

def feedback
  @feedback
end

#in_hiObject

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_loObject

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_hiObject

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_loObject

Returns the value of attribute out_lo.



105
106
107
# File 'lib/functions/analog_pin.rb', line 105

def out_lo
  @out_lo
end

#pinObject

Returns the value of attribute pin.



100
101
102
# File 'lib/functions/analog_pin.rb', line 100

def pin
  @pin
end

#scaleObject

Returns the value of attribute scale.



102
103
104
# File 'lib/functions/analog_pin.rb', line 102

def scale
  @scale
end

#thresholdObject

Returns the value of attribute threshold.



108
109
110
# File 'lib/functions/analog_pin.rb', line 108

def threshold
  @threshold
end

#windowObject

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_codeObject



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_codeObject



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_onObject



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_codeObject



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