Subversion Repositories Tronxy-X3A-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
/**
2
 * Marlin 3D Printer Firmware
3
 * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
 *
5
 * Based on Sprinter and grbl.
6
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
 
23
#ifndef CONFIGURATION_STORE_H
24
#define CONFIGURATION_STORE_H
25
 
26
#include "MarlinConfig.h"
27
 
28
class MarlinSettings {
29
  public:
30
    MarlinSettings() { }
31
 
32
    static uint16_t datasize();
33
 
34
    static void reset();
35
    static bool save();   // Return 'true' if data was saved
36
 
37
    FORCE_INLINE static bool init_eeprom() {
38
      reset();
39
      #if ENABLED(EEPROM_SETTINGS)
40
        const bool success = save();
41
        #if ENABLED(EEPROM_CHITCHAT)
42
          if (success) report();
43
        #endif
44
        return success;
45
      #else
46
        return true;
47
      #endif
48
    }
49
 
50
    #if ENABLED(EEPROM_SETTINGS)
51
      static bool load();     // Return 'true' if data was loaded ok
52
      static bool validate(); // Return 'true' if EEPROM data is ok
53
 
54
      #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
55
                                         // That can store is enabled
56
        static uint16_t meshes_start_index();
57
        FORCE_INLINE static uint16_t meshes_end_index() { return meshes_end; }
58
        static uint16_t calc_num_meshes();
59
        static int mesh_slot_offset(const int8_t slot);
60
        static void store_mesh(const int8_t slot);
61
        static void load_mesh(const int8_t slot, void * const into=NULL);
62
 
63
        //static void delete_mesh();    // necessary if we have a MAT
64
        //static void defrag_meshes();  // "
65
      #endif
66
    #else
67
      FORCE_INLINE
68
      static bool load() { reset(); report(); return true; }
69
    #endif
70
 
71
    #if DISABLED(DISABLE_M503)
72
      static void report(const bool forReplay=false);
73
    #else
74
      FORCE_INLINE
75
      static void report(const bool forReplay=false) { UNUSED(forReplay); }
76
    #endif
77
 
78
  private:
79
    static void postprocess();
80
 
81
    #if ENABLED(EEPROM_SETTINGS)
82
 
83
      static bool eeprom_error, validating;
84
 
85
      #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
86
                                         // That can store is enabled
87
        static constexpr uint16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
88
                                                            // live at the very end of the eeprom
89
 
90
      #endif
91
 
92
      static bool _load();
93
      static void write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
94
      static void read_data(int &pos, uint8_t *value, uint16_t size, uint16_t *crc, const bool force=false);
95
      static bool size_error(const uint16_t size);
96
    #endif
97
};
98
 
99
extern MarlinSettings settings;
100
 
101
#endif // CONFIGURATION_STORE_H