|
- #include <Arduino.h>
- #include <EEPROMex.h>
-
- #include "lcd.h"
- #include "serial.h"
- #include "scale.h"
- #include "buttons.h"
- #include "weight_controller.h"
-
- #define shift_element 3
-
- // =====================
- // ======= SETUP =======
- // =====================
- LCD lcd;
- SerialIO serial;
- Scale scale;
- Buttons buttons;
- WeightControllerPool pool;
-
- void setup()
- {
- //
- // INIT
- //
- lcd.init();
- serial.init();
- scale.init();
- buttons.init();
- pool.init();
-
- //
- // DISPLAY INIT MESSAGES
- //
- serial.print_init_message();
- lcd.print_init_message(scale.get_calibration_weight());
- lcd.clear();
- //
- // DISPLAY INIT MESSAGES
- //
- }
-
- void loop()
- {
- //
- // ON BUTTON PRESSED ACTION
- //
- if (buttons.is_any_pressed())
- {
- buttons.on_button_pressed(scale, pool, lcd);
- }
-
- //
- // READ WEIGHT
- //
- scale.read();
-
- if (pool.is_controller_displayed()) {
- //
- // SHOW CONTROL RESULT
- //
- WeightController &controller = pool.get();
- int result = controller.compare(scale.get_average_grain());
- lcd.print_control_result(controller.get_name(), controller.get_val_min(), controller.get_val_max(), result);
- //
- // SHOW CONTROL RESULT
- //
- } else {
- //
- // PRINT WEIGHT
- //
- lcd.print_weights(scale.get_average_gram(), scale.get_average_grain());
- //
- // PRINT WEIGHT
- //
- }
-
- //
- // PROCESS REQUESTS FROM SERIAL
- //
- if (serial.is_available())
- {
- serial.on_command(scale, pool, lcd);
- if (serial.is_debug_info_allowed())
- {
- serial.print_debug_info(scale.get_raw(), scale.get_average_raw(), scale.get_offset(), scale.get_weight(), scale.get_actual_gram(), scale.get_average_gram(), scale.get_average_grain());
- }
- }
- //
- // PROCESS REQUESTS FROM SERIAL
- //
- }
|