This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/module/printcounter.h

208 lines
6 KiB
C
Raw Normal View History

2017-02-25 11:15:18 +01:00
/**
* Marlin 3D Printer Firmware
2019-02-12 22:06:53 +01:00
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
2017-09-06 13:28:32 +02:00
#include "../libs/stopwatch.h"
#include "../libs/duration_t.h"
#include "../inc/MarlinConfig.h"
// Print debug messages with M111 S2
2016-04-27 03:55:22 +02:00
//#define DEBUG_PRINTCOUNTER
#if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
// round up address to next page boundary (assuming 32 byte pages)
#define STATS_EEPROM_ADDRESS 0x40
#else
#define STATS_EEPROM_ADDRESS 0x32
#endif
struct printStatistics { // 16 bytes
//const uint8_t magic; // Magic header, it will always be 0x16
2016-04-27 03:12:46 +02:00
uint16_t totalPrints; // Number of prints
uint16_t finishedPrints; // Number of complete prints
uint32_t printTime; // Accumulated printing time
2017-04-26 09:43:11 +02:00
uint32_t longestPrint; // Longest successful print job
float filamentUsed; // Accumulated filament consumed in mm
2019-02-12 22:58:56 +01:00
#if SERVICE_INTERVAL_1 > 0
uint32_t nextService1; // Service intervals (or placeholders)
#endif
#if SERVICE_INTERVAL_2 > 0
uint32_t nextService2;
#endif
#if SERVICE_INTERVAL_3 > 0
uint32_t nextService3;
#endif
};
class PrintCounter: public Stopwatch {
private:
typedef Stopwatch super;
#if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM) || defined(CPU_32_BIT)
2019-02-12 22:58:56 +01:00
typedef uint32_t eeprom_address_t;
#else
2019-02-12 22:58:56 +01:00
typedef uint16_t eeprom_address_t;
#endif
static printStatistics data;
/**
* @brief EEPROM address
* @details Defines the start offset address where the data is stored.
*/
2019-02-12 22:58:56 +01:00
static const eeprom_address_t address;
/**
* @brief Interval in seconds between counter updates
* @details This const value defines what will be the time between each
2016-04-28 16:40:24 +02:00
* accumulator update. This is different from the EEPROM save interval.
2016-05-22 14:14:58 +02:00
*
* @note The max value for this option is 60(s), otherwise integer
* overflow will happen.
*/
2018-09-01 00:40:39 +02:00
static constexpr uint16_t updateInterval = 10;
/**
* @brief Interval in seconds between EEPROM saves
* @details This const value defines what will be the time between each
* EEPROM save cycle, the development team recommends to set this value
* no lower than 3600 secs (1 hour).
*/
2018-09-01 00:40:39 +02:00
static constexpr uint16_t saveInterval = 3600;
/**
* @brief Timestamp of the last call to deltaDuration()
* @details Store the timestamp of the last deltaDuration(), this is
* required due to the updateInterval cycle.
*/
static millis_t lastDuration;
2016-04-27 03:12:46 +02:00
/**
* @brief Stats were loaded from EEPROM
2016-04-27 03:12:46 +02:00
* @details If set to true it indicates if the statistical data was already
* loaded from the EEPROM.
*/
static bool loaded;
2016-04-27 03:12:46 +02:00
protected:
/**
* @brief dT since the last call
* @details Return the elapsed time in seconds since the last call, this is
* used internally for print statistics accounting is not intended to be a
* user callable function.
*/
static millis_t deltaDuration();
public:
/**
* @brief Initialize the print counter
*/
static inline void init() {
super::init();
loadStats();
}
2016-04-27 03:12:46 +02:00
/**
* @brief Check if Print Statistics has been loaded
* @details Return true if the statistical data has been loaded.
2016-04-27 03:12:46 +02:00
* @return bool
*/
FORCE_INLINE static bool isLoaded() { return loaded; }
2016-04-27 03:12:46 +02:00
/**
* @brief Increment the total filament used
* @details The total filament used counter will be incremented by "amount".
*
* @param amount The amount of filament used in mm
*/
static void incFilamentUsed(float const &amount);
2016-04-27 03:12:46 +02:00
/**
* @brief Reset the Print Statistics
* @details Reset the statistics to zero and saves them to EEPROM creating
2016-04-27 03:12:46 +02:00
* also the magic header.
*/
static void initStats();
2016-04-27 03:12:46 +02:00
/**
* @brief Load the Print Statistics
* @details Load the statistics from EEPROM
2016-04-27 03:12:46 +02:00
*/
static void loadStats();
2016-04-27 03:12:46 +02:00
/**
* @brief Save the Print Statistics
* @details Save the statistics to EEPROM
2016-04-27 03:12:46 +02:00
*/
static void saveStats();
2016-04-27 03:12:46 +02:00
/**
* @brief Serial output the Print Statistics
* @details This function may change in the future, for now it directly
* prints the statistical data to serial.
*/
static void showStats();
2016-04-27 03:12:46 +02:00
/**
* @brief Return the currently loaded statistics
* @details Return the raw data, in the same structure used internally
*/
static printStatistics getStats() { return data; }
2016-04-27 03:12:46 +02:00
/**
* @brief Loop function
* @details This function should be called at loop, it will take care of
* periodically save the statistical data to EEPROM and do time keeping.
*/
static void tick();
2016-04-27 03:12:46 +02:00
/**
* The following functions are being overridden
*/
static bool start();
static bool stop();
static void reset();
2019-02-12 22:58:56 +01:00
#if HAS_SERVICE_INTERVALS
static void resetServiceInterval(const int index);
static bool needsService(const int index);
#endif
#if ENABLED(DEBUG_PRINTCOUNTER)
/**
* @brief Print a debug message
* @details Print a simple debug message
*/
static void debug(const char func[]);
#endif
};
// Global Print Job Timer instance
2017-09-09 07:18:43 +02:00
#if ENABLED(PRINTCOUNTER)
extern PrintCounter print_job_timer;
#else
extern Stopwatch print_job_timer;
#endif