Class: MINT::Head::StatefulProtocol

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EM::Protocols::LineText2
Defined in:
lib/MINT-core/model/ir/body/head.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatefulProtocol

attr_accessor :speed



46
47
48
49
50
51
# File 'lib/MINT-core/model/ir/body/head.rb', line 46

def initialize
  super()
  @consume_head_movement = false
  @consume_nose_movement = false

end

Instance Attribute Details

#consume_head_movementObject

Returns the value of attribute consume_head_movement.



43
44
45
# File 'lib/MINT-core/model/ir/body/head.rb', line 43

def consume_head_movement
  @consume_head_movement
end

#consume_nose_movementObject

Returns the value of attribute consume_nose_movement.



43
44
45
# File 'lib/MINT-core/model/ir/body/head.rb', line 43

def consume_nose_movement
  @consume_nose_movement
end

#headObject

Returns the value of attribute head.



42
43
44
# File 'lib/MINT-core/model/ir/body/head.rb', line 42

def head
  @head
end

Instance Method Details

#receive_line(data) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/MINT-core/model/ir/body/head.rb', line 53

def receive_line(data)
  begin
    d = data.split('/')

    case d[0]
      when "Move", "HeadMove"
        if   @consume_head_movement
          head_x = d[1].gsub(',',".").to_f
          head_y = d[2].gsub(',',".").to_f
          head_scale =  d[3].gsub(',',".").to_f
          @head_angle = d[4].gsub(',',".").to_f

          if (@head.head_angle-@head_angle).abs > @head.head_angle_threshold
            @head.process_event "head_move"
            @head.attribute_set(:head_angle,@head_angle)
            @channel_name =  @head.create_attribute_channel_name("head_angle")
            RedisConnector.redis.publish @channel_name,MultiJson.encode({:name=>@head.name,:head_angle => @head_angle})
          end
        end
      when "FaceMove"
        if   @consume_nose_movement
          @nose_x = d[1].gsub(',',".").to_f
          @nose_y = d[2].gsub(',',".").to_f

          if (@head.nose_x-@nose_x).abs > @head.nose_x_threshold or (@head.nose_y-@nose_y).abs > @head.nose_y_threshold
            @head.process_event "face_move"
            @head.attribute_set(:nose_x,@nose_x)
            @head.attribute_set(:nose_y,@nose_y)
            @channel_name =  @head.create_attribute_channel_name("nose")
            RedisConnector.redis.publish @channel_name,MultiJson.encode({:name=>@head.name,:x => @nose_x,:y =>@nose_y})
            RedisConnector.redis.publish("out_channel:#{@head.create_channel_w_name}:testuser",MultiJson.encode({:name=>@head.name,:x => @nose_x,:y =>@nose_y}))
          end
        end
      when 'Leave'
        @head.process_event :face_lost
      when 'Enter'
        @head.process_event :face_found
      else
        p "ERROR\r\nReceived Unknown data:#{data}\r\n "
    end
  end
rescue Statemachine::TransitionMissingException => bang
  puts "ERROR\n#{bang}"
end