diff --git a/include/Arduino.h b/include/Arduino.h index 82ef463..2e77312 100644 --- a/include/Arduino.h +++ b/include/Arduino.h @@ -101,7 +101,7 @@ extern "C" { } void _delay_ms(const int delay); void delayMicroseconds(unsigned long); -uint32_t millis(); +unsigned long millis(); uint64_t micros(); //IO functions diff --git a/src/MarlinSimulator/application.cpp b/src/MarlinSimulator/application.cpp index e883111..3f2e3c7 100644 --- a/src/MarlinSimulator/application.cpp +++ b/src/MarlinSimulator/application.cpp @@ -116,7 +116,7 @@ Application::Application() { user_interface.addElement("Pin List", [this](UiWindow* window){ for (auto p : pin_array) { bool value = Gpio::get_pin_value(p.pin); - if(ImGui::Checkbox((std::string("##") + p.name).c_str(), &value)) { + if (ImGui::Checkbox((std::string("##") + p.name).c_str(), &value)) { Gpio::set(p.pin, value); } ImGui::SameLine(); @@ -169,7 +169,7 @@ Application::Application() { static pin_type monitor_pin = X_STEP_PIN; static const char* label = "Select Pin"; static char* active_label = (char *)label; - if(ImGui::BeginCombo("##Select Pin", active_label)) { + if (ImGui::BeginCombo("##Select Pin", active_label)) { for (auto p : pin_array) { if (ImGui::Selectable(p.name, p.pin == monitor_pin)) { monitor_pin = p.pin; diff --git a/src/MarlinSimulator/execution_control.cpp b/src/MarlinSimulator/execution_control.cpp index e5c48e2..af7ad11 100644 --- a/src/MarlinSimulator/execution_control.cpp +++ b/src/MarlinSimulator/execution_control.cpp @@ -31,13 +31,13 @@ std::deque Kernel::isr_stack; bool Kernel::quit_requested = false; std::atomic_uint64_t Kernel::isr_timing_error = 0; -bool Kernel::is_initialized(bool known_state) { - static bool is_running = known_state; +bool Kernel::is_initialized(const bool known_state/*=false*/) { + static bool is_running = false; is_running = is_running || known_state; return is_running; } -bool Kernel::execute_loop( uint64_t max_end_ticks) { +bool Kernel::execute_loop(uint64_t max_end_ticks) { // Marlin often gets into reentrant loops, this is the only way to unroll out of that call stack early if (quit_requested) throw (std::runtime_error("Quit Requested")); if (debug_break_flag) { debug_break_flag = false; debug_break(); } @@ -76,7 +76,6 @@ bool Kernel::execute_loop( uint64_t max_end_ticks) { serial_stream_3.receive_buffer.write((uint8_t *)buffer, count); } - uint64_t current_ticks = TimeControl::getTicks(); uint64_t current_priority = std::numeric_limits::max(); auto stack_size = isr_stack.size(); @@ -94,7 +93,7 @@ bool Kernel::execute_loop( uint64_t max_end_ticks) { } } - if (next_isr != nullptr ) { + if (next_isr != nullptr) { if (current_ticks > lowest_isr) { isr_timing_error = TimeControl::ticksToNanos(current_ticks - lowest_isr); next_isr->source_offset = current_ticks; // late interrupt @@ -120,7 +119,7 @@ uint64_t Kernel::TimeControl::nanos() { } // if a thread wants to wait, see what should be executed during that wait -void Kernel::delayCycles(uint64_t cycles) { +void Kernel::delayCycles(const uint64_t cycles) { if (is_initialized()) { auto end = TimeControl::getTicks() + cycles; while (execute_loop(end) && TimeControl::getTicks() < end); @@ -131,13 +130,13 @@ void Kernel::delayCycles(uint64_t cycles) { // this is needed for when marlin loops idle waiting for an event with no delays (syncronize) void Kernel::yield() { if (is_initialized()) { - if(isr_stack.size() == 0) { + if (isr_stack.size() == 0) { // Kernel not started? TimeControl::addTicks(TimeControl::nanosToTicks(100)); return; } auto max_yield = isr_stack.back()->next_interrupt(TimeControl::frequency); - if(!execute_loop(max_yield)) { // dont wait longer than this threads exec period + if (!execute_loop(max_yield)) { // dont wait longer than this threads exec period TimeControl::setTicks(max_yield); isr_stack.back()->source_offset = max_yield; // there was nothing to run, and we now overrun our next cycle. } diff --git a/src/MarlinSimulator/execution_control.h b/src/MarlinSimulator/execution_control.h index 5cf7179..5932e01 100644 --- a/src/MarlinSimulator/execution_control.h +++ b/src/MarlinSimulator/execution_control.h @@ -34,12 +34,11 @@ struct KernelTimer { bool enabled() { return active; } void disable() { active = false; } - // in timer frequency + // In timer frequency void set_compare(const uint64_t compare) { this->compare = compare; } uint64_t get_compare() { return compare; } uint64_t get_count(const uint64_t source_count, const uint64_t source_frequency) { return tickConvertFrequency(source_count - source_offset, source_frequency, timer_frequency); } - void set_isr(std::string name, void (*callback)()) { isr_function = {callback}; this->name = name; @@ -65,9 +64,9 @@ class Kernel { auto now = clock.now(); auto delta = now - last_clock_read; uint64_t delta_uint64 = std::chrono::duration_cast(delta).count(); - if(delta_uint64 > std::numeric_limits::max() - ONE_BILLION) { + if (delta_uint64 > std::numeric_limits::max() - ONE_BILLION) { //printf("rt info: %ld : %f\n", delta_uint64, realtime_scale.load()); - //aparently time can go backwards, thread issue? + // Apparently time can go backwards, thread issue? delta_uint64 = 0; } uint64_t delta_uint64_scaled = delta_uint64 * realtime_scale; @@ -82,7 +81,7 @@ class Kernel { if (getRealtimeTicks() > getTicks() || realtime_scale > 99.0f) { realtime_nanos = SimulationRuntime::nanos(); } else while (getTicks() > getRealtimeTicks()) { - if (quit_requested) throw (std::runtime_error("Quit Requested")); // quit program when stuck at 0 speed + if (quit_requested) throw (std::runtime_error("Quit Requested")); // Quit program when stuck at 0 speed updateRealtime(); realtime_scale > 20.0f ? std::this_thread::yield() : std::this_thread::sleep_for(std::chrono::nanoseconds(1)); } @@ -157,7 +156,7 @@ class Kernel { inline static void timerInit(uint8_t timer_id, uint32_t rate) { if (timer_id < timers.size()) { timers[timer_id].timer_frequency = rate; - // printf("Timer[%d] Initialised( rate: %d )\n", timer_id, rate); + //printf("Timer[%d] Initialised( rate: %d )\n", timer_id, rate); } } @@ -165,14 +164,14 @@ class Kernel { if (timer_id < timers.size()) { timers[timer_id].compare = timers[timer_id].timer_frequency / interrupt_frequency; timers[timer_id].source_offset = TimeControl::getTicks(); - // printf("Timer[%d] Started( frequency: %d compare: %ld)\n", timer_id, interrupt_frequency, timers[timer_id].compare); + //printf("Timer[%d] Started( frequency: %d compare: %ld)\n", timer_id, interrupt_frequency, timers[timer_id].compare); } } inline static void timerEnable(uint8_t timer_id) { if (timer_id < timers.size()) { timers[timer_id].active = true; - // printf("Timer[%d] Enabled\n", timer_id); + //printf("Timer[%d] Enabled\n", timer_id); } } @@ -190,9 +189,7 @@ class Kernel { } inline static void timerSetCompare(uint8_t timer_id, uint64_t compare) { - if (timer_id < timers.size()) { - timers[timer_id].compare = compare; - } + if (timer_id < timers.size()) timers[timer_id].compare = compare; } inline static uint64_t timerGetCount(uint8_t timer_id) { @@ -214,13 +211,13 @@ class Kernel { // To avoid issues with global initialization order, this should be called with a true value // to enable operation of execute_loop. - static bool is_initialized(bool known_state = false); + static bool is_initialized(const bool known_state = false); - //execute highest priority thread with closest interrupt, return true if something was executed + // Execute highest priority thread with closest interrupt, return true if something was executed static bool execute_loop(uint64_t max_end_ticks = std::numeric_limits::max()); - // if a thread wants to wait, see what should be executed during that wait - static void delayCycles(uint64_t cycles); - // this was neede for when marlin loops idle waiting for an event with no delays + // If a thread wants to wait, see what should be executed during that wait + static void delayCycles(const uint64_t cycles); + // This was needed for when marlin loops idle waiting for an event with no delays static void yield(); static void shutdown() { @@ -230,14 +227,9 @@ class Kernel { static void execution_break() { debug_break_flag = true; } - //Timers - inline static void disableInterrupts() { - timers_active = false; - } - - inline static void enableInterrupts() { - timers_active = true; - } + // Timers + inline static void disableInterrupts() { timers_active = false; } + inline static void enableInterrupts() { timers_active = true; } inline static void delayNanos(uint64_t ns) { delayCycles(TimeControl::nanosToTicks(ns)); diff --git a/src/MarlinSimulator/hardware/Button.h b/src/MarlinSimulator/hardware/Button.h index 1e78170..54bf68c 100644 --- a/src/MarlinSimulator/hardware/Button.h +++ b/src/MarlinSimulator/hardware/Button.h @@ -16,7 +16,7 @@ class Button : public VirtualPrinter::Component { void ui_widget() { ImGui::Button("State"); - if(ImGui::IsItemActive()) { + if (ImGui::IsItemActive()) { active = invert_logic; } else { active = !invert_logic; diff --git a/src/MarlinSimulator/hardware/HD44780Device.cpp b/src/MarlinSimulator/hardware/HD44780Device.cpp index 4ced52f..ce9d75c 100644 --- a/src/MarlinSimulator/hardware/HD44780Device.cpp +++ b/src/MarlinSimulator/hardware/HD44780Device.cpp @@ -38,8 +38,12 @@ HD44780Device::HD44780Device(pin_type rs, pin_type en, pin_type d4, pin_type d5, active_rom = hd44780_a00_rom; #elif DISPLAY_CHARSET_HD44780 == WESTERN active_rom = hd44780_a02_rom; + #elif DISPLAY_CHARSET_HD44780 == CYRILLIC + active_rom = hd44780_a02_rom; + #warning "CYRILLIC HD44780 Character ROM not available. Falling back to WESTERN." #else - #error Unavailable HD44780 Character ROM + active_rom = hd44780_a02_rom; + #warning "Unknown HD44780 Character ROM. Falling back to WESTERN." #endif } @@ -143,7 +147,7 @@ void HD44780Device::update() { } void HD44780Device::interrupt(GpioEvent& ev) { - if(ev.pin_id == en_pin && ev.event == GpioEvent::RISE) { + if (ev.pin_id == en_pin && ev.event == GpioEvent::RISE) { //read the bus data_byte |= (Gpio::get_pin_value(d7_pin) << 3 | Gpio::get_pin_value(d6_pin) << 2 | Gpio::get_pin_value(d5_pin) << 1 |Gpio::get_pin_value(d4_pin)) << (4 * !data_low_nibble); data_low_nibble = !data_low_nibble; diff --git a/src/MarlinSimulator/hardware/bus/spi.h b/src/MarlinSimulator/hardware/bus/spi.h index f74da8c..9a4c902 100644 --- a/src/MarlinSimulator/hardware/bus/spi.h +++ b/src/MarlinSimulator/hardware/bus/spi.h @@ -70,7 +70,7 @@ class SpiBus { callbacks.push_back(std::function(args...)); } - void acquire() { if(busy == true) printf("spi bus contention!\n"); busy = true; } + void acquire() { if (busy) printf("spi bus contention!\n"); busy = true; } void release() { busy = false; } bool is_busy() { return busy; } diff --git a/src/MarlinSimulator/marlin_arduino_impl/Stream.cpp b/src/MarlinSimulator/marlin_arduino_impl/Stream.cpp index 6ac7281..bfc9301 100644 --- a/src/MarlinSimulator/marlin_arduino_impl/Stream.cpp +++ b/src/MarlinSimulator/marlin_arduino_impl/Stream.cpp @@ -128,22 +128,22 @@ long Stream::parseInt(char skipChar) c = peekNextDigit(); // ignore non numeric leading characters - if(c < 0) + if (c < 0) return 0; // zero returned if timeout - do{ - if(c == skipChar) + do { + if (c == skipChar) ; // ignore this charactor - else if(c == '-') + else if (c == '-') isNegative = true; - else if(c >= '0' && c <= '9') // is c a digit? + else if (c >= '0' && c <= '9') // is c a digit? value = value * 10 + c - '0'; read(); // consume the character we got with peek c = timedPeek(); } while( (c >= '0' && c <= '9') || c == skipChar ); - if(isNegative) + if (isNegative) value = -value; return value; } @@ -165,20 +165,20 @@ float Stream::parseFloat(char skipChar){ float fraction = 1.0; c = peekNextDigit(); - // ignore non numeric leading characters - if(c < 0) + // ignore non numeric leading characters + if (c < 0) return 0; // zero returned if timeout - do{ - if(c == skipChar) + do { + if (c == skipChar) ; // ignore - else if(c == '-') + else if (c == '-') isNegative = true; else if (c == '.') isFraction = true; - else if(c >= '0' && c <= '9') { // is c a digit? + else if (c >= '0' && c <= '9') { // is c a digit? value = value * 10 + c - '0'; - if(isFraction) + if (isFraction) fraction *= 0.1; } read(); // consume the character we got with peek @@ -186,9 +186,9 @@ float Stream::parseFloat(char skipChar){ } while( (c >= '0' && c <= '9') || c == '.' || c == skipChar ); - if(isNegative) + if (isNegative) value = -value; - if(isFraction) + if (isFraction) return value * fraction; else return value; diff --git a/src/MarlinSimulator/marlin_arduino_impl/arduino.cpp b/src/MarlinSimulator/marlin_arduino_impl/arduino.cpp index 54451f7..a082d77 100644 --- a/src/MarlinSimulator/marlin_arduino_impl/arduino.cpp +++ b/src/MarlinSimulator/marlin_arduino_impl/arduino.cpp @@ -81,6 +81,9 @@ uint16_t analogRead(pin_t adc_pin) { return Gpio::get(digitalPinToAnalogIndex(adc_pin)); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s) { char format_string[20]; snprintf(format_string, 20, "%%%d.%df", __width, __prec); @@ -88,6 +91,8 @@ char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s return __s; } +#pragma GCC diagnostic pop + int32_t random(int32_t max) { return rand() % max; } diff --git a/src/MarlinSimulator/resources/resources.cpp b/src/MarlinSimulator/resources/resources.cpp index 1972368..886b0f4 100644 --- a/src/MarlinSimulator/resources/resources.cpp +++ b/src/MarlinSimulator/resources/resources.cpp @@ -25,7 +25,7 @@ namespace resource { std::streamsize size = file.tellg(); file.seekg(0, std::ios::beg); m_data.reserve(size + 1); - if(file.read(m_data.data(), size)) { + if (file.read(m_data.data(), size)) { m_buffer = m_data.data(); m_data[size] = 0; } else { diff --git a/src/MarlinSimulator/visualisation.cpp b/src/MarlinSimulator/visualisation.cpp index 2da7726..7b55ef1 100644 --- a/src/MarlinSimulator/visualisation.cpp +++ b/src/MarlinSimulator/visualisation.cpp @@ -122,7 +122,7 @@ void Visualisation::create() { } auto kin = virtual_printer.get_component("Cartesian Kinematic System"); - if(kin == nullptr) kin = virtual_printer.get_component("Delta Kinematic System"); + if (kin == nullptr) kin = virtual_printer.get_component("Delta Kinematic System"); if (kin != nullptr && kin->state.effector_position.size() == extrusion.size()) { size_t i = 0; for (auto state : kin->state.effector_position) { @@ -250,7 +250,7 @@ void Visualisation::update() { } void Visualisation::destroy() { - if(framebuffer != nullptr) { + if (framebuffer != nullptr) { framebuffer->release(); delete framebuffer; } @@ -283,7 +283,7 @@ void Visualisation::set_head_position(size_t hotend_index, extruder_state& state if (active_buffer != nullptr && active_buffer->size() > 1 && active_buffer->size() < renderer::MAX_BUFFER_SIZE) { if (glm::length(glm::vec3(position) - glm::vec3(extruder.last_position)) > m_config.extrusion_segment_minimum_length) { // smooth out the path so the model renders with less geometry, rendering each individual step hurts the fps - if((points_are_collinear(position, active_buffer->cdata().end()[-3].position, active_buffer->cdata().end()[-2].position, m_config.extrusion_segment_collinearity_max_deviation) && extruder.extruding == extruder.last_extruding) || ( extruder.extruding == false && extruder.last_extruding == false)) { + if ((points_are_collinear(position, active_buffer->cdata().end()[-3].position, active_buffer->cdata().end()[-2].position, m_config.extrusion_segment_collinearity_max_deviation) && extruder.extruding == extruder.last_extruding) || ( extruder.extruding == false && extruder.last_extruding == false)) { // collinear and extrusion state has not changed so we can just change the current point. active_buffer->data().end()[-2].position = position; active_buffer->data().end()[-1].position = position; @@ -464,18 +464,18 @@ void Visualisation::ui_viewport_callback(UiWindow* window) { } // IMGUI: Relative Mouse mode within a window does not seem to be supported through the imgui mouse api - if (mouse_captured && !last_mouse_captured) { + if (mouse_captured && !last_mouse_captured) { // Mouse button was just pressed ImVec2 mouse_pos = ImGui::GetMousePos(); - mouse_lock_pos = {mouse_pos.x, mouse_pos.y}; + mouse_lock_pos = { mouse_pos.x, mouse_pos.y }; SDL_SetWindowGrab(SDL_GL_GetCurrentWindow(), SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE); SDL_GetRelativeMouseState(nullptr, nullptr); - } else if (!mouse_captured && last_mouse_captured) { + } else if (!mouse_captured && last_mouse_captured) { // Mouse button was just released SDL_SetRelativeMouseMode(SDL_FALSE); SDL_SetWindowGrab(SDL_GL_GetCurrentWindow(), SDL_FALSE); SDL_WarpMouseInWindow(SDL_GL_GetCurrentWindow(), mouse_lock_pos.x, mouse_lock_pos.y); SDL_GetRelativeMouseState(nullptr, nullptr); - } else if (mouse_captured) { + } else if (mouse_captured) { // Mouse button is being held int rel_x, rel_y; SDL_GetRelativeMouseState(&rel_x, &rel_y); camera.rotation.x -= rel_x * 0.2; diff --git a/src/MarlinSimulator/visualisation.h b/src/MarlinSimulator/visualisation.h index 7c2ce09..636d6fb 100644 --- a/src/MarlinSimulator/visualisation.h +++ b/src/MarlinSimulator/visualisation.h @@ -160,7 +160,6 @@ class Visualisation { std::shared_ptr default_program; bool mouse_captured = false; - bool input_state[6] = {}; glm::vec<2, int> mouse_lock_pos; #define BED_NORMAL 0.0, 1.0, 0.0 diff --git a/src/MarlinSimulator/window.cpp b/src/MarlinSimulator/window.cpp index 6e1060a..b2cfb26 100644 --- a/src/MarlinSimulator/window.cpp +++ b/src/MarlinSimulator/window.cpp @@ -148,5 +148,5 @@ void* Window::getHandle() { } void Window::swap_buffers() { - if(window_impl::window_valid) SDL_GL_SwapWindow(window_impl::window); + if (window_impl::window_valid) SDL_GL_SwapWindow(window_impl::window); }