Welcome to mirror list, hosted at ThFree Co, Russian Federation.

firmware.cpp « ArcWelderInverseProcessor - github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bab3968ca55af39031e3c8699f41ac0a823f1cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Arc Welder: Inverse Processor (firmware simulator).  
// Please see the copyright notices in the function definitions
//
// Converts G2/G3(arc) commands back to G0/G1 commands.  Intended to test firmware changes to improve arc support.
// This reduces file size and the number of gcodes per second.
// 
// Based on arc interpolation implementations from:
//    Marlin 1.x (see https://github.com/MarlinFirmware/Marlin/blob/1.0.x/LICENSE for the current license)
//    Marlin 2.x (see https://github.com/MarlinFirmware/Marlin/blob/2.0.x/LICENSE for the current license)
//    Prusa-Firmware (see https://github.com/prusa3d/Prusa-Firmware/blob/MK3/LICENSE for the current license)
//    Smoothieware (see https://github.com/Smoothieware/Smoothieware for the current license)
//    Repetier (see https://github.com/repetier/Repetier-Firmware for the current license)
// 
// Built using the 'Arc Welder: Anti Stutter' library
//
// Copyright(C) 2021 - Brad Hochgesang
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU Affero 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 Affero General Public License for more details.
//
//
// You can contact the author at the following email address: 
// FormerLurker@pm.me
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "firmware.h"
#include "utilities.h"

firmware::firmware() {
  version_index_ = -1;
  num_arc_segments_generated_ = 0;
};

firmware::firmware(firmware_arguments args) : args_(args) {
  version_index_ = -1;
  num_arc_segments_generated_ = 0;
};

std::string firmware::interpolate_arc(firmware_position& target, double i, double j, double r, bool is_clockwise)
{
  throw "Function not yet implemented";
}

void firmware::apply_arguments()
{
  throw "Function not yet implemented";
}

void firmware::set_current_position(firmware_position& position)
{
  position_ = position;
}

void firmware::set_current_state(firmware_state& state)
{
  state_ = state;
}

int firmware::get_num_arc_segments_generated()
{
  return num_arc_segments_generated_;
}

std::string firmware::g1_command(firmware_position& target)
{
  num_arc_segments_generated_++;
  std::string gcode = "G1 ";
  gcode.reserve(96);

  bool has_x = position_.x != target.x;
  bool has_y = position_.y != target.y;
  bool has_z = position_.z != target.z;
  bool has_e = position_.e != target.e;
  bool has_f = position_.f != target.f;
  bool is_first_parameter = true;
  if (has_x)
  {
    gcode += is_first_parameter ? "X" : " X";
    gcode += utilities::dtos(state_.is_relative ? target.x - position_.x : target.x, 3);
    is_first_parameter = false;
  }

  if (has_y)
  {
    gcode += is_first_parameter ? "Y" : " Y";
    gcode += utilities::dtos(state_.is_relative ? target.y - position_.y : target.y, 3);
    is_first_parameter = false;
  }

  if (has_z)
  {
    gcode += is_first_parameter ? "Z" : " Z";
    gcode += utilities::dtos(state_.is_relative ? target.z - position_.z : target.z, 3);
    is_first_parameter = false;
  }

  if (has_e)
  {
    gcode += is_first_parameter ? "E" : " E";
    gcode += utilities::dtos(state_.is_extruder_relative ? target.e - position_.e : target.e, 5);
    is_first_parameter = false;
  }

  if (has_f)
  {
    gcode += is_first_parameter ? "F" : " F";
    gcode += utilities::dtos(target.f, 0);
  }
  
  return gcode;
}

bool firmware::is_valid_version(std::string version)
{
  if (version == LATEST_FIRMWARE_VERSION_NAME)
  {
    return true;
  }
  for (std::vector<std::string>::const_iterator i = version_names_.begin(); i != version_names_.end(); ++i) {
    // process i
    if (*i == version)
    {
      return true;
    }
  }
  return false;
}

std::vector<std::string> firmware::get_version_names()
{
  return version_names_;
}

std::string firmware::get_version_names_string()
{
    std::vector<std::string> version_names_with_release_info;
    bool foundLatestRelease = false;
    for (int index = 0; index < version_names_.size(); index++)
    {
        std::string version_name = version_names_[index];
        
        if (foundLatestRelease)
        {
            version_name.append(" (").append("NON_RELEASE_VERSION").append(")");
        }
        else if (version_name == args_.latest_release_version)
        {
            version_name.append(" (").append(LATEST_FIRMWARE_VERSION_NAME).append(")");
            foundLatestRelease = true;
        }
        version_names_with_release_info.push_back(version_name);
    }
    return utilities::join(version_names_with_release_info, ",");
}

bool firmware::get_g90_g91_influences_extruder()
{
  return args_.g90_g91_influences_extruder;
}

std::string firmware::get_arguments_description(std::string separator, std::string argument_prefix, std::string replacement_string, std::string replacement_value) {
  
  return args_.get_arguments_description(separator, argument_prefix, replacement_string, replacement_value);
}

std::string firmware::get_gcode_header_comment()
{
    return args_.get_gcode_header_comment();
}

void firmware::set_versions(std::vector<std::string> version_names, std::string latest_release_version_name)
{
  args_.latest_release_version = latest_release_version_name;
  std::string requested_version = args_.version;
  if (requested_version == LATEST_FIRMWARE_VERSION_NAME || args_.version == latest_release_version_name)
  {
    requested_version = latest_release_version_name;
  }
  version_index_ = (int)version_names.size() - 1;
  for (int i = 0; i < version_names.size(); i++)
  {
    std::string version = version_names[i];
    version_names_.push_back(version);
    if (version == requested_version)
    {
      version_index_ = i;
    }
  }
}

firmware_arguments firmware::get_default_arguments_for_current_version() const
{
  return firmware_arguments();
}

void firmware::set_arguments(firmware_arguments args)
{
  args_ = args;
  this->apply_arguments();
}

firmware_arguments firmware::arguments_changed(firmware_arguments current_args, firmware_arguments new_args)
{
  return new_args;
}