Acme-FishFarm

 view release on metacpan or  search on metacpan

lib/Acme/FishFarm/WaterConditionMonitor.pm  view on Meta::CPAN

The values are in the range of C<1-14>. However, this range is not checked for incorrect values.

=item temperature

Optional. The default threshold range is C<[20, 25]> degree celcius and the default temprature is C<25>.

This will set the threshold value of the water temperature. Please pass in an array reference to this key
in the form of C<[min_temperature, max_temperature]>

The ranges of values are between C<0> and C<50> degree B<celcius>. However, this range is not checked for incorrect values. The unit C<celcius> is just a unit, it doesn't show up if you call any of it's related getters.

=item turbidity

Optional. The default threshold is C<180 ntu> and the default turbidity is set to C<10 ntu>.

This will set the threshold of the turbidity of the water.

The range of values are between C<0 ntu> and C<300 ntu>. However, this range is not checked for incorrect values. The unit C<ntu> is just a unit, it doesn't show up if you call any of it's related getters.

=back

=cut

sub install {
    my $class = shift;
    my %sensors = @_;
    
    if ( not $sensors{pH} ) {
        $sensors{pH_range} = [6.5, 7.5];
        $sensors{current_pH} = 7.0;
        $sensors{pH_LED_on} = 0;
    }
    
    if ( not $sensors{temperature} ) {
        $sensors{temperature_range} = [20, 25];
        $sensors{current_temperature} = 23;
        $sensors{temperature_LED_on} = 0;
    }
    
    if ( not $sensors{turbidity} ) {
        $sensors{turbidity_threshold} = 180;
        $sensors{current_turbidity} = 10;
        $sensors{turbidity_LED_on} = 0;
    }
    
    # low DO led, use Acme::FishFarm::OxygenMaintainer to determine
    $sensors{DO_LED_on} = 0;
    
    $sensors{lighted_LED_count} = 0;
    $sensors{short_buzzer_on} = 0;
    $sensors{long_buzzer_on} = 0;
    
    bless \%sensors, "Acme::FishFarm::WaterConditionMonitor";
}


=head2 add_oxygen_maintainer ( $oxygen_maintainer )

Connects the oxygen maintainer ie C<Acme::FishFarm::OxygenMaintainer> system to this monitoring system.

For now, this module can only check if the oxygen is lacking or not. This module contains a user friendly method compared to the standard terminology used in the C<Acme::FishFarm::OxygenMaintainer> module. Other user friendly methods will be added in...

=cut

sub add_oxygen_maintainer {
    ref( my $self = shift ) or croak "Please use this the OO way";
    if ( ref( my $oxygen_maintainer = shift ) ne "Acme::FishFarm::OxygenMaintainer") {
        croak "Please pass in an Acme::FishFarm::OxygenMaintainer object!";
    } else {
        $self->{oxygen_maintainer} = $oxygen_maintainer;
    }
}

=head1 WATER CONDITIONS RELATED SUBROUTINES/METHODS

=head2 current_ph ( $new_ph )

Sets / returns the current pH of the water.

C<$new_pH> is optional. If present, the current pH will be set to C<$new_ph>. Otherwise, returns the current pH reading.

=cut

sub current_ph {
    ref( my $self = shift ) or croak "Please use this the OO way";
    if ( @_ ) {
        $self->{current_pH} = shift;
    } else {
        $self->{current_pH};
    }
}

=head2 ph_threshold

Returns the pH threshold as an array ref.

=cut

sub ph_threshold {
    ref( my $self = shift ) or croak "Please use this the OO way";
    $self->{pH_range};
}

=head2 set_ph_threshold ( $ph_value )

Sets the pH threshold.

=cut

sub set_ph_threshold {
    ref( my $self = shift ) or croak "Please use this the OO way";
    my $new_ph_range_ref = shift;
    croak "Please supply an array ref to set new pH range" if ref( $new_ph_range_ref ) ne ref( [] );
    $self->{pH_range} = $new_ph_range_ref;
}

=head2 ph_is_normal

Returns true if the current pH is within the set range of threshold.

The pH LED will light up and a short buzzer will be turned on if B<only> the pH is not normal.



( run in 0.788 second using v1.01-cache-2.11-cpan-39bf76dae61 )