| 1 | package Acme::FishFarm; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Carp "croak"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use Acme::FishFarm::Feeder; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use Acme::FishFarm::OxygenMaintainer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use Acme::FishFarm::WaterConditionMonitor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use Acme::FishFarm::WaterLevelMaintainer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use Acme::FishFarm::WaterFiltration; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | Acme::FishFarm - A Fish Farm with Automated Systems | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 VERSION | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | Version 1.01 | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | our $VERSION = '1.01'; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | use 5.010; | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | use Acme::FishFarm ":all"; | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install; | ||||||||||||||||||||
| 34 | my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | $water_monitor->add_oxygen_maintainer( $oxygen ); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | say "Water condition monitor installed..."; | ||||||||||||||||||||
| 39 | say "Oxygen maintainer installed and connected to water condition monitor..."; | ||||||||||||||||||||
| 40 | say "Water condition monitor switched on!"; | ||||||||||||||||||||
| 41 | say ""; | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | while ( "fish are swimming happily" ) { | ||||||||||||||||||||
| 44 | ### DO | ||||||||||||||||||||
| 45 | check_DO( $oxygen, reduce_precision( rand(8) ) ); | ||||||||||||||||||||
| 46 | say ""; | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | ### pH | ||||||||||||||||||||
| 49 | check_pH( $water_monitor, 6.912 ); | ||||||||||||||||||||
| 50 | #check_pH( $water_monitor, 5.9 ); | ||||||||||||||||||||
| 51 | say "" ; | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | ## temperature | ||||||||||||||||||||
| 54 | #check_temperature( $water_monitor, 23 ); | ||||||||||||||||||||
| 55 | check_temperature( $water_monitor, 26 ); | ||||||||||||||||||||
| 56 | say ""; | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | ## turbidity | ||||||||||||||||||||
| 59 | check_turbidity( $water_monitor, 120 ); | ||||||||||||||||||||
| 60 | #check_turbidity( $water_monitor, 190 ); | ||||||||||||||||||||
| 61 | say ""; | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # all LEDs | ||||||||||||||||||||
| 64 | render_leds( $water_monitor ); | ||||||||||||||||||||
| 65 | say ""; | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # buzzers | ||||||||||||||||||||
| 68 | render_buzzer( $water_monitor ); | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | sleep(3); | ||||||||||||||||||||
| 71 | say "-----------------------------"; | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head1 EXPORT | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | The C<:all> tag can be used to import all the subroutines available in this module. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 2 | ▶ | use Exporter qw( import ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 81 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||
| 82 | install_all_systems | ||||||||||||||||||||
| 83 | reduce_precision consume_oxygen | ||||||||||||||||||||
| 84 | check_DO check_pH check_temperature check_turbidity check_water_filter check_water_level check_feeder | ||||||||||||||||||||
| 85 | render_leds render_buzzer | ||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||
| 87 | 2 | our %EXPORT_TAGS = ( | |||||||||||||||||||
| 88 | all => [ qw( install_all_systems reduce_precision consume_oxygen check_DO check_pH check_temperature | ||||||||||||||||||||
| 89 | check_turbidity check_water_filter check_water_level check_feeder render_leds | ||||||||||||||||||||
| 90 | render_buzzer ) ], | ||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head1 NOTES | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | Almost all the subroutines in this module will give output. The unit measurements used will be according to the ones mentioned in C<Acme::FishFarm::WaterConditionMonitor>. | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 SYSTEM INSTALLATION RELATED SUBROUTINES | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head2 install_all_systems | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | Installs all the available systems the default way and returns them as a list of C<Acme::FishFarm::*> objects in the following sequence: | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | (Feeder, OxygenMaintainer, WaterConditionMonitor, WaterLevelMaintainer, WaterFiltration) | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 1 | ▶ | sub install_all_systems { | ||||||||||||||||||
|
Subroutine
install_all_systems: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 108 | 1 | my $feeder = Acme::FishFarm::Feeder->install; | |||||||||||||||||||
| 109 | 1 | my $oxygen_maintainer = Acme::FishFarm::OxygenMaintainer->install; | |||||||||||||||||||
| 110 | 1 | my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install; | |||||||||||||||||||
| 111 | 1 | my $water_level = Acme::FishFarm::WaterLevelMaintainer->install; | |||||||||||||||||||
| 112 | 1 | my $water_filter = Acme::FishFarm::WaterFiltration->install; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | # remember to connect water oxygem maintainer to water condition monitoring :) | ||||||||||||||||||||
| 115 | 1 | $water_monitor->add_oxygen_maintainer( $oxygen_maintainer ); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 1 | ( $feeder, $oxygen_maintainer, $water_monitor, $water_level, $water_filter ); | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head1 SENSOR READING RELATED SUBROUTINES | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =head2 reduce_precision ( $decimal ) | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | Reduces positive or negative C<$decimal> to a 3-decimal value. Make sure to pass in a decimal with more than 3 decimal points. | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | Returns the reduced precision value. | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | This subroutine is useful if you are trying to set the current sensor readings randomly using the built-in C<rand> function as you do not want to end up with too many decimals on the screen. | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 3 | ▶ | sub reduce_precision { | ||||||||||||||||||
|
Subroutine
reduce_precision: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 134 | 3 | my $sensor_reading = shift; | |||||||||||||||||||
| 135 | 3 | ▶ | croak "Please pass in a decimal value" if not $sensor_reading =~ /\./; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 2 | $sensor_reading =~ /(-?\d+\.\d{3})/; | |||||||||||||||||||
| 138 | 2 | return $1; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =head1 AUTOMATED SYSTEMS RELATED SUBROUTINES | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | All of the subroutines here will give output. | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | Take note that there are some systems that can't be connected to the water monitoring system and therefore will not effect the LEDs or buzzers. These systems are: | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =over 4 | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =item * Acme::FishFarm::Feeder | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =item * Acme::FishFarm::WaterFiltration | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =item * Acme::FishFarm::WaterLevelMaintainer | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | =back | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =head2 consume_oxygen ( $oxygen_maintainer, $consumed_oxygen ) | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | This will cause the oxygen level (DO level) of the C<Acme::FishFarm::OxygenMaintainer> to reduce by C<$consumed_oxygen mg/L> | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Returns 1 upon success. | ||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | 2 | ▶ | sub consume_oxygen { | ||||||||||||||||||
|
Subroutine
consume_oxygen: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 165 | 2 | my $o2_maintainer = shift; | |||||||||||||||||||
| 166 | 2 | my $consumed_oxygen = shift; | |||||||||||||||||||
| 167 | 2 | print "$consumed_oxygen mg/L of oxygen consumed...\n"; | |||||||||||||||||||
| 168 | 2 | my $o2_remaining = $o2_maintainer->current_DO - $consumed_oxygen; | |||||||||||||||||||
| 169 | 2 | $o2_maintainer->current_DO( $o2_remaining ); | |||||||||||||||||||
| 170 | 2 | 1; | |||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =head2 check_DO ( $oxygen_maintainer, $current_DO_reading ) | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | This checks and outputs the condition of the current DO level. | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | Take note that this process will trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | Returns 1 upon success. | ||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 1 | ▶ | sub check_DO { | ||||||||||||||||||
|
Subroutine
check_DO: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 183 | 1 | my ( $oxygen, $current_reading ) = @_; | |||||||||||||||||||
| 184 | 1 | my $DO_threshold = $oxygen->DO_threshold; | |||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 1 | $oxygen->current_DO( $current_reading ); | |||||||||||||||||||
| 187 | 1 | $oxygen->is_low_DO; | |||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 1 | print "Current Oxygen Level: ", $current_reading, " mg/L", | |||||||||||||||||||
| 190 | " (low: < ", $DO_threshold, ")\n"; | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 1 | ▶ | if ( $oxygen->is_low_DO ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 193 | 0 | print " !! Low oxygen level!\n"; | |||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||
| 195 | 1 | print " Oxygen level is normal.\n"; | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | 1 | 1; | |||||||||||||||||||
| 198 | } | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =head2 check_pH ( $water_monitor, $current_ph_reading ) | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | This checks and outputs the condition of the current pH value. | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | Take note that this process will trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | Returns 1 upon success. | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | =cut | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 1 | ▶ | sub check_pH { | ||||||||||||||||||
|
Subroutine
check_pH: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 211 | 1 | my ( $water_monitor, $current_reading ) = @_; | |||||||||||||||||||
| 212 | 1 | my $ph_range = $water_monitor->ph_threshold; | |||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 1 | $water_monitor->current_ph( $current_reading ); | |||||||||||||||||||
| 215 | 1 | $water_monitor->ph_is_normal; | |||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | 1 | print "Current pH: ", $water_monitor->current_ph, | |||||||||||||||||||
| 218 | " (normal range: ", $ph_range->[0], "~", $ph_range->[1], ")\n"; | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | 1 | ▶ | if ( !$water_monitor->ph_is_normal ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 221 | 1 | print " !! Abnormal pH!\n"; | |||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||
| 223 | 0 | print " pH is normal.\n"; | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | 1 | 1; | |||||||||||||||||||
| 226 | } | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | =head2 check_temperature ( $water_monitor, $current_temperature_reading ) | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | This checks and outputs the condition of the current temperature. | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | Take note that this process will trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | Returns 1 upon success. | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | 1 | ▶ | sub check_temperature { | ||||||||||||||||||
|
Subroutine
check_temperature: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 239 | 1 | my ( $water_monitor, $current_reading ) = @_; | |||||||||||||||||||
| 240 | 1 | my $temperature_range = $water_monitor->temperature_threshold; | |||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | 1 | $water_monitor->current_temperature( $current_reading ); | |||||||||||||||||||
| 243 | 1 | $water_monitor->temperature_is_normal; | |||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 1 | print "Current temperature: ", $water_monitor->current_temperature, " C", | |||||||||||||||||||
| 246 | " (normal range: ", $temperature_range->[0], " C ~ ", $temperature_range->[1], " C)\n"; | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 1 | ▶ | if ( !$water_monitor->temperature_is_normal ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 249 | 0 | print " !! Abnormal temperature!\n"; | |||||||||||||||||||
| 250 | } else { | ||||||||||||||||||||
| 251 | 1 | print " Temperature is normal.\n"; | |||||||||||||||||||
| 252 | } | ||||||||||||||||||||
| 253 | 1 | 1; | |||||||||||||||||||
| 254 | } | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | =head2 check_turbidity ( $water_monitor, $current_turbidity_reading ) | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | This checks and outputs the condition of the current temperature. | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | Take note that this process will trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | Returns 1 upon success. | ||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | =cut | ||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | 1 | ▶ | sub check_turbidity { | ||||||||||||||||||
|
Subroutine
check_turbidity: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 267 | 1 | my ( $water_monitor, $current_reading ) = @_; | |||||||||||||||||||
| 268 | 1 | my $turbidity_threshold = $water_monitor->turbidity_threshold; | |||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | 1 | $water_monitor->current_turbidity( $current_reading ); | |||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | 1 | print "Current Turbidity: ", $water_monitor->current_turbidity, " ntu", | |||||||||||||||||||
| 273 | " (dirty: > ", $turbidity_threshold, ")\n"; | ||||||||||||||||||||
| 274 | |||||||||||||||||||||
| 275 | 1 | ▶ | if ( $water_monitor->water_dirty ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 276 | 1 | print " !! Water is dirty!\n"; | |||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||
| 278 | 0 | print " Water is still clean.\n"; | |||||||||||||||||||
| 279 | } | ||||||||||||||||||||
| 280 | 1 | 1; | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | =head2 check_water_filter ( $water_filter, $current_waste_count, $reduce_waste_by ) | ||||||||||||||||||||
| 285 | |||||||||||||||||||||
| 286 | This checks, performs necessary actions and outputs the condition of the current waste count in the filtering cylinder. | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | Take note that this process B<DOES NOT> trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | Returns 1 upon success. | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | =cut | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | 1 | ▶ | sub check_water_filter { | ||||||||||||||||||
|
Subroutine
check_water_filter: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 295 | 1 | my $water_filter = shift; | |||||||||||||||||||
| 296 | 1 | my $current_reading = shift; | |||||||||||||||||||
| 297 | 1 | ▶ | my $reduce_waste_by = shift || $water_filter->reduce_waste_count_by; | ||||||||||||||||||
|
Condition33%1/3
shift() || $water_filter->reduce_waste_count_by
MC/DC0%0/2
shift() || $water_filter->reduce_waste_count_by
shift()
$water_filter->reduce_waste_count_by
Truth table33%1/3
A || B
A= shift()B= $water_filter->reduce_waste_count_by
| |||||||||||||||||||||
| 298 | 1 | my $waste_threshold = $water_filter->waste_count_threshold; | |||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | 1 | $water_filter->current_waste_count( $current_reading ); | |||||||||||||||||||
| 301 | 1 | print "Waste Count to Reduce: ", $water_filter->reduce_waste_count_by, "\n"; | |||||||||||||||||||
| 302 | 1 | print "Current Waste Count: ", $current_reading, " (high: >= ", $waste_threshold, ")\n"; | |||||||||||||||||||
| 303 | |||||||||||||||||||||
| 304 | 1 | ▶ | if ( $water_filter->is_cylinder_dirty ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 305 | 1 | print " !! Filtering cylinder is dirty!\n"; | |||||||||||||||||||
| 306 | 1 | $water_filter->turn_on_spatulas; | |||||||||||||||||||
| 307 | 1 | print " Cleaning spatulas turned on.\n"; | |||||||||||||||||||
| 308 | 1 | $water_filter->clean_cylinder( $reduce_waste_by ); | |||||||||||||||||||
| 309 | 1 | print " Cleaning the cylinder...Done!\n"; | |||||||||||||||||||
| 310 | 1 | print "Current waste count: ", $water_filter->current_waste_count, "\n"; | |||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||
| 312 | 0 | print " Filtering cylinder is still clean.\n"; | |||||||||||||||||||
| 313 | } | ||||||||||||||||||||
| 314 | 1 | 1; | |||||||||||||||||||
| 315 | } | ||||||||||||||||||||
| 316 | |||||||||||||||||||||
| 317 | =head2 check_water_level ( $water_level_maintainer, $current_water_level ) | ||||||||||||||||||||
| 318 | |||||||||||||||||||||
| 319 | This checks, performs necessary actions and outputs the condition of the current waste count in the filtering cylinder. | ||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | Take note that this process B<DOES NOT> trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 322 | |||||||||||||||||||||
| 323 | Returns 1 upon success. | ||||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | =cut | ||||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | 1 | ▶ | sub check_water_level { | ||||||||||||||||||
|
Subroutine
check_water_level: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 328 | 1 | my $water_level = shift; | |||||||||||||||||||
| 329 | 1 | my $current_reading = shift; | |||||||||||||||||||
| 330 | 1 | my $height_increase = $water_level->water_level_increase_height; # for output | |||||||||||||||||||
| 331 | 1 | my $water_level_threshold = $water_level->low_water_level_threshold; | |||||||||||||||||||
| 332 | |||||||||||||||||||||
| 333 | 1 | $water_level->current_water_level( $current_reading ); # input by user | |||||||||||||||||||
| 334 | 1 | print "Current Water Level: ", $current_reading, " m (low: < ", $water_level_threshold, " m)\n"; | |||||||||||||||||||
| 335 | |||||||||||||||||||||
| 336 | 1 | ▶ | if ( $water_level->is_low_water_level ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 337 | 1 | print " !! Water level is low!\n"; | |||||||||||||||||||
| 338 | 1 | $water_level->pump_water_in; | |||||||||||||||||||
| 339 | 1 | print " Pumping in ", $height_increase, " m of water...\n"; | |||||||||||||||||||
| 340 | 1 | print "Current Water Level: ", $water_level->current_water_level, " m\n"; | |||||||||||||||||||
| 341 | } else { | ||||||||||||||||||||
| 342 | 0 | print " Water level is still normal.\n"; | |||||||||||||||||||
| 343 | } | ||||||||||||||||||||
| 344 | 1 | 1; | |||||||||||||||||||
| 345 | } | ||||||||||||||||||||
| 346 | |||||||||||||||||||||
| 347 | =head2 check_feeder ( $feeder, $verbose ) | ||||||||||||||||||||
| 348 | |||||||||||||||||||||
| 349 | This checks, performs necessary actions and outputs the condition of the feeder. Each call will tick the clock inside the feeder. See C<Acme::FishFarm::Feeder> for more info. | ||||||||||||||||||||
| 350 | |||||||||||||||||||||
| 351 | If the food tank is empty, it will be filled to the default. So if you want to fill a different amount, please set the amount before hand. See C<Acme::FishFarm::Feeder>. | ||||||||||||||||||||
| 352 | |||||||||||||||||||||
| 353 | Setting C<$verbose> to 1 will give more output about the empty food tank. | ||||||||||||||||||||
| 354 | |||||||||||||||||||||
| 355 | Take note that this process B<DOES NOT> trigger the LED and buzzer if abnormal condition is present. | ||||||||||||||||||||
| 356 | |||||||||||||||||||||
| 357 | Returns 1 upon success. | ||||||||||||||||||||
| 358 | |||||||||||||||||||||
| 359 | =cut | ||||||||||||||||||||
| 360 | |||||||||||||||||||||
| 361 | 2 | ▶ | sub check_feeder { | ||||||||||||||||||
|
Subroutine
check_feeder: called CC=4 SCAR=19.4
Pod
documented
| |||||||||||||||||||||
| 362 | 2 | my ( $feeder, $verbose ) = @_; | |||||||||||||||||||
| 363 | 2 | ▶ | if ( $feeder->timer_is_up ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 364 | 0 | print "Timer is up, time to feed the fish!\n"; | |||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | 0 | ▶ | if ( $verbose) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 367 | 0 | $feeder->feed_fish( verbose => 1 ); | |||||||||||||||||||
| 368 | } else { | ||||||||||||||||||||
| 369 | 0 | $feeder->feed_fish; | |||||||||||||||||||
| 370 | } | ||||||||||||||||||||
| 371 | 0 | print " Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...\n"; | |||||||||||||||||||
| 372 | |||||||||||||||||||||
| 373 | } else { | ||||||||||||||||||||
| 374 | 2 | print $feeder->time_remaining, " hours left until it's time to feed the fish.\n"; | |||||||||||||||||||
| 375 | } | ||||||||||||||||||||
| 376 | |||||||||||||||||||||
| 377 | 2 | ▶ | if ( $feeder->food_remaining <= 0 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 378 | 0 | print " !! Food tank empty!\n"; | |||||||||||||||||||
| 379 | 0 | $feeder->refill; # default back to 500 cm^3 | |||||||||||||||||||
| 380 | 0 | print " Refilled food tank back to ", $feeder->food_tank_capacity, " cm^3.\n"; | |||||||||||||||||||
| 381 | } | ||||||||||||||||||||
| 382 | |||||||||||||||||||||
| 383 | 2 | print " Food Remaining: ", $feeder->food_remaining, "cm^3.\n"; | |||||||||||||||||||
| 384 | |||||||||||||||||||||
| 385 | 2 | $feeder->tick_clock; | |||||||||||||||||||
| 386 | 2 | 1; | |||||||||||||||||||
| 387 | } | ||||||||||||||||||||
| 388 | |||||||||||||||||||||
| 389 | =head2 render_leds ( $water_monitor ) | ||||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | Outputs which LEDs are lighted up. Returns 1 upon success. | ||||||||||||||||||||
| 392 | |||||||||||||||||||||
| 393 | Currently this subroutine only shows the LEDs present in the C<Acme::FishFarm::WaterConditionMonitor> object. See that module for more details about the available LEDs. | ||||||||||||||||||||
| 394 | |||||||||||||||||||||
| 395 | More LEDs will be available in the future. | ||||||||||||||||||||
| 396 | |||||||||||||||||||||
| 397 | =cut | ||||||||||||||||||||
| 398 | |||||||||||||||||||||
| 399 | 1 | ▶ | sub render_leds { | ||||||||||||||||||
|
Subroutine
render_leds: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||
| 400 | 1 | my $water_monitor = shift; | |||||||||||||||||||
| 401 | |||||||||||||||||||||
| 402 | # must check condition first! If not it won't work | ||||||||||||||||||||
| 403 | # this process will update the LEDs status | ||||||||||||||||||||
| 404 | 1 | $water_monitor->ph_is_normal; | |||||||||||||||||||
| 405 | 1 | $water_monitor->temperature_is_normal; | |||||||||||||||||||
| 406 | 1 | $water_monitor->lacking_oxygen; | |||||||||||||||||||
| 407 | 1 | $water_monitor->water_dirty; | |||||||||||||||||||
| 408 | |||||||||||||||||||||
| 409 | 1 | print "Total LEDs up: ", $water_monitor->lighted_LED_count, "\n"; | |||||||||||||||||||
| 410 | |||||||||||||||||||||
| 411 | 1 | ▶ | if ( $water_monitor->is_on_LED_pH ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 412 | 1 | print " pH LED: on\n"; | |||||||||||||||||||
| 413 | } else { | ||||||||||||||||||||
| 414 | 0 | print " pH LED: off\n"; | |||||||||||||||||||
| 415 | } | ||||||||||||||||||||
| 416 | |||||||||||||||||||||
| 417 | 1 | ▶ | if ( $water_monitor->is_on_LED_temperature ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 418 | 0 | print " Temperature LED: on\n"; | |||||||||||||||||||
| 419 | } else { | ||||||||||||||||||||
| 420 | 1 | print " Temperature LED: off\n"; | |||||||||||||||||||
| 421 | } | ||||||||||||||||||||
| 422 | |||||||||||||||||||||
| 423 | 1 | ▶ | if ( $water_monitor->is_on_LED_DO ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 424 | 0 | print " Low DO LED: on\n"; | |||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||
| 426 | 1 | print " Low DO LED: off\n"; | |||||||||||||||||||
| 427 | } | ||||||||||||||||||||
| 428 | |||||||||||||||||||||
| 429 | 1 | ▶ | if ( $water_monitor->is_on_LED_turbidity ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 430 | 1 | print " Turbidity LED: on\n"; | |||||||||||||||||||
| 431 | } else { | ||||||||||||||||||||
| 432 | 0 | print " Turbidity LED: off\n"; | |||||||||||||||||||
| 433 | } | ||||||||||||||||||||
| 434 | 1 | 1; | |||||||||||||||||||
| 435 | } | ||||||||||||||||||||
| 436 | |||||||||||||||||||||
| 437 | =head2 render_buzzer ( $water_monitor ) | ||||||||||||||||||||
| 438 | |||||||||||||||||||||
| 439 | Outputs which buzzer is buzzing. Returns 1 upon success. | ||||||||||||||||||||
| 440 | |||||||||||||||||||||
| 441 | See C<Acme::FishFarm::WaterConditionMonitor> for details on how the short and long buzzers are switched on and off. | ||||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | =cut | ||||||||||||||||||||
| 444 | |||||||||||||||||||||
| 445 | 1 | ▶ | sub render_buzzer { | ||||||||||||||||||
|
Subroutine
render_buzzer: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||
| 446 | 1 | my $water_monitor = shift; | |||||||||||||||||||
| 447 | |||||||||||||||||||||
| 448 | #$water_monitor->_tweak_buzzers; | ||||||||||||||||||||
| 449 | 1 | ▶ | if ( $water_monitor->is_on_buzzer_long ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 450 | 1 | print "Long buzzer is on, water condition very critical!\n"; | |||||||||||||||||||
| 451 | } elsif ( $water_monitor->is_on_buzzer_short ) { | ||||||||||||||||||||
| 452 | 0 | print "Short buzzer is on, water condition is a bit worrying :|\n"; | |||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||
| 454 | 0 | print "No buzzers on, what a peaceful moment.\n"; | |||||||||||||||||||
| 455 | } | ||||||||||||||||||||
| 456 | 1 | 1; | |||||||||||||||||||
| 457 | } | ||||||||||||||||||||
| 458 | |||||||||||||||||||||
| 459 | |||||||||||||||||||||
| 460 | =head1 AUTHOR | ||||||||||||||||||||
| 461 | |||||||||||||||||||||
| 462 | Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >> | ||||||||||||||||||||
| 463 | |||||||||||||||||||||
| 464 | =head1 BUGS | ||||||||||||||||||||
| 465 | |||||||||||||||||||||
| 466 | Please report any bugs or feature requests to C<bug-acme-fishfarm at rt.cpan.org>, or through | ||||||||||||||||||||
| 467 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-FishFarm>. I will be notified, and then you'll | ||||||||||||||||||||
| 468 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||
| 469 | |||||||||||||||||||||
| 470 | |||||||||||||||||||||
| 471 | |||||||||||||||||||||
| 472 | |||||||||||||||||||||
| 473 | =head1 SUPPORT | ||||||||||||||||||||
| 474 | |||||||||||||||||||||
| 475 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 476 | |||||||||||||||||||||
| 477 | perldoc Acme::FishFarm | ||||||||||||||||||||
| 478 | |||||||||||||||||||||
| 479 | |||||||||||||||||||||
| 480 | You can also look for information at: | ||||||||||||||||||||
| 481 | |||||||||||||||||||||
| 482 | =over 4 | ||||||||||||||||||||
| 483 | |||||||||||||||||||||
| 484 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||
| 485 | |||||||||||||||||||||
| 486 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Acme-FishFarm> | ||||||||||||||||||||
| 487 | |||||||||||||||||||||
| 488 | =item * CPAN Ratings | ||||||||||||||||||||
| 489 | |||||||||||||||||||||
| 490 | L<https://cpanratings.perl.org/d/Acme-FishFarm> | ||||||||||||||||||||
| 491 | |||||||||||||||||||||
| 492 | =item * Search CPAN | ||||||||||||||||||||
| 493 | |||||||||||||||||||||
| 494 | L<https://metacpan.org/release/Acme-FishFarm> | ||||||||||||||||||||
| 495 | |||||||||||||||||||||
| 496 | =back | ||||||||||||||||||||
| 497 | |||||||||||||||||||||
| 498 | |||||||||||||||||||||
| 499 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 500 | |||||||||||||||||||||
| 501 | Besiyata d'shmaya | ||||||||||||||||||||
| 502 | |||||||||||||||||||||
| 503 | =head1 SEE ALSO | ||||||||||||||||||||
| 504 | |||||||||||||||||||||
| 505 | Acme::FishFarm::Feeder | ||||||||||||||||||||
| 506 | |||||||||||||||||||||
| 507 | Acme::FishFarm::OxygenMaintainer | ||||||||||||||||||||
| 508 | |||||||||||||||||||||
| 509 | Acme::FishFarm::WaterConditionMonitor | ||||||||||||||||||||
| 510 | |||||||||||||||||||||
| 511 | Acme::FishFarm::WaterFiltration | ||||||||||||||||||||
| 512 | |||||||||||||||||||||
| 513 | Acme::FishFarm::::WaterLevelMaintainer | ||||||||||||||||||||
| 514 | |||||||||||||||||||||
| 515 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 516 | |||||||||||||||||||||
| 517 | This software is Copyright (c) 2021 by Raphael Jong Jun Jie. | ||||||||||||||||||||
| 518 | |||||||||||||||||||||
| 519 | This is free software, licensed under: | ||||||||||||||||||||
| 520 | |||||||||||||||||||||
| 521 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||
| 522 | |||||||||||||||||||||
| 523 | |||||||||||||||||||||
| 524 | =cut | ||||||||||||||||||||
| 525 | |||||||||||||||||||||
| 526 | 2 | 1; # End of Acme::FishFarm | |||||||||||||||||||