Merge branch 'bugfix-2.0.x' of https://github.com/MarlinFirmware/Marlin into bugfix-2.0.x
This commit is contained in:
213
Marlin/src/lcd/menu/game/brickout.cpp
Normal file
213
Marlin/src/lcd/menu/game/brickout.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(MARLIN_BRICKOUT)
|
||||
|
||||
#include "game.h"
|
||||
|
||||
#define BRICK_H 5
|
||||
#define BRICK_TOP MENU_FONT_ASCENT
|
||||
#define BRICK_ROWS 4
|
||||
#define BRICK_COLS 16
|
||||
|
||||
#define PADDLE_H 2
|
||||
#define PADDLE_VEL 3
|
||||
#define PADDLE_W ((LCD_PIXEL_WIDTH) / 8)
|
||||
#define PADDLE_Y (LCD_PIXEL_HEIGHT - 1 - PADDLE_H)
|
||||
|
||||
#define BRICK_W ((LCD_PIXEL_WIDTH) / (BRICK_COLS))
|
||||
#define BRICK_BOT (BRICK_TOP + BRICK_H * BRICK_ROWS - 1)
|
||||
|
||||
#define BRICK_COL(X) ((X) / (BRICK_W))
|
||||
#define BRICK_ROW(Y) ((Y - (BRICK_TOP)) / (BRICK_H))
|
||||
|
||||
uint8_t balls_left, brick_count;
|
||||
uint16_t bricks[BRICK_ROWS];
|
||||
|
||||
inline void reset_bricks(const uint16_t v) {
|
||||
brick_count = (BRICK_COLS) * (BRICK_ROWS);
|
||||
LOOP_L_N(i, BRICK_ROWS) bricks[i] = v;
|
||||
}
|
||||
|
||||
int8_t paddle_x, hit_dir;
|
||||
fixed_t ballx, bally, ballh, ballv;
|
||||
|
||||
void reset_ball() {
|
||||
constexpr uint8_t ball_dist = 24;
|
||||
bally = BTOF(PADDLE_Y - ball_dist);
|
||||
ballv = FTOP(1.3f);
|
||||
ballh = -FTOP(1.25f);
|
||||
uint8_t bx = paddle_x + (PADDLE_W) / 2 + ball_dist;
|
||||
if (bx >= LCD_PIXEL_WIDTH - 10) { bx -= ball_dist * 2; ballh = -ballh; }
|
||||
ballx = BTOF(bx);
|
||||
hit_dir = -1;
|
||||
}
|
||||
|
||||
void BrickoutGame::game_screen() {
|
||||
if (game_frame()) { // Run logic twice for finer resolution
|
||||
// Update Paddle Position
|
||||
paddle_x = (int8_t)ui.encoderPosition;
|
||||
paddle_x = constrain(paddle_x, 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL));
|
||||
ui.encoderPosition = paddle_x;
|
||||
paddle_x *= (PADDLE_VEL);
|
||||
|
||||
// Run the ball logic
|
||||
if (game_state) do {
|
||||
|
||||
// Provisionally update the ball position
|
||||
const fixed_t newx = ballx + ballh, newy = bally + ballv; // current next position
|
||||
if (!WITHIN(newx, 0, BTOF(LCD_PIXEL_WIDTH - 1))) { // out in x?
|
||||
ballh = -ballh; _BUZZ(5, 220); // bounce x
|
||||
}
|
||||
if (newy < 0) { // out in y?
|
||||
ballv = -ballv; _BUZZ(5, 280); // bounce v
|
||||
hit_dir = 1;
|
||||
}
|
||||
// Did the ball go below the bottom?
|
||||
else if (newy > BTOF(LCD_PIXEL_HEIGHT)) {
|
||||
BUZZ(500, 75);
|
||||
if (--balls_left) reset_ball(); else game_state = 0;
|
||||
break; // done
|
||||
}
|
||||
|
||||
// Is the ball colliding with a brick?
|
||||
if (WITHIN(newy, BTOF(BRICK_TOP), BTOF(BRICK_BOT))) {
|
||||
const int8_t bit = BRICK_COL(FTOB(newx)), row = BRICK_ROW(FTOB(newy));
|
||||
const uint16_t mask = _BV(bit);
|
||||
if (bricks[row] & mask) {
|
||||
// Yes. Remove it!
|
||||
bricks[row] &= ~mask;
|
||||
// Score!
|
||||
score += BRICK_ROWS - row;
|
||||
// If bricks are gone, go to reset state
|
||||
if (!--brick_count) game_state = 2;
|
||||
// Bounce the ball cleverly
|
||||
if ((ballv < 0) == (hit_dir < 0)) { ballv = -ballv; ballh += fixed_t(random(-16, 16)); _BUZZ(5, 880); }
|
||||
else { ballh = -ballh; ballv += fixed_t(random(-16, 16)); _BUZZ(5, 640); }
|
||||
}
|
||||
}
|
||||
// Is the ball moving down and in paddle range?
|
||||
else if (ballv > 0 && WITHIN(newy, BTOF(PADDLE_Y), BTOF(PADDLE_Y + PADDLE_H))) {
|
||||
// Ball actually hitting paddle
|
||||
const int8_t diff = FTOB(newx) - paddle_x;
|
||||
if (WITHIN(diff, 0, PADDLE_W - 1)) {
|
||||
|
||||
// Reverse Y direction
|
||||
ballv = -ballv; _BUZZ(3, 880);
|
||||
hit_dir = -1;
|
||||
|
||||
// Near edges affects X velocity
|
||||
const bool is_left_edge = (diff <= 1);
|
||||
if (is_left_edge || diff >= PADDLE_W-1 - 1) {
|
||||
if ((ballh > 0) == is_left_edge) ballh = -ballh;
|
||||
}
|
||||
else if (diff <= 3) {
|
||||
ballh += fixed_t(random(-64, 0));
|
||||
NOLESS(ballh, BTOF(-2));
|
||||
NOMORE(ballh, BTOF(2));
|
||||
}
|
||||
else if (diff >= PADDLE_W-1 - 3) {
|
||||
ballh += fixed_t(random( 0, 64));
|
||||
NOLESS(ballh, BTOF(-2));
|
||||
NOMORE(ballh, BTOF(2));
|
||||
}
|
||||
|
||||
// Paddle hit after clearing the board? Reset the board.
|
||||
if (game_state == 2) { reset_bricks(0xFFFF); game_state = 1; }
|
||||
}
|
||||
}
|
||||
|
||||
ballx += ballh; bally += ballv; // update with new velocity
|
||||
|
||||
} while (false);
|
||||
}
|
||||
|
||||
u8g.setColorIndex(1);
|
||||
|
||||
// Draw bricks
|
||||
if (PAGE_CONTAINS(BRICK_TOP, BRICK_BOT)) {
|
||||
for (uint8_t y = 0; y < BRICK_ROWS; ++y) {
|
||||
const uint8_t yy = y * BRICK_H + BRICK_TOP;
|
||||
if (PAGE_CONTAINS(yy, yy + BRICK_H - 1)) {
|
||||
for (uint8_t x = 0; x < BRICK_COLS; ++x) {
|
||||
if (TEST(bricks[y], x)) {
|
||||
const uint8_t xx = x * BRICK_W;
|
||||
for (uint8_t v = 0; v < BRICK_H - 1; ++v)
|
||||
if (PAGE_CONTAINS(yy + v, yy + v))
|
||||
u8g.drawHLine(xx, yy + v, BRICK_W - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw paddle
|
||||
if (PAGE_CONTAINS(PADDLE_Y-1, PADDLE_Y)) {
|
||||
u8g.drawHLine(paddle_x, PADDLE_Y, PADDLE_W);
|
||||
#if PADDLE_H > 1
|
||||
u8g.drawHLine(paddle_x, PADDLE_Y-1, PADDLE_W);
|
||||
#if PADDLE_H > 2
|
||||
u8g.drawHLine(paddle_x, PADDLE_Y-2, PADDLE_W);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw ball while game is running
|
||||
if (game_state) {
|
||||
const uint8_t by = FTOB(bally);
|
||||
if (PAGE_CONTAINS(by, by+1))
|
||||
u8g.drawFrame(FTOB(ballx), by, 2, 2);
|
||||
}
|
||||
// Or draw GAME OVER
|
||||
else
|
||||
draw_game_over();
|
||||
|
||||
if (PAGE_UNDER(MENU_FONT_ASCENT)) {
|
||||
// Score Digits
|
||||
//const uint8_t sx = (LCD_PIXEL_WIDTH - (score >= 10 ? score >= 100 ? score >= 1000 ? 4 : 3 : 2 : 1) * MENU_FONT_WIDTH) / 2;
|
||||
constexpr uint8_t sx = 0;
|
||||
lcd_moveto(sx, MENU_FONT_ASCENT - 1);
|
||||
lcd_put_int(score);
|
||||
|
||||
// Balls Left
|
||||
lcd_moveto(LCD_PIXEL_WIDTH - MENU_FONT_WIDTH * 3, MENU_FONT_ASCENT - 1);
|
||||
PGM_P const ohs = PSTR("ooo\0\0");
|
||||
lcd_put_u8str_P(ohs + 3 - balls_left);
|
||||
}
|
||||
|
||||
// A click always exits this game
|
||||
if (ui.use_click()) exit_game();
|
||||
}
|
||||
|
||||
void BrickoutGame::enter_game() {
|
||||
init_game(2, game_screen); // 2 = reset bricks on paddle hit
|
||||
constexpr uint8_t paddle_start = SCREEN_M - (PADDLE_W) / 2;
|
||||
paddle_x = paddle_start;
|
||||
balls_left = 3;
|
||||
reset_bricks(0x0000);
|
||||
reset_ball();
|
||||
ui.encoderPosition = paddle_start / (PADDLE_VEL);
|
||||
}
|
||||
|
||||
#endif // MARLIN_BRICKOUT
|
68
Marlin/src/lcd/menu/game/game.cpp
Normal file
68
Marlin/src/lcd/menu/game/game.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GAMES
|
||||
|
||||
#include "game.h"
|
||||
|
||||
int MarlinGame::score;
|
||||
uint8_t MarlinGame::game_state;
|
||||
millis_t MarlinGame::next_frame;
|
||||
|
||||
bool MarlinGame::game_frame() {
|
||||
static int8_t slew;
|
||||
if (ui.first_page) slew = 2;
|
||||
ui.refresh(LCDVIEW_CALL_NO_REDRAW); // Refresh as often as possible
|
||||
return (game_state && slew-- > 0);
|
||||
}
|
||||
|
||||
void MarlinGame::draw_game_over() {
|
||||
constexpr int8_t gowide = (MENU_FONT_WIDTH) * 9,
|
||||
gohigh = MENU_FONT_ASCENT - 3,
|
||||
lx = (LCD_PIXEL_WIDTH - gowide) / 2,
|
||||
ly = (LCD_PIXEL_HEIGHT + gohigh) / 2;
|
||||
if (PAGE_CONTAINS(ly - gohigh - 1, ly + 1)) {
|
||||
u8g.setColorIndex(0);
|
||||
u8g.drawBox(lx - 1, ly - gohigh - 1, gowide + 2, gohigh + 2);
|
||||
u8g.setColorIndex(1);
|
||||
if (ui.get_blink()) {
|
||||
lcd_moveto(lx, ly);
|
||||
lcd_put_u8str_P(PSTR("GAME OVER"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MarlinGame::init_game(const uint8_t init_state, const screenFunc_t screen) {
|
||||
score = 0;
|
||||
game_state = init_state;
|
||||
ui.encoder_direction_normal();
|
||||
ui.goto_screen(screen);
|
||||
ui.defer_status_screen();
|
||||
}
|
||||
|
||||
void MarlinGame::exit_game() {
|
||||
ui.goto_previous_screen_no_defer();
|
||||
}
|
||||
|
||||
#endif // HAS_GAMES
|
78
Marlin/src/lcd/menu/game/game.h
Normal file
78
Marlin/src/lcd/menu/game/game.h
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* 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
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
#include "../../dogm/ultralcd_DOGM.h"
|
||||
#include "../../lcdprint.h"
|
||||
#include "../../ultralcd.h"
|
||||
|
||||
//#define MUTE_GAMES
|
||||
|
||||
#ifdef MUTE_GAMES
|
||||
#define _BUZZ(D,F) NOOP
|
||||
#else
|
||||
#define _BUZZ(D,F) BUZZ(D,F)
|
||||
#endif
|
||||
|
||||
// Simple 8:8 fixed-point
|
||||
typedef int16_t fixed_t;
|
||||
#define FTOP(F) fixed_t((F)*256.0f)
|
||||
#define PTOF(P) (float(P)*(1.0f/256.0f))
|
||||
#define BTOF(X) (fixed_t(X)<<8)
|
||||
#define FTOB(X) int8_t(fixed_t(X)>>8)
|
||||
|
||||
#define SCREEN_M ((LCD_PIXEL_WIDTH) / 2)
|
||||
|
||||
#if HAS_GAME_MENU
|
||||
void menu_game();
|
||||
#endif
|
||||
|
||||
class MarlinGame {
|
||||
protected:
|
||||
static int score;
|
||||
static uint8_t game_state;
|
||||
static millis_t next_frame;
|
||||
|
||||
static bool game_frame();
|
||||
static void draw_game_over();
|
||||
static void exit_game();
|
||||
public:
|
||||
static void init_game(const uint8_t init_state, const screenFunc_t screen);
|
||||
};
|
||||
|
||||
#if ENABLED(MARLIN_BRICKOUT)
|
||||
class BrickoutGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
|
||||
extern BrickoutGame brickout;
|
||||
#endif
|
||||
#if ENABLED(MARLIN_INVADERS)
|
||||
class InvadersGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
|
||||
extern InvadersGame invaders;
|
||||
#endif
|
||||
#if ENABLED(MARLIN_SNAKE)
|
||||
class SnakeGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
|
||||
extern SnakeGame snake;
|
||||
#endif
|
||||
#if ENABLED(MARLIN_MAZE)
|
||||
class MazeGame : MarlinGame { public: static void enter_game(); static void game_screen(); };
|
||||
extern MazeGame maze;
|
||||
#endif
|
468
Marlin/src/lcd/menu/game/invaders.cpp
Normal file
468
Marlin/src/lcd/menu/game/invaders.cpp
Normal file
@ -0,0 +1,468 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(MARLIN_INVADERS)
|
||||
|
||||
#include "game.h"
|
||||
|
||||
// 11x8
|
||||
const unsigned char invader[3][2][16] PROGMEM = {
|
||||
{ { B00000110,B00000000,
|
||||
B00001111,B00000000,
|
||||
B00011111,B10000000,
|
||||
B00110110,B11000000,
|
||||
B00111111,B11000000,
|
||||
B00001001,B00000000,
|
||||
B00010110,B10000000,
|
||||
B00101001,B01000000
|
||||
}, {
|
||||
B00000110,B00000000,
|
||||
B00001111,B00000000,
|
||||
B00011111,B10000000,
|
||||
B00110110,B11000000,
|
||||
B00111111,B11000000,
|
||||
B00010110,B10000000,
|
||||
B00100000,B01000000,
|
||||
B00010000,B10000000
|
||||
}
|
||||
}, {
|
||||
{ B00010000,B01000000,
|
||||
B00001000,B10000000,
|
||||
B00011111,B11000000,
|
||||
B00110111,B01100000,
|
||||
B01111111,B11110000,
|
||||
B01011111,B11010000,
|
||||
B01010000,B01010000,
|
||||
B00001101,B10000000
|
||||
}, {
|
||||
B00010000,B01000000,
|
||||
B01001000,B10010000,
|
||||
B01011111,B11010000,
|
||||
B01110111,B01110000,
|
||||
B01111111,B11110000,
|
||||
B00011111,B11000000,
|
||||
B00010000,B01000000,
|
||||
B00100000,B00100000
|
||||
}
|
||||
}, {
|
||||
{ B00001111,B00000000,
|
||||
B01111111,B11100000,
|
||||
B11111111,B11110000,
|
||||
B11100110,B01110000,
|
||||
B11111111,B11110000,
|
||||
B00011001,B10000000,
|
||||
B00110110,B11000000,
|
||||
B11000000,B00110000
|
||||
}, {
|
||||
B00001111,B00000000,
|
||||
B01111111,B11100000,
|
||||
B11111111,B11110000,
|
||||
B11100110,B01110000,
|
||||
B11111111,B11110000,
|
||||
B00011001,B10000000,
|
||||
B00110110,B11000000,
|
||||
B00011001,B10000000
|
||||
}
|
||||
}
|
||||
};
|
||||
const unsigned char cannon[] PROGMEM = {
|
||||
B00000100,B00000000,
|
||||
B00001110,B00000000,
|
||||
B00001110,B00000000,
|
||||
B01111111,B11000000,
|
||||
B11111111,B11100000,
|
||||
B11111111,B11100000,
|
||||
B11111111,B11100000,
|
||||
B11111111,B11100000
|
||||
};
|
||||
const unsigned char life[] PROGMEM = {
|
||||
B00010000,
|
||||
B01111100,
|
||||
B11111110,
|
||||
B11111110,
|
||||
B11111110
|
||||
};
|
||||
const unsigned char explosion[] PROGMEM = {
|
||||
B01000100,B01000000,
|
||||
B00100100,B10000000,
|
||||
B00000000,B00000000,
|
||||
B00110001,B10000000,
|
||||
B00000000,B00000000,
|
||||
B00100100,B10000000,
|
||||
B01000100,B01000000
|
||||
};
|
||||
const unsigned char ufo[] PROGMEM = {
|
||||
B00011111,B11000000,
|
||||
B01111111,B11110000,
|
||||
B11011101,B11011000,
|
||||
B11111111,B11111000,
|
||||
B01111111,B11110000
|
||||
};
|
||||
|
||||
#define INVASION_SIZE 3
|
||||
|
||||
#if INVASION_SIZE == 3
|
||||
#define INVADER_COLS 5
|
||||
#elif INVASION_SIZE == 4
|
||||
#define INVADER_COLS 6
|
||||
#else
|
||||
#define INVADER_COLS 8
|
||||
#undef INVASION_SIZE
|
||||
#define INVASION_SIZE 5
|
||||
#endif
|
||||
|
||||
#define INVADER_ROWS INVASION_SIZE
|
||||
|
||||
constexpr uint8_t inv_type[] = {
|
||||
#if INVADER_ROWS == 5
|
||||
0, 1, 1, 2, 2
|
||||
#elif INVADER_ROWS == 4
|
||||
0, 1, 1, 2
|
||||
#elif INVADER_ROWS == 3
|
||||
0, 1, 2
|
||||
#else
|
||||
#error "INVASION_SIZE must be 3, 4, or 5."
|
||||
#endif
|
||||
};
|
||||
|
||||
#define INVADER_RIGHT ((INVADER_COLS) * (COL_W))
|
||||
|
||||
#define CANNON_W 11
|
||||
#define CANNON_H 8
|
||||
#define CANNON_VEL 4
|
||||
#define CANNON_Y (LCD_PIXEL_HEIGHT - 1 - CANNON_H)
|
||||
|
||||
#define COL_W 14
|
||||
#define INVADER_H 8
|
||||
#define ROW_H (INVADER_H + 2)
|
||||
#define INVADER_VEL 3
|
||||
|
||||
#define INVADER_TOP MENU_FONT_ASCENT
|
||||
#define INVADERS_WIDE ((COL_W) * (INVADER_COLS))
|
||||
#define INVADERS_HIGH ((ROW_H) * (INVADER_ROWS))
|
||||
|
||||
#define UFO_H 5
|
||||
#define UFO_W 13
|
||||
|
||||
#define LASER_H 4
|
||||
#define SHOT_H 3
|
||||
#define EXPL_W 11
|
||||
#define LIFE_W 8
|
||||
#define LIFE_H 5
|
||||
|
||||
#define INVADER_COL(X) ((X - invaders_x) / (COL_W))
|
||||
#define INVADER_ROW(Y) ((Y - invaders_y + 2) / (ROW_H))
|
||||
|
||||
#define INV_X_LEFT(C,T) (invaders_x + (C) * (COL_W) + inv_off[T])
|
||||
#define INV_X_CTR(C,T) (INV_X_LEFT(C,T) + inv_wide[T] / 2)
|
||||
#define INV_Y_BOT(R) (invaders_y + (R + 1) * (ROW_H) - 2)
|
||||
|
||||
typedef struct { int8_t x, y, v; } laser_t;
|
||||
|
||||
uint8_t cannons_left;
|
||||
int8_t cannon_x;
|
||||
laser_t explod, laser, bullet[10];
|
||||
constexpr uint8_t inv_off[] = { 2, 1, 0 }, inv_wide[] = { 8, 11, 12 };
|
||||
int8_t invaders_x, invaders_y, invaders_dir, leftmost, rightmost, botmost;
|
||||
uint8_t invader_count, quit_count, bugs[INVADER_ROWS], shooters[(INVADER_ROWS) * (INVADER_COLS)];
|
||||
|
||||
inline void update_invader_data() {
|
||||
uint8_t inv_mask = 0;
|
||||
// Get a list of all active invaders
|
||||
uint8_t sc = 0;
|
||||
LOOP_L_N(y, INVADER_ROWS) {
|
||||
uint8_t m = bugs[y];
|
||||
if (m) botmost = y + 1;
|
||||
inv_mask |= m;
|
||||
for (uint8_t x = 0; x < INVADER_COLS; ++x)
|
||||
if (TEST(m, x)) shooters[sc++] = (y << 4) | x;
|
||||
}
|
||||
leftmost = 0;
|
||||
LOOP_L_N(i, INVADER_COLS) { if (TEST(inv_mask, i)) break; leftmost -= COL_W; }
|
||||
rightmost = LCD_PIXEL_WIDTH - (INVADERS_WIDE);
|
||||
for (uint8_t i = INVADER_COLS; i--;) { if (TEST(inv_mask, i)) break; rightmost += COL_W; }
|
||||
if (invader_count == 2) invaders_dir = invaders_dir > 0 ? INVADER_VEL + 1 : -(INVADER_VEL + 1);
|
||||
}
|
||||
|
||||
inline void reset_bullets() {
|
||||
LOOP_L_N(i, COUNT(bullet)) bullet[i].v = 0;
|
||||
}
|
||||
|
||||
inline void reset_invaders() {
|
||||
invaders_x = 0; invaders_y = INVADER_TOP;
|
||||
invaders_dir = INVADER_VEL;
|
||||
invader_count = (INVADER_COLS) * (INVADER_ROWS);
|
||||
LOOP_L_N(i, INVADER_ROWS) bugs[i] = _BV(INVADER_COLS) - 1;
|
||||
update_invader_data();
|
||||
reset_bullets();
|
||||
}
|
||||
|
||||
int8_t ufox, ufov;
|
||||
inline void spawn_ufo() {
|
||||
ufov = random(0, 2) ? 1 : -1;
|
||||
ufox = ufov > 0 ? -(UFO_W) : LCD_PIXEL_WIDTH - 1;
|
||||
}
|
||||
|
||||
inline void reset_player() {
|
||||
cannon_x = 0;
|
||||
ui.encoderPosition = 0;
|
||||
}
|
||||
|
||||
inline void fire_cannon() {
|
||||
laser.x = cannon_x + CANNON_W / 2;
|
||||
laser.y = LCD_PIXEL_HEIGHT - CANNON_H - (LASER_H);
|
||||
laser.v = -(LASER_H);
|
||||
}
|
||||
|
||||
inline void explode(const int8_t x, const int8_t y, const int8_t v=4) {
|
||||
explod.x = x - (EXPL_W) / 2;
|
||||
explod.y = y;
|
||||
explod.v = v;
|
||||
}
|
||||
|
||||
inline void kill_cannon(uint8_t &game_state, const uint8_t st) {
|
||||
reset_bullets();
|
||||
explode(cannon_x + (CANNON_W) / 2, CANNON_Y, 6);
|
||||
_BUZZ(1000, 10);
|
||||
if (--cannons_left) {
|
||||
laser.v = 0;
|
||||
game_state = st;
|
||||
reset_player();
|
||||
}
|
||||
else
|
||||
game_state = 0;
|
||||
}
|
||||
|
||||
void InvadersGame::game_screen() {
|
||||
static bool game_blink;
|
||||
|
||||
ui.refresh(LCDVIEW_CALL_NO_REDRAW); // Call as often as possible
|
||||
|
||||
// Run game logic once per full screen
|
||||
if (ui.first_page) {
|
||||
|
||||
// Update Cannon Position
|
||||
int16_t ep = int16_t(ui.encoderPosition);
|
||||
ep = constrain(ep, 0, (LCD_PIXEL_WIDTH - (CANNON_W)) / (CANNON_VEL));
|
||||
ui.encoderPosition = ep;
|
||||
|
||||
ep *= (CANNON_VEL);
|
||||
if (ep > cannon_x) { cannon_x += CANNON_VEL - 1; if (ep - cannon_x < 2) cannon_x = ep; }
|
||||
if (ep < cannon_x) { cannon_x -= CANNON_VEL - 1; if (cannon_x - ep < 2) cannon_x = ep; }
|
||||
|
||||
// Run the game logic
|
||||
if (game_state) do {
|
||||
|
||||
// Move the UFO, if any
|
||||
if (ufov) { ufox += ufov; if (!WITHIN(ufox, -(UFO_W), LCD_PIXEL_WIDTH - 1)) ufov = 0; }
|
||||
|
||||
if (game_state > 1) { if (--game_state == 2) { reset_invaders(); } else if (game_state == 100) { game_state = 1; } break; }
|
||||
|
||||
static uint8_t blink_count;
|
||||
const bool did_blink = (++blink_count > invader_count >> 1);
|
||||
if (did_blink) {
|
||||
game_blink = !game_blink;
|
||||
blink_count = 0;
|
||||
}
|
||||
|
||||
if (invader_count && did_blink) {
|
||||
const int8_t newx = invaders_x + invaders_dir;
|
||||
if (!WITHIN(newx, leftmost, rightmost)) { // Invaders reached the edge?
|
||||
invaders_dir *= -1; // Invaders change direction
|
||||
invaders_y += (ROW_H) / 2; // Invaders move down
|
||||
invaders_x -= invaders_dir; // ...and only move down this time.
|
||||
if (invaders_y + botmost * (ROW_H) - 2 >= CANNON_Y) // Invaders reached the bottom?
|
||||
kill_cannon(game_state, 20); // Kill the cannon. Reset invaders.
|
||||
}
|
||||
|
||||
invaders_x += invaders_dir; // Invaders take one step left/right
|
||||
|
||||
// Randomly shoot if invaders are listed
|
||||
if (invader_count && !random(0, 20)) {
|
||||
|
||||
// Find a free bullet
|
||||
laser_t *b = NULL;
|
||||
LOOP_L_N(i, COUNT(bullet)) if (!bullet[i].v) { b = &bullet[i]; break; }
|
||||
if (b) {
|
||||
// Pick a random shooter and update the bullet
|
||||
//SERIAL_ECHOLNPGM("free bullet found");
|
||||
const uint8_t inv = shooters[random(0, invader_count + 1)], col = inv & 0x0F, row = inv >> 4, type = inv_type[row];
|
||||
b->x = INV_X_CTR(col, type);
|
||||
b->y = INV_Y_BOT(row);
|
||||
b->v = 2 + random(0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the laser position
|
||||
if (laser.v) {
|
||||
laser.y += laser.v;
|
||||
if (laser.y < 0) laser.v = 0;
|
||||
}
|
||||
|
||||
// Did the laser collide with an invader?
|
||||
if (laser.v && WITHIN(laser.y, invaders_y, invaders_y + INVADERS_HIGH - 1)) {
|
||||
const int8_t col = INVADER_COL(laser.x);
|
||||
if (WITHIN(col, 0, INVADER_COLS - 1)) {
|
||||
const int8_t row = INVADER_ROW(laser.y);
|
||||
if (WITHIN(row, 0, INVADER_ROWS - 1)) {
|
||||
const uint8_t mask = _BV(col);
|
||||
if (bugs[row] & mask) {
|
||||
const uint8_t type = inv_type[row];
|
||||
const int8_t invx = INV_X_LEFT(col, type);
|
||||
if (WITHIN(laser.x, invx, invx + inv_wide[type] - 1)) {
|
||||
// Turn off laser
|
||||
laser.v = 0;
|
||||
// Remove the invader!
|
||||
bugs[row] &= ~mask;
|
||||
// Score!
|
||||
score += INVADER_ROWS - row;
|
||||
// Explode sound!
|
||||
_BUZZ(40, 10);
|
||||
// Explosion bitmap!
|
||||
explode(invx + inv_wide[type] / 2, invaders_y + row * (ROW_H));
|
||||
// If invaders are gone, go to reset invaders state
|
||||
if (--invader_count) update_invader_data(); else { game_state = 20; reset_bullets(); }
|
||||
} // laser x hit
|
||||
} // invader exists
|
||||
} // good row
|
||||
} // good col
|
||||
} // laser in invader zone
|
||||
|
||||
// Handle alien bullets
|
||||
LOOP_L_N(s, COUNT(bullet)) {
|
||||
laser_t *b = &bullet[s];
|
||||
if (b->v) {
|
||||
// Update alien bullet position
|
||||
b->y += b->v;
|
||||
if (b->y >= LCD_PIXEL_HEIGHT)
|
||||
b->v = 0; // Offscreen
|
||||
else if (b->y >= CANNON_Y && WITHIN(b->x, cannon_x, cannon_x + CANNON_W - 1))
|
||||
kill_cannon(game_state, 120); // Hit the cannon
|
||||
}
|
||||
}
|
||||
|
||||
// Randomly spawn a UFO
|
||||
if (!ufov && !random(0,500)) spawn_ufo();
|
||||
|
||||
// Did the laser hit a ufo?
|
||||
if (laser.v && ufov && laser.y < UFO_H + 2 && WITHIN(laser.x, ufox, ufox + UFO_W - 1)) {
|
||||
// Turn off laser and UFO
|
||||
laser.v = ufov = 0;
|
||||
// Score!
|
||||
score += 10;
|
||||
// Explode!
|
||||
_BUZZ(40, 10);
|
||||
// Explosion bitmap
|
||||
explode(ufox + (UFO_W) / 2, 1);
|
||||
}
|
||||
|
||||
} while (false);
|
||||
|
||||
}
|
||||
|
||||
// Click-and-hold to abort
|
||||
if (ui.button_pressed()) --quit_count; else quit_count = 10;
|
||||
|
||||
// Click to fire or exit
|
||||
if (ui.use_click()) {
|
||||
if (!game_state)
|
||||
quit_count = 0;
|
||||
else if (game_state == 1 && !laser.v)
|
||||
fire_cannon();
|
||||
}
|
||||
|
||||
if (!quit_count) exit_game();
|
||||
|
||||
u8g.setColorIndex(1);
|
||||
|
||||
// Draw invaders
|
||||
if (PAGE_CONTAINS(invaders_y, invaders_y + botmost * (ROW_H) - 2 - 1)) {
|
||||
int8_t yy = invaders_y;
|
||||
for (uint8_t y = 0; y < INVADER_ROWS; ++y) {
|
||||
const uint8_t type = inv_type[y];
|
||||
if (PAGE_CONTAINS(yy, yy + INVADER_H - 1)) {
|
||||
int8_t xx = invaders_x;
|
||||
for (uint8_t x = 0; x < INVADER_COLS; ++x) {
|
||||
if (TEST(bugs[y], x))
|
||||
u8g.drawBitmapP(xx, yy, 2, INVADER_H, invader[type][game_blink]);
|
||||
xx += COL_W;
|
||||
}
|
||||
}
|
||||
yy += ROW_H;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw UFO
|
||||
if (ufov && PAGE_UNDER(UFO_H + 2))
|
||||
u8g.drawBitmapP(ufox, 2, 2, UFO_H, ufo);
|
||||
|
||||
// Draw cannon
|
||||
if (game_state && PAGE_CONTAINS(CANNON_Y, CANNON_Y + CANNON_H - 1) && (game_state < 2 || (game_state & 0x02)))
|
||||
u8g.drawBitmapP(cannon_x, CANNON_Y, 2, CANNON_H, cannon);
|
||||
|
||||
// Draw laser
|
||||
if (laser.v && PAGE_CONTAINS(laser.y, laser.y + LASER_H - 1))
|
||||
u8g.drawVLine(laser.x, laser.y, LASER_H);
|
||||
|
||||
// Draw invader bullets
|
||||
LOOP_L_N (i, COUNT(bullet)) {
|
||||
if (bullet[i].v && PAGE_CONTAINS(bullet[i].y - (SHOT_H - 1), bullet[i].y))
|
||||
u8g.drawVLine(bullet[i].x, bullet[i].y - (SHOT_H - 1), SHOT_H);
|
||||
}
|
||||
|
||||
// Draw explosion
|
||||
if (explod.v && PAGE_CONTAINS(explod.y, explod.y + 7 - 1)) {
|
||||
u8g.drawBitmapP(explod.x, explod.y, 2, 7, explosion);
|
||||
--explod.v;
|
||||
}
|
||||
|
||||
// Blink GAME OVER when game is over
|
||||
if (!game_state) draw_game_over();
|
||||
|
||||
if (PAGE_UNDER(MENU_FONT_ASCENT - 1)) {
|
||||
// Draw Score
|
||||
//const uint8_t sx = (LCD_PIXEL_WIDTH - (score >= 10 ? score >= 100 ? score >= 1000 ? 4 : 3 : 2 : 1) * MENU_FONT_WIDTH) / 2;
|
||||
constexpr uint8_t sx = 0;
|
||||
lcd_moveto(sx, MENU_FONT_ASCENT - 1);
|
||||
lcd_put_int(score);
|
||||
|
||||
// Draw lives
|
||||
if (cannons_left)
|
||||
for (uint8_t i = 1; i <= cannons_left; ++i)
|
||||
u8g.drawBitmapP(LCD_PIXEL_WIDTH - i * (LIFE_W), 6 - (LIFE_H), 1, LIFE_H, life);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InvadersGame::enter_game() {
|
||||
init_game(20, game_screen); // countdown to reset invaders
|
||||
cannons_left = 3;
|
||||
quit_count = 10;
|
||||
laser.v = 0;
|
||||
reset_invaders();
|
||||
reset_player();
|
||||
}
|
||||
|
||||
#endif // MARLIN_INVADERS
|
137
Marlin/src/lcd/menu/game/maze.cpp
Normal file
137
Marlin/src/lcd/menu/game/maze.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(MARLIN_MAZE)
|
||||
|
||||
#include "game.h"
|
||||
|
||||
int8_t move_dir, last_move_dir, // NESW0
|
||||
prizex, prizey, prize_cnt, old_encoder;
|
||||
fixed_t playerx, playery;
|
||||
|
||||
// Up to 50 lines, then you win!
|
||||
typedef struct { int8_t x, y; } pos_t;
|
||||
uint8_t head_ind;
|
||||
pos_t maze_walls[50] = {
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
// Turn the player cw or ccw
|
||||
inline void turn_player(const bool cw) {
|
||||
if (move_dir == 4) move_dir = last_move_dir;
|
||||
move_dir += cw ? 1 : -1;
|
||||
move_dir &= 0x03;
|
||||
last_move_dir = move_dir;
|
||||
}
|
||||
|
||||
// Reset the player for a new game
|
||||
void player_reset() {
|
||||
// Init position
|
||||
playerx = BTOF(1);
|
||||
playery = BTOF(GAME_H / 2);
|
||||
|
||||
// Init motion with a ccw turn
|
||||
move_dir = 0;
|
||||
turn_player(false);
|
||||
|
||||
// Clear prize flag
|
||||
prize_cnt = 255;
|
||||
|
||||
// Clear the controls
|
||||
ui.encoderPosition = 0;
|
||||
old_encoder = 0;
|
||||
}
|
||||
|
||||
void MazeGame::game_screen() {
|
||||
// Run the sprite logic
|
||||
if (game_frame()) do { // Run logic twice for finer resolution
|
||||
|
||||
// Move the man one unit in the current direction
|
||||
// Direction index 4 is for the stopped man
|
||||
const int8_t oldx = FTOB(playerx), oldy = FTOB(playery);
|
||||
pos_t dir_add[] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, 0 } };
|
||||
playerx += dir_add[move_dir].x;
|
||||
playery += dir_add[move_dir].y;
|
||||
const int8_t x = FTOB(playerx), y = FTOB(playery);
|
||||
|
||||
} while(0);
|
||||
|
||||
u8g.setColorIndex(1);
|
||||
|
||||
// Draw Score
|
||||
if (PAGE_UNDER(HEADER_H)) {
|
||||
lcd_moveto(0, HEADER_H - 1);
|
||||
lcd_put_int(score);
|
||||
}
|
||||
|
||||
// Draw the maze
|
||||
// for (uint8_t n = 0; n < head_ind; ++n) {
|
||||
// const pos_t &p = maze_walls[n], &q = maze_walls[n + 1];
|
||||
// if (p.x == q.x) {
|
||||
// const int8_t y1 = GAMEY(MIN(p.y, q.y)), y2 = GAMEY(MAX(p.y, q.y));
|
||||
// if (PAGE_CONTAINS(y1, y2))
|
||||
// u8g.drawVLine(GAMEX(p.x), y1, y2 - y1 + 1);
|
||||
// }
|
||||
// else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) {
|
||||
// const int8_t x1 = GAMEX(MIN(p.x, q.x)), x2 = GAMEX(MAX(p.x, q.x));
|
||||
// u8g.drawHLine(x1, GAMEY(p.y), x2 - x1 + 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Draw Man
|
||||
// const int8_t fy = GAMEY(foody);
|
||||
// if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) {
|
||||
// const int8_t fx = GAMEX(foodx);
|
||||
// u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH);
|
||||
// if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2);
|
||||
// }
|
||||
|
||||
// Draw Ghosts
|
||||
// const int8_t fy = GAMEY(foody);
|
||||
// if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) {
|
||||
// const int8_t fx = GAMEX(foodx);
|
||||
// u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH);
|
||||
// if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2);
|
||||
// }
|
||||
|
||||
// Draw Prize
|
||||
// if (PAGE_CONTAINS(prizey, prizey + PRIZE_WH - 1)) {
|
||||
// u8g.drawFrame(prizex, prizey, PRIZE_WH, PRIZE_WH);
|
||||
// if (PRIZE_WH == 5) u8g.drawPixel(prizex + 2, prizey + 2);
|
||||
// }
|
||||
|
||||
// Draw GAME OVER
|
||||
if (!game_state) draw_game_over();
|
||||
|
||||
// A click always exits this game
|
||||
if (ui.use_click()) exit_game();
|
||||
}
|
||||
|
||||
void MazeGame::enter_game() {
|
||||
init_game(1, game_screen); // Game running
|
||||
reset_player();
|
||||
reset_enemies();
|
||||
}
|
||||
|
||||
#endif // MARLIN_MAZE
|
334
Marlin/src/lcd/menu/game/snake.cpp
Normal file
334
Marlin/src/lcd/menu/game/snake.cpp
Normal file
@ -0,0 +1,334 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(MARLIN_SNAKE)
|
||||
|
||||
#include "game.h"
|
||||
|
||||
#define SNAKE_BOX 4
|
||||
|
||||
#define HEADER_H (MENU_FONT_ASCENT - 2)
|
||||
#define SNAKE_WH (SNAKE_BOX + 1)
|
||||
|
||||
#define IDEAL_L 2
|
||||
#define IDEAL_R (LCD_PIXEL_WIDTH - 1 - 2)
|
||||
#define IDEAL_T (HEADER_H + 2)
|
||||
#define IDEAL_B (LCD_PIXEL_HEIGHT - 1 - 2)
|
||||
#define IDEAL_W (IDEAL_R - (IDEAL_L) + 1)
|
||||
#define IDEAL_H (IDEAL_B - (IDEAL_T) + 1)
|
||||
|
||||
#define GAME_W int((IDEAL_W) / (SNAKE_WH))
|
||||
#define GAME_H int((IDEAL_H) / (SNAKE_WH))
|
||||
|
||||
#define BOARD_W ((SNAKE_WH) * (GAME_W) + 1)
|
||||
#define BOARD_H ((SNAKE_WH) * (GAME_H) + 1)
|
||||
#define BOARD_L ((LCD_PIXEL_WIDTH - (BOARD_W) + 1) / 2)
|
||||
#define BOARD_R (BOARD_L + BOARD_W - 1)
|
||||
#define BOARD_T (((LCD_PIXEL_HEIGHT + IDEAL_T) - (BOARD_H)) / 2)
|
||||
#define BOARD_B (BOARD_T + BOARD_H - 1)
|
||||
|
||||
#define GAMEX(X) (BOARD_L + ((X) * (SNAKE_WH)))
|
||||
#define GAMEY(Y) (BOARD_T + ((Y) * (SNAKE_WH)))
|
||||
|
||||
#if SNAKE_BOX > 2
|
||||
#define FOOD_WH SNAKE_BOX
|
||||
#else
|
||||
#define FOOD_WH 2
|
||||
#endif
|
||||
|
||||
#if SNAKE_BOX < 1
|
||||
#define SNAKE_SIZ 1
|
||||
#else
|
||||
#define SNAKE_SIZ SNAKE_BOX
|
||||
#endif
|
||||
|
||||
constexpr fixed_t snakev = FTOP(0.20);
|
||||
|
||||
int8_t snake_dir, // NESW
|
||||
foodx, foody, food_cnt,
|
||||
old_encoder;
|
||||
fixed_t snakex, snakey;
|
||||
|
||||
// Up to 50 lines, then you win!
|
||||
typedef struct { int8_t x, y; } pos_t;
|
||||
uint8_t head_ind;
|
||||
pos_t snake_tail[50];
|
||||
|
||||
// Remove the first pixel from the tail.
|
||||
// If needed, shift out the first segment.
|
||||
void shorten_tail() {
|
||||
pos_t &p = snake_tail[0], &q = snake_tail[1];
|
||||
bool shift = false;
|
||||
if (p.x == q.x) {
|
||||
// Vertical line
|
||||
p.y += (q.y > p.y) ? 1 : -1;
|
||||
shift = p.y == q.y;
|
||||
}
|
||||
else {
|
||||
// Horizontal line
|
||||
p.x += (q.x > p.x) ? 1 : -1;
|
||||
shift = p.x == q.x;
|
||||
}
|
||||
if (shift) {
|
||||
head_ind--;
|
||||
for (uint8_t i = 0; i <= head_ind; ++i)
|
||||
snake_tail[i] = snake_tail[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
// The food is on a line
|
||||
inline bool food_on_line() {
|
||||
for (uint8_t n = 0; n < head_ind; ++n) {
|
||||
pos_t &p = snake_tail[n], &q = snake_tail[n + 1];
|
||||
if (p.x == q.x) {
|
||||
if ((foodx == p.x - 1 || foodx == p.x) && WITHIN(foody, MIN(p.y, q.y), MAX(p.y, q.y)))
|
||||
return true;
|
||||
}
|
||||
else if ((foody == p.y - 1 || foody == p.y) && WITHIN(foodx, MIN(p.x, q.x), MAX(p.x, q.x)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add a new food blob
|
||||
void food_reset() {
|
||||
do {
|
||||
foodx = random(0, GAME_W);
|
||||
foody = random(0, GAME_H);
|
||||
} while (food_on_line());
|
||||
}
|
||||
|
||||
// Turn the snake cw or ccw
|
||||
inline void turn_snake(const bool cw) {
|
||||
snake_dir += cw ? 1 : -1;
|
||||
snake_dir &= 0x03;
|
||||
head_ind++;
|
||||
snake_tail[head_ind].x = FTOB(snakex);
|
||||
snake_tail[head_ind].y = FTOB(snakey);
|
||||
}
|
||||
|
||||
// Reset the snake for a new game
|
||||
void snake_reset() {
|
||||
// Init the head and velocity
|
||||
snakex = BTOF(1);
|
||||
snakey = BTOF(GAME_H / 2);
|
||||
//snakev = FTOP(0.25);
|
||||
|
||||
// Init the tail with a cw turn
|
||||
snake_dir = 0;
|
||||
head_ind = 0;
|
||||
snake_tail[0].x = 0;
|
||||
snake_tail[0].y = GAME_H / 2;
|
||||
turn_snake(true);
|
||||
|
||||
// Clear food flag
|
||||
food_cnt = 5;
|
||||
|
||||
// Clear the controls
|
||||
ui.encoderPosition = 0;
|
||||
old_encoder = 0;
|
||||
}
|
||||
|
||||
// Check if head segment overlaps another
|
||||
bool snake_overlap() {
|
||||
// 4 lines must exist before a collision is possible
|
||||
if (head_ind < 4) return false;
|
||||
// Is the last segment crossing any others?
|
||||
const pos_t &h1 = snake_tail[head_ind - 1], &h2 = snake_tail[head_ind];
|
||||
// VERTICAL head segment?
|
||||
if (h1.x == h2.x) {
|
||||
// Loop from oldest to segment two away from head
|
||||
for (uint8_t n = 0; n < head_ind - 2; ++n) {
|
||||
// Segment p to q
|
||||
const pos_t &p = snake_tail[n], &q = snake_tail[n + 1];
|
||||
if (p.x != q.x) {
|
||||
// Crossing horizontal segment
|
||||
if (WITHIN(h1.x, MIN(p.x, q.x), MAX(p.x, q.x)) && (h1.y <= p.y) == (h2.y >= p.y)) return true;
|
||||
} // Overlapping vertical segment
|
||||
else if (h1.x == p.x && MIN(h1.y, h2.y) <= MAX(p.y, q.y) && MAX(h1.y, h2.y) >= MIN(p.y, q.y)) return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Loop from oldest to segment two away from head
|
||||
for (uint8_t n = 0; n < head_ind - 2; ++n) {
|
||||
// Segment p to q
|
||||
const pos_t &p = snake_tail[n], &q = snake_tail[n + 1];
|
||||
if (p.y != q.y) {
|
||||
// Crossing vertical segment
|
||||
if (WITHIN(h1.y, MIN(p.y, q.y), MAX(p.y, q.y)) && (h1.x <= p.x) == (h2.x >= p.x)) return true;
|
||||
} // Overlapping horizontal segment
|
||||
else if (h1.y == p.y && MIN(h1.x, h2.x) <= MAX(p.x, q.x) && MAX(h1.x, h2.x) >= MIN(p.x, q.x)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SnakeGame::game_screen() {
|
||||
// Run the snake logic
|
||||
if (game_frame()) do { // Run logic twice for finer resolution
|
||||
|
||||
// Move the snake's head one unit in the current direction
|
||||
const int8_t oldx = FTOB(snakex), oldy = FTOB(snakey);
|
||||
switch (snake_dir) {
|
||||
case 0: snakey -= snakev; break;
|
||||
case 1: snakex += snakev; break;
|
||||
case 2: snakey += snakev; break;
|
||||
case 3: snakex -= snakev; break;
|
||||
}
|
||||
const int8_t x = FTOB(snakex), y = FTOB(snakey);
|
||||
|
||||
// If movement took place...
|
||||
if (oldx != x || oldy != y) {
|
||||
|
||||
if (!WITHIN(x, 0, GAME_W - 1) || !WITHIN(y, 0, GAME_H - 1)) {
|
||||
game_state = 0; // Game Over
|
||||
_BUZZ(400, 40); // Bzzzt!
|
||||
break; // ...out of do-while
|
||||
}
|
||||
|
||||
snake_tail[head_ind].x = x;
|
||||
snake_tail[head_ind].y = y;
|
||||
|
||||
// Change snake direction if set
|
||||
const int8_t enc = int8_t(ui.encoderPosition), diff = enc - old_encoder;
|
||||
if (diff) {
|
||||
old_encoder = enc;
|
||||
turn_snake(diff > 0);
|
||||
}
|
||||
|
||||
if (food_cnt) --food_cnt; else shorten_tail();
|
||||
|
||||
// Did the snake collide with itself or go out of bounds?
|
||||
if (snake_overlap()) {
|
||||
game_state = 0; // Game Over
|
||||
_BUZZ(400, 40); // Bzzzt!
|
||||
}
|
||||
// Is the snake at the food?
|
||||
else if (x == foodx && y == foody) {
|
||||
_BUZZ(5, 220);
|
||||
_BUZZ(5, 280);
|
||||
score++;
|
||||
food_cnt = 2;
|
||||
food_reset();
|
||||
}
|
||||
}
|
||||
|
||||
} while(0);
|
||||
|
||||
u8g.setColorIndex(1);
|
||||
|
||||
// Draw Score
|
||||
if (PAGE_UNDER(HEADER_H)) {
|
||||
lcd_moveto(0, HEADER_H - 1);
|
||||
lcd_put_int(score);
|
||||
}
|
||||
|
||||
// DRAW THE PLAYFIELD BORDER
|
||||
u8g.drawFrame(BOARD_L - 2, BOARD_T - 2, BOARD_R - BOARD_L + 4, BOARD_B - BOARD_T + 4);
|
||||
|
||||
// Draw the snake (tail)
|
||||
#if SNAKE_WH < 2
|
||||
|
||||
// At this scale just draw a line
|
||||
for (uint8_t n = 0; n < head_ind; ++n) {
|
||||
const pos_t &p = snake_tail[n], &q = snake_tail[n + 1];
|
||||
if (p.x == q.x) {
|
||||
const int8_t y1 = GAMEY(MIN(p.y, q.y)), y2 = GAMEY(MAX(p.y, q.y));
|
||||
if (PAGE_CONTAINS(y1, y2))
|
||||
u8g.drawVLine(GAMEX(p.x), y1, y2 - y1 + 1);
|
||||
}
|
||||
else if (PAGE_CONTAINS(GAMEY(p.y), GAMEY(p.y))) {
|
||||
const int8_t x1 = GAMEX(MIN(p.x, q.x)), x2 = GAMEX(MAX(p.x, q.x));
|
||||
u8g.drawHLine(x1, GAMEY(p.y), x2 - x1 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
#elif SNAKE_WH == 2
|
||||
|
||||
// At this scale draw two lines
|
||||
for (uint8_t n = 0; n < head_ind; ++n) {
|
||||
const pos_t &p = snake_tail[n], &q = snake_tail[n + 1];
|
||||
if (p.x == q.x) {
|
||||
const int8_t y1 = GAMEY(MIN(p.y, q.y)), y2 = GAMEY(MAX(p.y, q.y));
|
||||
if (PAGE_CONTAINS(y1, y2 + 1))
|
||||
u8g.drawFrame(GAMEX(p.x), y1, 2, y2 - y1 + 1 + 1);
|
||||
}
|
||||
else {
|
||||
const int8_t py = GAMEY(p.y);
|
||||
if (PAGE_CONTAINS(py, py + 1)) {
|
||||
const int8_t x1 = GAMEX(MIN(p.x, q.x)), x2 = GAMEX(MAX(p.x, q.x));
|
||||
u8g.drawFrame(x1, py, x2 - x1 + 1 + 1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Draw a series of boxes
|
||||
for (uint8_t n = 0; n < head_ind; ++n) {
|
||||
const pos_t &p = snake_tail[n], &q = snake_tail[n + 1];
|
||||
if (p.x == q.x) {
|
||||
const int8_t y1 = MIN(p.y, q.y), y2 = MAX(p.y, q.y);
|
||||
if (PAGE_CONTAINS(GAMEY(y1), GAMEY(y2) + SNAKE_SIZ - 1)) {
|
||||
for (int8_t i = y1; i <= y2; ++i) {
|
||||
const int8_t y = GAMEY(i);
|
||||
if (PAGE_CONTAINS(y, y + SNAKE_SIZ - 1))
|
||||
u8g.drawBox(GAMEX(p.x), y, SNAKE_SIZ, SNAKE_SIZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const int8_t py = GAMEY(p.y);
|
||||
if (PAGE_CONTAINS(py, py + SNAKE_SIZ - 1)) {
|
||||
const int8_t x1 = MIN(p.x, q.x), x2 = MAX(p.x, q.x);
|
||||
for (int8_t i = x1; i <= x2; ++i)
|
||||
u8g.drawBox(GAMEX(i), py, SNAKE_SIZ, SNAKE_SIZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Draw food
|
||||
const int8_t fy = GAMEY(foody);
|
||||
if (PAGE_CONTAINS(fy, fy + FOOD_WH - 1)) {
|
||||
const int8_t fx = GAMEX(foodx);
|
||||
u8g.drawFrame(fx, fy, FOOD_WH, FOOD_WH);
|
||||
if (FOOD_WH == 5) u8g.drawPixel(fx + 2, fy + 2);
|
||||
}
|
||||
|
||||
// Draw GAME OVER
|
||||
if (!game_state) draw_game_over();
|
||||
|
||||
// A click always exits this game
|
||||
if (ui.use_click()) exit_game();
|
||||
}
|
||||
|
||||
void SnakeGame::enter_game() {
|
||||
init_game(1, game_screen); // 1 = Game running
|
||||
snake_reset();
|
||||
food_reset();
|
||||
}
|
||||
|
||||
#endif // MARLIN_SNAKE
|
@ -37,7 +37,7 @@
|
||||
#include "../../module/configuration_store.h"
|
||||
#endif
|
||||
|
||||
#if WATCH_HOTENDS || WATCH_BED || ENABLED(BABYSTEP_ZPROBE_OFFSET)
|
||||
#if WATCH_HOTENDS || WATCH_BED
|
||||
#include "../../module/temperature.h"
|
||||
#endif
|
||||
|
||||
@ -54,21 +54,23 @@
|
||||
////////////////////////////////////////////
|
||||
|
||||
// Menu Navigation
|
||||
int8_t encoderTopLine;
|
||||
int8_t encoderTopLine, encoderLine, screen_items;
|
||||
|
||||
typedef struct {
|
||||
screenFunc_t menu_function;
|
||||
uint32_t encoder_position;
|
||||
int8_t top_line, items;
|
||||
} menuPosition;
|
||||
menuPosition screen_history[6];
|
||||
uint8_t screen_history_depth = 0;
|
||||
bool screen_changed;
|
||||
|
||||
// Value Editing
|
||||
PGM_P editLabel;
|
||||
void *editValue;
|
||||
int32_t minEditValue, maxEditValue;
|
||||
screenFunc_t callbackFunc;
|
||||
bool liveEdit;
|
||||
PGM_P MenuItemBase::editLabel;
|
||||
void* MenuItemBase::editValue;
|
||||
int16_t MenuItemBase::minEditValue, MenuItemBase::maxEditValue;
|
||||
screenFunc_t MenuItemBase::callbackFunc;
|
||||
bool MenuItemBase::liveEdit;
|
||||
|
||||
// Prevent recursion into screen handlers
|
||||
bool no_reentry = false;
|
||||
@ -80,20 +82,14 @@ bool no_reentry = false;
|
||||
void MarlinUI::return_to_status() { goto_screen(status_screen); }
|
||||
|
||||
void MarlinUI::save_previous_screen() {
|
||||
if (screen_history_depth < COUNT(screen_history)) {
|
||||
screen_history[screen_history_depth].menu_function = currentScreen;
|
||||
screen_history[screen_history_depth].encoder_position = encoderPosition;
|
||||
++screen_history_depth;
|
||||
}
|
||||
if (screen_history_depth < COUNT(screen_history))
|
||||
screen_history[screen_history_depth++] = { currentScreen, encoderPosition, encoderTopLine, screen_items };
|
||||
}
|
||||
|
||||
void MarlinUI::goto_previous_screen() {
|
||||
if (screen_history_depth > 0) {
|
||||
--screen_history_depth;
|
||||
goto_screen(
|
||||
screen_history[screen_history_depth].menu_function,
|
||||
screen_history[screen_history_depth].encoder_position
|
||||
);
|
||||
menuPosition &sh = screen_history[--screen_history_depth];
|
||||
goto_screen(sh.menu_function, sh.encoder_position, sh.top_line, sh.items);
|
||||
}
|
||||
else
|
||||
return_to_status();
|
||||
@ -135,8 +131,8 @@ void MenuItem_gcode::action(PGM_P pgcode) { enqueue_and_echo_commands_P(pgcode);
|
||||
*/
|
||||
void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
|
||||
ui.encoder_direction_normal();
|
||||
if ((int32_t)ui.encoderPosition < 0) ui.encoderPosition = 0;
|
||||
if ((int32_t)ui.encoderPosition > maxEditValue) ui.encoderPosition = maxEditValue;
|
||||
if (int16_t(ui.encoderPosition) < 0) ui.encoderPosition = 0;
|
||||
if (int16_t(ui.encoderPosition) > maxEditValue) ui.encoderPosition = maxEditValue;
|
||||
if (ui.should_draw())
|
||||
draw_edit_screen(editLabel, strfunc(ui.encoderPosition + minEditValue));
|
||||
if (ui.lcd_clicked || (liveEdit && ui.should_draw())) {
|
||||
@ -146,7 +142,7 @@ void MenuItemBase::edit(strfunc_t strfunc, loadfunc_t loadfunc) {
|
||||
}
|
||||
}
|
||||
|
||||
void MenuItemBase::init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint32_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le) {
|
||||
void MenuItemBase::init(PGM_P const el, void * const ev, const int16_t minv, const int16_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le) {
|
||||
ui.save_previous_screen();
|
||||
ui.refresh();
|
||||
editLabel = el;
|
||||
@ -197,7 +193,7 @@ bool printer_busy() {
|
||||
/**
|
||||
* General function to go directly to a screen
|
||||
*/
|
||||
void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
|
||||
void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, const uint8_t top/*=0*/, const uint8_t items/*=0*/) {
|
||||
if (currentScreen != screen) {
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
@ -246,6 +242,8 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
|
||||
|
||||
currentScreen = screen;
|
||||
encoderPosition = encoder;
|
||||
encoderTopLine = top;
|
||||
screen_items = items;
|
||||
if (screen == status_screen) {
|
||||
defer_status_screen(false);
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
@ -314,7 +312,6 @@ void MarlinUI::synchronize(PGM_P const msg/*=NULL*/) {
|
||||
* _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
|
||||
* screen_items is the total number of items in the menu (after one call)
|
||||
*/
|
||||
int8_t encoderLine, screen_items;
|
||||
void scroll_screen(const uint8_t limit, const bool is_menu) {
|
||||
ui.encoder_direction_menus();
|
||||
ENCODER_RATE_MULTIPLY(false);
|
||||
@ -355,6 +352,8 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) {
|
||||
|
||||
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
|
||||
|
||||
#include "../../feature/babystep.h"
|
||||
|
||||
void lcd_babystep_zoffset() {
|
||||
if (ui.use_click()) return ui.goto_previous_screen_no_defer();
|
||||
ui.defer_status_screen();
|
||||
@ -365,7 +364,7 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) {
|
||||
#endif
|
||||
ui.encoder_direction_normal();
|
||||
if (ui.encoderPosition) {
|
||||
const int16_t babystep_increment = (int32_t)ui.encoderPosition * (BABYSTEP_MULTIPLICATOR);
|
||||
const int16_t babystep_increment = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR);
|
||||
ui.encoderPosition = 0;
|
||||
|
||||
const float diff = planner.steps_to_mm[Z_AXIS] * babystep_increment,
|
||||
@ -379,7 +378,7 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) {
|
||||
;
|
||||
if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
|
||||
|
||||
thermalManager.babystep_axis(Z_AXIS, babystep_increment);
|
||||
babystep.add_steps(Z_AXIS, babystep_increment);
|
||||
|
||||
if (do_probe) zprobe_zoffset = new_offs;
|
||||
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
|
||||
@ -392,7 +391,7 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) {
|
||||
if (ui.should_draw()) {
|
||||
#if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
|
||||
if (!do_probe)
|
||||
draw_edit_screen(PSTR(MSG_IDEX_Z_OFFSET), ftostr43sign(hotend_offset[Z_AXIS][active_extruder]));
|
||||
draw_edit_screen(PSTR(MSG_Z_OFFSET), ftostr43sign(hotend_offset[Z_AXIS][active_extruder]));
|
||||
else
|
||||
#endif
|
||||
draw_edit_screen(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
|
||||
@ -437,4 +436,12 @@ void _lcd_draw_homing() {
|
||||
void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }
|
||||
#endif
|
||||
|
||||
void do_select_screen(PGM_P const yes, PGM_P const no, bool &yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
|
||||
if (ui.encoderPosition) {
|
||||
yesno = int16_t(ui.encoderPosition) > 0;
|
||||
ui.encoderPosition = 0;
|
||||
}
|
||||
draw_select_screen(yes, no, yesno, pref, string, suff);
|
||||
}
|
||||
|
||||
#endif // HAS_LCD_MENU
|
||||
|
@ -43,7 +43,7 @@ bool printer_busy();
|
||||
static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
|
||||
};
|
||||
|
||||
DECLARE_MENU_EDIT_TYPE(uint8_t, percent, ui8tostr_percent,1 ); // 100% right-justified
|
||||
DECLARE_MENU_EDIT_TYPE(uint8_t, percent, ui8tostr4pct, 1 ); // 100% right-justified
|
||||
DECLARE_MENU_EDIT_TYPE(int16_t, int3, i16tostr3, 1 ); // 123, -12 right-justified
|
||||
DECLARE_MENU_EDIT_TYPE(int16_t, int4, i16tostr4sign, 1 ); // 1234, -123 right-justified
|
||||
DECLARE_MENU_EDIT_TYPE(int8_t, int8, i8tostr3, 1 ); // 123, -12 right-justified
|
||||
@ -64,6 +64,11 @@ DECLARE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f ); // 123
|
||||
////////////////////////////////////////////
|
||||
|
||||
void draw_edit_screen(PGM_P const pstr, const char* const value=NULL);
|
||||
void draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff);
|
||||
void do_select_screen(PGM_P const yes, PGM_P const no, bool &yesno, PGM_P const pref, const char * const string=NULL, PGM_P const suff=NULL);
|
||||
inline void do_select_screen_yn(bool &yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
|
||||
do_select_screen(PSTR(MSG_YES), PSTR(MSG_NO), yesno, pref, string, suff);
|
||||
}
|
||||
void draw_menu_item(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char);
|
||||
void draw_menu_item_static(const uint8_t row, PGM_P const pstr, const bool center=true, const bool invert=false, const char *valstr=NULL);
|
||||
void _draw_menu_item_edit(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm);
|
||||
@ -151,10 +156,16 @@ class MenuItem_function {
|
||||
////////////////////////////////////////////
|
||||
|
||||
class MenuItemBase {
|
||||
private:
|
||||
static PGM_P editLabel;
|
||||
static void *editValue;
|
||||
static int16_t minEditValue, maxEditValue;
|
||||
static screenFunc_t callbackFunc;
|
||||
static bool liveEdit;
|
||||
protected:
|
||||
typedef char* (*strfunc_t)(const int32_t);
|
||||
typedef void (*loadfunc_t)(void *, const int32_t);
|
||||
static void init(PGM_P const el, void * const ev, const int32_t minv, const int32_t maxv, const uint32_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
|
||||
typedef char* (*strfunc_t)(const int16_t);
|
||||
typedef void (*loadfunc_t)(void *, const int16_t);
|
||||
static void init(PGM_P const el, void * const ev, const int16_t minv, const int16_t maxv, const uint16_t ep, const screenFunc_t cs, const screenFunc_t cb, const bool le);
|
||||
static void edit(strfunc_t, loadfunc_t);
|
||||
};
|
||||
|
||||
@ -164,12 +175,12 @@ class TMenuItem : MenuItemBase {
|
||||
typedef typename NAME::type_t type_t;
|
||||
static inline float unscale(const float value) { return value * (1.0f / NAME::scale); }
|
||||
static inline float scale(const float value) { return value * NAME::scale; }
|
||||
static void load(void *ptr, const int32_t value) { *((type_t*)ptr) = unscale(value); }
|
||||
static char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }
|
||||
static void load(void *ptr, const int16_t value) { *((type_t*)ptr) = unscale(value); }
|
||||
static char* to_string(const int16_t value) { return NAME::strfunc(unscale(value)); }
|
||||
public:
|
||||
static void action_edit(PGM_P const pstr, type_t * const ptr, const type_t minValue, const type_t maxValue, const screenFunc_t callback=NULL, const bool live=false) {
|
||||
const int32_t minv = scale(minValue);
|
||||
init(pstr, ptr, minv, int32_t(scale(maxValue)) - minv, int32_t(scale(*ptr)) - minv, edit, callback, live);
|
||||
const int16_t minv = scale(minValue);
|
||||
init(pstr, ptr, minv, int16_t(scale(maxValue)) - minv, int16_t(scale(*ptr)) - minv, edit, callback, live);
|
||||
}
|
||||
static void edit() { MenuItemBase::edit(to_string, load); }
|
||||
};
|
||||
@ -309,8 +320,8 @@ class MenuItem_bool {
|
||||
|
||||
#define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
|
||||
#define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
|
||||
#define MENU_ITEM_P(TYPE, PLABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ## __VA_ARGS__)
|
||||
#define MENU_ITEM(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ## __VA_ARGS__)
|
||||
#define MENU_ITEM_P(TYPE, PLABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ## __VA_ARGS__)
|
||||
#define MENU_ITEM(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ## __VA_ARGS__)
|
||||
#define MENU_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
|
||||
#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
|
||||
#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
|
||||
|
@ -120,7 +120,7 @@
|
||||
// Encoder knob or keypad buttons adjust the Z position
|
||||
//
|
||||
if (ui.encoderPosition) {
|
||||
const float z = current_position[Z_AXIS] + float((int32_t)ui.encoderPosition) * (MESH_EDIT_Z_STEP);
|
||||
const float z = current_position[Z_AXIS] + float(int16_t(ui.encoderPosition)) * (MESH_EDIT_Z_STEP);
|
||||
line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f));
|
||||
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
|
||||
ui.encoderPosition = 0;
|
||||
|
@ -119,19 +119,37 @@ static void lcd_factory_settings() {
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
|
||||
#if HAS_HOTEND_OFFSET
|
||||
#include "../../module/motion.h"
|
||||
#include "../../gcode/queue.h"
|
||||
|
||||
void _recalc_IDEX_settings() {
|
||||
if (active_extruder) { // For the 2nd extruder re-home so the next tool-change gets the new offsets.
|
||||
void _recalc_offsets() {
|
||||
if (active_extruder && all_axes_known()) { // For the 2nd extruder re-home so the next tool-change gets the new offsets.
|
||||
enqueue_and_echo_commands_P(PSTR("G28")); // In future, we can babystep the 2nd extruder (if active), making homing unnecessary.
|
||||
active_extruder = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void menu_IDEX() {
|
||||
void menu_tool_offsets() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_MAIN);
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_X_OFFSET, &hotend_offset[X_AXIS][1], MIN(X2_HOME_POS, X2_MAX_POS) - 25.0, MAX(X2_HOME_POS, X2_MAX_POS) + 25.0, _recalc_offsets);
|
||||
#else
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_X_OFFSET, &hotend_offset[X_AXIS][1], -10.0, 10.0, _recalc_offsets);
|
||||
#endif
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_Y_OFFSET, &hotend_offset[Y_AXIS][1], -10.0, 10.0, _recalc_offsets);
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_Z_OFFSET, &hotend_offset[Z_AXIS][1], Z_PROBE_LOW_POINT, 10.0, _recalc_offsets);
|
||||
#if ENABLED(EEPROM_SETTINGS)
|
||||
MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
|
||||
#endif
|
||||
END_MENU();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
|
||||
void menu_idex() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_MAIN);
|
||||
|
||||
@ -146,10 +164,6 @@ static void lcd_factory_settings() {
|
||||
: PSTR("M605 S1\nT0\nM605 S2 X200\nG28 X\nG1 X100\nM605 S3 X200")
|
||||
);
|
||||
MENU_ITEM(gcode, MSG_IDEX_MODE_FULL_CTRL, PSTR("M605 S0\nG28 X"));
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_IDEX_X_OFFSET , &hotend_offset[X_AXIS][1], MIN(X2_HOME_POS, X2_MAX_POS) - 25.0, MAX(X2_HOME_POS, X2_MAX_POS) + 25.0, _recalc_IDEX_settings);
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_IDEX_Y_OFFSET , &hotend_offset[Y_AXIS][1], -10.0, 10.0, _recalc_IDEX_settings);
|
||||
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float52, MSG_IDEX_Z_OFFSET , &hotend_offset[Z_AXIS][1], -10.0, 10.0, _recalc_IDEX_settings);
|
||||
MENU_ITEM(gcode, MSG_IDEX_SAVE_OFFSETS, PSTR("M500"));
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
@ -287,8 +301,12 @@ void menu_configuration() {
|
||||
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE, menu_delta_calibrate);
|
||||
#endif
|
||||
|
||||
#if HAS_HOTEND_OFFSET
|
||||
MENU_ITEM(submenu, MSG_OFFSETS_MENU, menu_tool_offsets);
|
||||
#endif
|
||||
|
||||
#if ENABLED(DUAL_X_CARRIAGE)
|
||||
MENU_ITEM(submenu, MSG_IDEX_MENU, menu_IDEX);
|
||||
MENU_ITEM(submenu, MSG_IDEX_MENU, menu_idex);
|
||||
#endif
|
||||
|
||||
#if ENABLED(BLTOUCH)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -33,19 +33,20 @@
|
||||
#include "../../gcode/queue.h"
|
||||
#include "../../module/printcounter.h"
|
||||
#include "../../module/stepper.h"
|
||||
#include "../../sd/cardreader.h"
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
#include "../../feature/power_loss_recovery.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
#include "../../sd/cardreader.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(HOST_ACTION_COMMANDS)
|
||||
#include "../../feature/host_actions.h"
|
||||
#endif
|
||||
|
||||
#if HAS_GAMES
|
||||
#include "game/game.h"
|
||||
#endif
|
||||
|
||||
#define MACHINE_CAN_STOP (EITHER(SDSUPPORT, HOST_PROMPT_SUPPORT) || defined(ACTION_ON_CANCEL))
|
||||
#define MACHINE_CAN_PAUSE (ANY(SDSUPPORT, HOST_PROMPT_SUPPORT, PARK_HEAD_ON_PAUSE) || defined(ACTION_ON_PAUSE))
|
||||
|
||||
@ -152,7 +153,7 @@ void menu_main() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_WATCH);
|
||||
|
||||
const bool busy = printer_busy()
|
||||
const bool busy = IS_SD_PRINTING() || print_job_timer.isRunning()
|
||||
#if ENABLED(SDSUPPORT)
|
||||
, card_detected = card.isDetected()
|
||||
, card_open = card_detected && card.isFileOpen()
|
||||
@ -286,16 +287,19 @@ void menu_main() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ANY(MARLIN_BRICKOUT, MARLIN_INVADERS, MARLIN_SNAKE)
|
||||
#if ANY(MARLIN_BRICKOUT, MARLIN_INVADERS, MARLIN_SNAKE, MARLIN_MAZE)
|
||||
MENU_ITEM(submenu, "Game", (
|
||||
#if HAS_GAME_MENU
|
||||
menu_game
|
||||
#elif ENABLED(MARLIN_BRICKOUT)
|
||||
lcd_goto_brickout
|
||||
brickout.enter_game
|
||||
#elif ENABLED(MARLIN_INVADERS)
|
||||
lcd_goto_invaders
|
||||
invaders.enter_game
|
||||
#elif ENABLED(MARLIN_SNAKE)
|
||||
lcd_goto_snake
|
||||
snake.enter_game
|
||||
#elif ENABLED(MARLIN_MAZE)
|
||||
maze.enter_game
|
||||
#endif
|
||||
));
|
||||
#endif
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
ui.encoder_direction_normal();
|
||||
ENCODER_RATE_MULTIPLY(true);
|
||||
if (ui.encoderPosition != 0) {
|
||||
mixer.gradient.start_z += float((int)ui.encoderPosition) * 0.1;
|
||||
mixer.gradient.start_z += float(int16_t(ui.encoderPosition)) * 0.1;
|
||||
ui.encoderPosition = 0;
|
||||
NOLESS(mixer.gradient.start_z, 0);
|
||||
NOMORE(mixer.gradient.start_z, Z_MAX_POS);
|
||||
@ -69,7 +69,7 @@
|
||||
ui.encoder_direction_normal();
|
||||
ENCODER_RATE_MULTIPLY(true);
|
||||
if (ui.encoderPosition != 0) {
|
||||
mixer.gradient.end_z += float((int)ui.encoderPosition) * 0.1;
|
||||
mixer.gradient.end_z += float(int16_t(ui.encoderPosition)) * 0.1;
|
||||
ui.encoderPosition = 0;
|
||||
NOLESS(mixer.gradient.end_z, 0);
|
||||
NOMORE(mixer.gradient.end_z, Z_MAX_POS);
|
||||
@ -185,7 +185,7 @@ void lcd_mixer_mix_edit() {
|
||||
#elif DUAL_MIXING_EXTRUDER
|
||||
|
||||
if (ui.encoderPosition != 0) {
|
||||
mixer.mix[0] += (int)ui.encoderPosition;
|
||||
mixer.mix[0] += int16_t(ui.encoderPosition);
|
||||
ui.encoderPosition = 0;
|
||||
if (mixer.mix[0] < 0) mixer.mix[0] += 101;
|
||||
if (mixer.mix[0] > 100) mixer.mix[0] -= 101;
|
||||
|
@ -35,60 +35,60 @@ bool mmuMenuWait;
|
||||
// Load Filament
|
||||
//
|
||||
|
||||
void _mmu2_loadFilamentToNozzle(uint8_t index) {
|
||||
void _mmu2_load_filamentToNozzle(uint8_t index) {
|
||||
ui.reset_status();
|
||||
ui.return_to_status();
|
||||
ui.status_printf_P(0, PSTR(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
|
||||
if (mmu2.loadFilamentToNozzle(index)) ui.reset_status();
|
||||
if (mmu2.load_filament_to_nozzle(index)) ui.reset_status();
|
||||
}
|
||||
|
||||
inline void action_mmu2_loadFilamentToNozzle(const uint8_t tool) {
|
||||
_mmu2_loadFilamentToNozzle(tool);
|
||||
inline void action_mmu2_load_filament_to_nozzl_e(const uint8_t tool) {
|
||||
_mmu2_load_filamentToNozzle(tool);
|
||||
ui.return_to_status();
|
||||
}
|
||||
inline void action_mmu2_loadFilamentToNozzle0() { action_mmu2_loadFilamentToNozzle(0); }
|
||||
inline void action_mmu2_loadFilamentToNozzle1() { action_mmu2_loadFilamentToNozzle(1); }
|
||||
inline void action_mmu2_loadFilamentToNozzle2() { action_mmu2_loadFilamentToNozzle(2); }
|
||||
inline void action_mmu2_loadFilamentToNozzle3() { action_mmu2_loadFilamentToNozzle(3); }
|
||||
inline void action_mmu2_loadFilamentToNozzle4() { action_mmu2_loadFilamentToNozzle(4); }
|
||||
inline void action_mmu2_load_filament_to_nozzle_0() { action_mmu2_load_filament_to_nozzl_e(0); }
|
||||
inline void action_mmu2_load_filament_to_nozzle_1() { action_mmu2_load_filament_to_nozzl_e(1); }
|
||||
inline void action_mmu2_load_filament_to_nozzle_2() { action_mmu2_load_filament_to_nozzl_e(2); }
|
||||
inline void action_mmu2_load_filament_to_nozzle_3() { action_mmu2_load_filament_to_nozzl_e(3); }
|
||||
inline void action_mmu2_load_filament_to_nozzle_4() { action_mmu2_load_filament_to_nozzl_e(4); }
|
||||
|
||||
void _mmu2_loadFilament(uint8_t index) {
|
||||
void _mmu2_load_filament(uint8_t index) {
|
||||
ui.return_to_status();
|
||||
ui.status_printf_P(0, PSTR(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
|
||||
mmu2.loadFilament(index);
|
||||
mmu2.load_filament(index);
|
||||
ui.reset_status();
|
||||
}
|
||||
void action_mmu2_loadAll() {
|
||||
void action_mmu2_load_all() {
|
||||
for (uint8_t i = 0; i < EXTRUDERS; i++)
|
||||
_mmu2_loadFilament(i);
|
||||
_mmu2_load_filament(i);
|
||||
ui.return_to_status();
|
||||
}
|
||||
inline void action_mmu2_loadFilament0() { _mmu2_loadFilament(0); }
|
||||
inline void action_mmu2_loadFilament1() { _mmu2_loadFilament(1); }
|
||||
inline void action_mmu2_loadFilament2() { _mmu2_loadFilament(2); }
|
||||
inline void action_mmu2_loadFilament3() { _mmu2_loadFilament(3); }
|
||||
inline void action_mmu2_loadFilament4() { _mmu2_loadFilament(4); }
|
||||
inline void action_mmu2_load_filament_0() { _mmu2_load_filament(0); }
|
||||
inline void action_mmu2_load_filament_1() { _mmu2_load_filament(1); }
|
||||
inline void action_mmu2_load_filament_2() { _mmu2_load_filament(2); }
|
||||
inline void action_mmu2_load_filament_3() { _mmu2_load_filament(3); }
|
||||
inline void action_mmu2_load_filament_4() { _mmu2_load_filament(4); }
|
||||
|
||||
void menu_mmu2_loadFilament() {
|
||||
void menu_mmu2_load_filament() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_MMU2_MENU);
|
||||
MENU_ITEM(function, MSG_MMU2_ALL, action_mmu2_loadAll);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT0, action_mmu2_loadFilament0);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT1, action_mmu2_loadFilament1);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT2, action_mmu2_loadFilament2);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT3, action_mmu2_loadFilament3);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT4, action_mmu2_loadFilament4);
|
||||
MENU_ITEM(function, MSG_MMU2_ALL, action_mmu2_load_all);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT0, action_mmu2_load_filament_0);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT1, action_mmu2_load_filament_1);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT2, action_mmu2_load_filament_2);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT3, action_mmu2_load_filament_3);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT4, action_mmu2_load_filament_4);
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
void menu_mmu2_loadToNozzle() {
|
||||
void menu_mmu2_load_to_nozzle() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_MMU2_MENU);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT0, action_mmu2_loadFilamentToNozzle0);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT1, action_mmu2_loadFilamentToNozzle1);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT2, action_mmu2_loadFilamentToNozzle2);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT3, action_mmu2_loadFilamentToNozzle3);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT4, action_mmu2_loadFilamentToNozzle4);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT0, action_mmu2_load_filament_to_nozzle_0);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT1, action_mmu2_load_filament_to_nozzle_1);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT2, action_mmu2_load_filament_to_nozzle_2);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT3, action_mmu2_load_filament_to_nozzle_3);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT4, action_mmu2_load_filament_to_nozzle_4);
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
@ -96,19 +96,19 @@ void menu_mmu2_loadToNozzle() {
|
||||
// Eject Filament
|
||||
//
|
||||
|
||||
void _mmu2_ejectFilament(uint8_t index) {
|
||||
void _mmu2_eject_filament(uint8_t index) {
|
||||
ui.reset_status();
|
||||
ui.return_to_status();
|
||||
ui.status_printf_P(0, PSTR(MSG_MMU2_EJECTING_FILAMENT), int(index + 1));
|
||||
if (mmu2.ejectFilament(index, true)) ui.reset_status();
|
||||
if (mmu2.eject_filament(index, true)) ui.reset_status();
|
||||
}
|
||||
inline void action_mmu2_ejectFilament0() { _mmu2_ejectFilament(0); }
|
||||
inline void action_mmu2_ejectFilament1() { _mmu2_ejectFilament(1); }
|
||||
inline void action_mmu2_ejectFilament2() { _mmu2_ejectFilament(2); }
|
||||
inline void action_mmu2_ejectFilament3() { _mmu2_ejectFilament(3); }
|
||||
inline void action_mmu2_ejectFilament4() { _mmu2_ejectFilament(4); }
|
||||
inline void action_mmu2_eject_filament_0() { _mmu2_eject_filament(0); }
|
||||
inline void action_mmu2_eject_filament_1() { _mmu2_eject_filament(1); }
|
||||
inline void action_mmu2_eject_filament_2() { _mmu2_eject_filament(2); }
|
||||
inline void action_mmu2_eject_filament_3() { _mmu2_eject_filament(3); }
|
||||
inline void action_mmu2_eject_filament_4() { _mmu2_eject_filament(4); }
|
||||
|
||||
void action_mmu2_unloadFilament() {
|
||||
void action_mmu2_unload_filament() {
|
||||
ui.reset_status();
|
||||
ui.return_to_status();
|
||||
LCD_MESSAGEPGM(MSG_MMU2_UNLOADING_FILAMENT);
|
||||
@ -116,14 +116,14 @@ void action_mmu2_unloadFilament() {
|
||||
if (mmu2.unload()) ui.reset_status();
|
||||
}
|
||||
|
||||
void menu_mmu2_ejectFilament() {
|
||||
void menu_mmu2_eject_filament() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_MMU2_MENU);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT0, action_mmu2_ejectFilament0);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT1, action_mmu2_ejectFilament1);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT2, action_mmu2_ejectFilament2);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT3, action_mmu2_ejectFilament3);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT4, action_mmu2_ejectFilament4);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT0, action_mmu2_eject_filament_0);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT1, action_mmu2_eject_filament_1);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT2, action_mmu2_eject_filament_2);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT3, action_mmu2_eject_filament_3);
|
||||
MENU_ITEM(function, MSG_MMU2_FILAMENT4, action_mmu2_eject_filament_4);
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
@ -139,10 +139,10 @@ void action_mmu2_reset() {
|
||||
void menu_mmu2() {
|
||||
START_MENU();
|
||||
MENU_BACK(MSG_MAIN);
|
||||
MENU_ITEM(submenu, MSG_MMU2_LOAD_FILAMENT, menu_mmu2_loadFilament);
|
||||
MENU_ITEM(submenu, MSG_MMU2_LOAD_TO_NOZZLE, menu_mmu2_loadToNozzle);
|
||||
MENU_ITEM(submenu, MSG_MMU2_EJECT_FILAMENT, menu_mmu2_ejectFilament);
|
||||
MENU_ITEM(function, MSG_MMU2_UNLOAD_FILAMENT, action_mmu2_unloadFilament);
|
||||
MENU_ITEM(submenu, MSG_MMU2_LOAD_FILAMENT, menu_mmu2_load_filament);
|
||||
MENU_ITEM(submenu, MSG_MMU2_LOAD_TO_NOZZLE, menu_mmu2_load_to_nozzle);
|
||||
MENU_ITEM(submenu, MSG_MMU2_EJECT_FILAMENT, menu_mmu2_eject_filament);
|
||||
MENU_ITEM(function, MSG_MMU2_UNLOAD_FILAMENT, action_mmu2_unload_filament);
|
||||
MENU_ITEM(function, MSG_MMU2_RESET, action_mmu2_reset);
|
||||
END_MENU();
|
||||
}
|
||||
@ -161,7 +161,7 @@ inline void action_mmu2_choose2() { action_mmu2_choose(2); }
|
||||
inline void action_mmu2_choose3() { action_mmu2_choose(3); }
|
||||
inline void action_mmu2_choose4() { action_mmu2_choose(4); }
|
||||
|
||||
void menu_mmu2_chooseFilament() {
|
||||
void menu_mmu2_choose_filament() {
|
||||
START_MENU();
|
||||
#if LCD_HEIGHT > 2
|
||||
STATIC_ITEM(MSG_MMU2_CHOOSE_FILAMENT_HEADER, true, true);
|
||||
@ -178,21 +178,21 @@ void menu_mmu2_chooseFilament() {
|
||||
// MMU2 Filament Runout
|
||||
//
|
||||
|
||||
inline void action_mmu2_M600_loadCurrentFilament() { mmu2.loadFilament(currentTool); }
|
||||
inline void action_mmu2_M600_loadCurrentFilamentToNozzle() { mmu2.loadFilamentToNozzle(currentTool); }
|
||||
inline void action_mmu2_M600_unloadFilament() { mmu2.unload(); }
|
||||
inline void action_mmu2_M600_load_current_filament() { mmu2.load_filament(currentTool); }
|
||||
inline void action_mmu2_M600_load_current_filament_to_nozzle() { mmu2.load_filament_to_nozzle(currentTool); }
|
||||
inline void action_mmu2_M600_unload_filament() { mmu2.unload(); }
|
||||
inline void action_mmu2_M600_resume() { mmuMenuWait = false; }
|
||||
|
||||
void menu_mmu2_pause() {
|
||||
currentTool = mmu2.getCurrentTool();
|
||||
currentTool = mmu2.get_current_tool();
|
||||
START_MENU();
|
||||
#if LCD_HEIGHT > 2
|
||||
STATIC_ITEM(MSG_MMU2_FILAMENT_CHANGE_HEADER, true, true);
|
||||
#endif
|
||||
MENU_ITEM(function, MSG_MMU2_RESUME, action_mmu2_M600_resume);
|
||||
MENU_ITEM(function, MSG_MMU2_UNLOAD_FILAMENT, action_mmu2_M600_unloadFilament);
|
||||
MENU_ITEM(function, MSG_MMU2_LOAD_FILAMENT, action_mmu2_M600_loadCurrentFilament);
|
||||
MENU_ITEM(function, MSG_MMU2_LOAD_TO_NOZZLE, action_mmu2_M600_loadCurrentFilamentToNozzle);
|
||||
MENU_ITEM(function, MSG_MMU2_UNLOAD_FILAMENT, action_mmu2_M600_unload_filament);
|
||||
MENU_ITEM(function, MSG_MMU2_LOAD_FILAMENT, action_mmu2_M600_load_current_filament);
|
||||
MENU_ITEM(function, MSG_MMU2_LOAD_TO_NOZZLE, action_mmu2_M600_load_current_filament_to_nozzle);
|
||||
END_MENU();
|
||||
}
|
||||
|
||||
@ -203,9 +203,9 @@ void mmu2_M600() {
|
||||
while (mmuMenuWait) idle();
|
||||
}
|
||||
|
||||
uint8_t mmu2_chooseFilament() {
|
||||
uint8_t mmu2_choose_filament() {
|
||||
ui.defer_status_screen();
|
||||
ui.goto_screen(menu_mmu2_chooseFilament);
|
||||
ui.goto_screen(menu_mmu2_choose_filament);
|
||||
mmuMenuWait = true;
|
||||
while (mmuMenuWait) idle();
|
||||
ui.return_to_status();
|
||||
|
@ -25,4 +25,4 @@
|
||||
|
||||
void menu_mmu2();
|
||||
void mmu2_M600();
|
||||
uint8_t mmu2_chooseFilament();
|
||||
uint8_t mmu2_choose_filament();
|
||||
|
@ -121,16 +121,16 @@ static void _lcd_move_xyz(PGM_P name, AxisEnum axis) {
|
||||
#endif
|
||||
|
||||
// Get the new position
|
||||
const float diff = float((int32_t)ui.encoderPosition) * move_menu_scale;
|
||||
const float diff = float(int16_t(ui.encoderPosition)) * move_menu_scale;
|
||||
#if IS_KINEMATIC
|
||||
manual_move_offset += diff;
|
||||
if ((int32_t)ui.encoderPosition < 0)
|
||||
if (int16_t(ui.encoderPosition) < 0)
|
||||
NOLESS(manual_move_offset, min - current_position[axis]);
|
||||
else
|
||||
NOMORE(manual_move_offset, max - current_position[axis]);
|
||||
#else
|
||||
current_position[axis] += diff;
|
||||
if ((int32_t)ui.encoderPosition < 0)
|
||||
if (int16_t(ui.encoderPosition) < 0)
|
||||
NOLESS(current_position[axis], min);
|
||||
else
|
||||
NOMORE(current_position[axis], max);
|
||||
@ -161,7 +161,7 @@ static void _lcd_move_e(
|
||||
ui.encoder_direction_normal();
|
||||
if (ui.encoderPosition) {
|
||||
if (!ui.processing_manual_move) {
|
||||
const float diff = float((int32_t)ui.encoderPosition) * move_menu_scale;
|
||||
const float diff = float(int16_t(ui.encoderPosition)) * move_menu_scale;
|
||||
#if IS_KINEMATIC
|
||||
manual_move_offset += diff;
|
||||
#else
|
||||
@ -335,7 +335,7 @@ void menu_move() {
|
||||
else
|
||||
MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
|
||||
|
||||
#if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
|
||||
#if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD)
|
||||
|
||||
#if EXTRUDERS == 6
|
||||
switch (active_extruder) {
|
||||
@ -465,7 +465,7 @@ void menu_motion() {
|
||||
#if DISABLED(PROBE_MANUALLY)
|
||||
MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G28\nG29"));
|
||||
#endif
|
||||
if (leveling_is_valid()) {
|
||||
if (all_axes_homed() && leveling_is_valid()) {
|
||||
bool new_level_state = planner.leveling_active;
|
||||
MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
|
||||
}
|
||||
|
@ -47,10 +47,11 @@ void lcd_sd_updir() {
|
||||
|
||||
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
||||
|
||||
uint32_t last_sdfile_encoderPosition = 0xFFFF;
|
||||
uint16_t sd_encoder_position = 0xFFFF;
|
||||
int8_t sd_top_line, sd_items;
|
||||
|
||||
void MarlinUI::reselect_last_file() {
|
||||
if (last_sdfile_encoderPosition == 0xFFFF) return;
|
||||
if (sd_encoder_position == 0xFFFF) return;
|
||||
//#if HAS_GRAPHICAL_LCD
|
||||
// // This is a hack to force a screen update.
|
||||
// ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
|
||||
@ -61,8 +62,8 @@ void lcd_sd_updir() {
|
||||
// ui.drawing_screen = screen_changed = true;
|
||||
//#endif
|
||||
|
||||
goto_screen(menu_sdcard, last_sdfile_encoderPosition);
|
||||
last_sdfile_encoderPosition = 0xFFFF;
|
||||
goto_screen(menu_sdcard, sd_encoder_position, sd_top_line, sd_items);
|
||||
sd_encoder_position = 0xFFFF;
|
||||
|
||||
defer_status_screen();
|
||||
|
||||
@ -72,15 +73,44 @@ void lcd_sd_updir() {
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void sdcard_start_selected_file() {
|
||||
card.openAndPrintFile(card.filename);
|
||||
ui.return_to_status();
|
||||
ui.reset_status();
|
||||
}
|
||||
|
||||
#if ENABLED(SD_MENU_CONFIRM_START)
|
||||
|
||||
bool do_print_file;
|
||||
void menu_sd_confirm() {
|
||||
if (ui.should_draw())
|
||||
do_select_screen(PSTR(MSG_BUTTON_PRINT), PSTR(MSG_BUTTON_CANCEL), do_print_file, PSTR(MSG_START_PRINT " "), card.longest_filename(), PSTR("?"));
|
||||
|
||||
if (ui.use_click()) {
|
||||
if (do_print_file)
|
||||
sdcard_start_selected_file();
|
||||
else
|
||||
ui.goto_previous_screen();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class MenuItem_sdfile {
|
||||
public:
|
||||
static void action(CardReader &theCard) {
|
||||
#if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
|
||||
last_sdfile_encoderPosition = ui.encoderPosition; // Save which file was selected for later use
|
||||
// Save menu state for the selected file
|
||||
sd_encoder_position = ui.encoderPosition;
|
||||
sd_top_line = encoderTopLine;
|
||||
sd_items = screen_items;
|
||||
#endif
|
||||
#if ENABLED(SD_MENU_CONFIRM_START)
|
||||
do_print_file = false;
|
||||
MenuItem_submenu::action(menu_sd_confirm);
|
||||
#else
|
||||
sdcard_start_selected_file();
|
||||
#endif
|
||||
card.openAndPrintFile(theCard.filename);
|
||||
ui.return_to_status();
|
||||
ui.reset_status();
|
||||
}
|
||||
};
|
||||
|
||||
@ -89,7 +119,7 @@ class MenuItem_sdfolder {
|
||||
static void action(CardReader &theCard) {
|
||||
card.chdir(theCard.filename);
|
||||
encoderTopLine = 0;
|
||||
ui.encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
|
||||
ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
|
||||
screen_changed = true;
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
ui.drawing_screen = false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
|
@ -65,32 +65,60 @@
|
||||
|
||||
#if ENABLED(BABYSTEPPING)
|
||||
|
||||
long babysteps_done = 0;
|
||||
#include "../../feature/babystep.h"
|
||||
#include "../lcdprint.h"
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
#include "../dogm/ultralcd_DOGM.h"
|
||||
#endif
|
||||
|
||||
void _lcd_babystep(const AxisEnum axis, PGM_P msg) {
|
||||
void _lcd_babystep(const AxisEnum axis, PGM_P const msg) {
|
||||
if (ui.use_click()) return ui.goto_previous_screen_no_defer();
|
||||
ui.encoder_direction_normal();
|
||||
if (ui.encoderPosition) {
|
||||
const int16_t babystep_increment = (int32_t)ui.encoderPosition * (BABYSTEP_MULTIPLICATOR);
|
||||
const int16_t steps = int16_t(ui.encoderPosition) * (BABYSTEP_MULTIPLICATOR);
|
||||
ui.encoderPosition = 0;
|
||||
ui.refresh(LCDVIEW_REDRAW_NOW);
|
||||
thermalManager.babystep_axis(axis, babystep_increment);
|
||||
babysteps_done += babystep_increment;
|
||||
babystep.add_steps(axis, steps);
|
||||
}
|
||||
if (ui.should_draw())
|
||||
draw_edit_screen(msg, ftostr43sign(planner.steps_to_mm[axis] * babysteps_done));
|
||||
if (ui.should_draw()) {
|
||||
const float spm = planner.steps_to_mm[axis];
|
||||
draw_edit_screen(msg, ftostr54sign(spm * babystep.accum));
|
||||
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
||||
const bool in_view = (true
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
&& PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1)
|
||||
#endif
|
||||
);
|
||||
if (in_view) {
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
ui.set_font(FONT_MENU);
|
||||
lcd_moveto(0, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT);
|
||||
#else
|
||||
lcd_moveto(0, LCD_HEIGHT - 1);
|
||||
#endif
|
||||
lcd_put_u8str_P(PSTR(MSG_BABYSTEP_TOTAL ":"));
|
||||
lcd_put_u8str(ftostr54sign(spm * babystep.axis_total[BS_TOTAL_AXIS(axis)]));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline void _lcd_babystep_go(const screenFunc_t screen) {
|
||||
ui.goto_screen(screen);
|
||||
ui.defer_status_screen();
|
||||
babystep.accum = 0;
|
||||
}
|
||||
|
||||
#if ENABLED(BABYSTEP_XY)
|
||||
void _lcd_babystep_x() { _lcd_babystep(X_AXIS, PSTR(MSG_BABYSTEP_X)); }
|
||||
void _lcd_babystep_y() { _lcd_babystep(Y_AXIS, PSTR(MSG_BABYSTEP_Y)); }
|
||||
void lcd_babystep_x() { ui.goto_screen(_lcd_babystep_x); babysteps_done = 0; ui.defer_status_screen(); }
|
||||
void lcd_babystep_y() { ui.goto_screen(_lcd_babystep_y); babysteps_done = 0; ui.defer_status_screen(); }
|
||||
void lcd_babystep_x() { _lcd_babystep_go(_lcd_babystep_x); }
|
||||
void lcd_babystep_y() { _lcd_babystep_go(_lcd_babystep_y); }
|
||||
#endif
|
||||
|
||||
#if DISABLED(BABYSTEP_ZPROBE_OFFSET)
|
||||
void _lcd_babystep_z() { _lcd_babystep(Z_AXIS, PSTR(MSG_BABYSTEP_Z)); }
|
||||
void lcd_babystep_z() { ui.goto_screen(_lcd_babystep_z); babysteps_done = 0; ui.defer_status_screen(); }
|
||||
void lcd_babystep_z() { _lcd_babystep_go(_lcd_babystep_z); }
|
||||
#endif
|
||||
|
||||
#endif // BABYSTEPPING
|
||||
|
@ -471,7 +471,7 @@ void _lcd_ubl_output_map_lcd() {
|
||||
ui.encoder_direction_normal();
|
||||
|
||||
if (ui.encoderPosition) {
|
||||
step_scaler += (int32_t)ui.encoderPosition;
|
||||
step_scaler += int16_t(ui.encoderPosition);
|
||||
x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
|
||||
ui.encoderPosition = 0;
|
||||
ui.refresh(LCDVIEW_REDRAW_NOW);
|
||||
|
Reference in New Issue
Block a user