Merge pull request #2071 from d18c7db/master

Bugfix to graph scrolling with keyboard
This commit is contained in:
Iceman 2023-08-09 16:06:14 +02:00 committed by GitHub
commit 81a0739153
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 117 additions and 120 deletions

10
.vscode/setup.sh vendored
View file

@ -129,17 +129,17 @@ fi
HOSTOS=$(uname | awk '{print toupper($0)}') HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then if [ "$HOSTOS" = "LINUX" ]; then
if uname -a|grep -q Microsoft; then if uname -a|grep -q Microsoft; then
setup_wsl setup_wsl
else else
setup_linux setup_linux
fi fi
elif [ "$HOSTOS" = "DARWIN" ]; then elif [ "$HOSTOS" = "DARWIN" ]; then
echo >&2 "[!!] MacOS not supported, sorry!" echo >&2 "[!!] MacOS not supported, sorry!"
exit 1 exit 1
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
setup_ps setup_ps
else else
echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS" echo >&2 "[!!] Host OS not recognized, abort: $HOSTOS"
exit 1 exit 1
fi fi

View file

@ -95,43 +95,43 @@ void SetupSpi(int mode) {
case SPI_FPGA_MODE: case SPI_FPGA_MODE:
AT91C_BASE_SPI->SPI_MR = AT91C_BASE_SPI->SPI_MR =
(0 << 24) | // Delay between chip selects (take default: 6 MCK periods) (0 << 24) | // Delay between chip selects (take default: 6 MCK periods)
(0xE << 16) | // Peripheral Chip Select (selects FPGA SPI_NCS0 or PA11) (0xE << 16) | // Peripheral Chip Select (selects FPGA SPI_NCS0 or PA11)
(0 << 7) | // Local Loopback Disabled (0 << 7) | // Local Loopback Disabled
AT91C_SPI_MODFDIS | // Mode Fault Detection disabled AT91C_SPI_MODFDIS | // Mode Fault Detection disabled
(0 << 2) | // Chip selects connected directly to peripheral (0 << 2) | // Chip selects connected directly to peripheral
AT91C_SPI_PS_FIXED | // Fixed Peripheral Select AT91C_SPI_PS_FIXED | // Fixed Peripheral Select
AT91C_SPI_MSTR; // Master Mode AT91C_SPI_MSTR; // Master Mode
AT91C_BASE_SPI->SPI_CSR[0] = AT91C_BASE_SPI->SPI_CSR[0] =
(1 << 24) | // Delay between Consecutive Transfers (32 MCK periods) (1 << 24) | // Delay between Consecutive Transfers (32 MCK periods)
(1 << 16) | // Delay Before SPCK (1 MCK period) (1 << 16) | // Delay Before SPCK (1 MCK period)
(6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24MHz/6 = 4M baud (6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24MHz/6 = 4M baud
AT91C_SPI_BITS_16 | // Bits per Transfer (16 bits) AT91C_SPI_BITS_16 | // Bits per Transfer (16 bits)
(0 << 3) | // Chip Select inactive after transfer (0 << 3) | // Chip Select inactive after transfer
AT91C_SPI_NCPHA | // Clock Phase data captured on leading edge, changes on following edge AT91C_SPI_NCPHA | // Clock Phase data captured on leading edge, changes on following edge
(0 << 0); // Clock Polarity inactive state is logic 0 (0 << 0); // Clock Polarity inactive state is logic 0
break; break;
/* /*
case SPI_LCD_MODE: case SPI_LCD_MODE:
AT91C_BASE_SPI->SPI_MR = AT91C_BASE_SPI->SPI_MR =
( 0 << 24) | // Delay between chip selects (take default: 6 MCK periods) ( 0 << 24) | // Delay between chip selects (take default: 6 MCK periods)
(0xB << 16) | // Peripheral Chip Select (selects LCD SPI_NCS2 or PA10) (0xB << 16) | // Peripheral Chip Select (selects LCD SPI_NCS2 or PA10)
( 0 << 7) | // Local Loopback Disabled ( 0 << 7) | // Local Loopback Disabled
( 1 << 4) | // Mode Fault Detection disabled ( 1 << 4) | // Mode Fault Detection disabled
( 0 << 2) | // Chip selects connected directly to peripheral ( 0 << 2) | // Chip selects connected directly to peripheral
( 0 << 1) | // Fixed Peripheral Select ( 0 << 1) | // Fixed Peripheral Select
( 1 << 0); // Master Mode ( 1 << 0); // Master Mode
AT91C_BASE_SPI->SPI_CSR[2] = AT91C_BASE_SPI->SPI_CSR[2] =
( 1 << 24) | // Delay between Consecutive Transfers (32 MCK periods) ( 1 << 24) | // Delay between Consecutive Transfers (32 MCK periods)
( 1 << 16) | // Delay Before SPCK (1 MCK period) ( 1 << 16) | // Delay Before SPCK (1 MCK period)
( 6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24MHz/6 = 4M baud ( 6 << 8) | // Serial Clock Baud Rate (baudrate = MCK/6 = 24MHz/6 = 4M baud
AT91C_SPI_BITS_9 | // Bits per Transfer (9 bits) AT91C_SPI_BITS_9 | // Bits per Transfer (9 bits)
( 0 << 3) | // Chip Select inactive after transfer ( 0 << 3) | // Chip Select inactive after transfer
( 1 << 1) | // Clock Phase data captured on leading edge, changes on following edge ( 1 << 1) | // Clock Phase data captured on leading edge, changes on following edge
( 0 << 0); // Clock Polarity inactive state is logic 0 ( 0 << 0); // Clock Polarity inactive state is logic 0
break; break;
*/ */
default: default:
DisableSpi(); DisableSpi();
break; break;

View file

@ -379,7 +379,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/fileutils.c ${PM3_ROOT}/client/src/fileutils.c
${PM3_ROOT}/client/src/flash.c ${PM3_ROOT}/client/src/flash.c
${PM3_ROOT}/client/src/graph.c ${PM3_ROOT}/client/src/graph.c
${PM3_ROOT}/client/src/iso4217.c ${PM3_ROOT}/client/src/iso4217.c
${PM3_ROOT}/client/src/jansson_path.c ${PM3_ROOT}/client/src/jansson_path.c
${PM3_ROOT}/client/src/preferences.c ${PM3_ROOT}/client/src/preferences.c
${PM3_ROOT}/client/src/pm3.c ${PM3_ROOT}/client/src/pm3.c

View file

@ -10,8 +10,8 @@ add_library(pm3rrg_rdv4_mbedtls STATIC
../../common/mbedtls/error.c ../../common/mbedtls/error.c
../../common/mbedtls/ecp.c ../../common/mbedtls/ecp.c
../../common/mbedtls/ecdh.c ../../common/mbedtls/ecdh.c
../../common/mbedtls/ecc_point_compression.c ../../common/mbedtls/ecc_point_compression.c
../../common/mbedtls/gcm.c ../../common/mbedtls/gcm.c
../../common/mbedtls/ecp_curves.c ../../common/mbedtls/ecp_curves.c
../../common/mbedtls/certs.c ../../common/mbedtls/certs.c
../../common/mbedtls/camellia.c ../../common/mbedtls/camellia.c

View file

@ -379,7 +379,7 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/fileutils.c ${PM3_ROOT}/client/src/fileutils.c
${PM3_ROOT}/client/src/flash.c ${PM3_ROOT}/client/src/flash.c
${PM3_ROOT}/client/src/graph.c ${PM3_ROOT}/client/src/graph.c
${PM3_ROOT}/client/src/iso4217.c ${PM3_ROOT}/client/src/iso4217.c
${PM3_ROOT}/client/src/jansson_path.c ${PM3_ROOT}/client/src/jansson_path.c
${PM3_ROOT}/client/src/preferences.c ${PM3_ROOT}/client/src/preferences.c
${PM3_ROOT}/client/src/pm3.c ${PM3_ROOT}/client/src/pm3.c

View file

@ -25,7 +25,6 @@
"description": "iPhones before IOS17 emit this frame so that other Apple devices don't react to the field during background reading. Also emitted during NFCReaderSession subtypes" "description": "iPhones before IOS17 emit this frame so that other Apple devices don't react to the field during background reading. Also emitted during NFCReaderSession subtypes"
}, },
{ {
"value": "6a02c801000300000000000000", "value": "6a02c801000300000000000000",
"name": "Transit: Ventra", "name": "Transit: Ventra",

View file

@ -690,7 +690,7 @@ static int CmdSetDivisor(const char *Cmd) {
CLIParserFree(ctx); CLIParserFree(ctx);
if (arg < 19) { if (arg < 19) {
PrintAndLogEx(ERR, "Divisor must be between" _YELLOW_("19") " and " _YELLOW_("255")); PrintAndLogEx(ERR, "Divisor must be between " _YELLOW_("19") " and " _YELLOW_("255"));
return PM3_EINVARG; return PM3_EINVARG;
} }
// 12 000 000 (12MHz) // 12 000 000 (12MHz)

View file

@ -794,7 +794,7 @@ void Plot::paintEvent(QPaintEvent *event) {
snprintf(scalestr, sizeof(scalestr), "[%2.2f %s] ", ((int32_t)(CursorBPos - CursorAPos)) / g_CursorScaleFactor, g_CursorScaleFactorUnit); snprintf(scalestr, sizeof(scalestr), "[%2.2f %s] ", ((int32_t)(CursorBPos - CursorAPos)) / g_CursorScaleFactor, g_CursorScaleFactorUnit);
} }
} }
snprintf(str, sizeof(str), "@%u..%u dt=%i %szoom=%2.2f CursorAPos=%u CursorBPos=%u GridX=%lf GridY=%lf (%s) GridXoffset=%lf", snprintf(str, sizeof(str), "@%u..%u dt=%i %szoom=%2.3f CursorAPos=%u CursorBPos=%u GridX=%lf GridY=%lf (%s) GridXoffset=%lf",
g_GraphStart, g_GraphStart,
g_GraphStop, g_GraphStop,
CursorBPos - CursorAPos, CursorBPos - CursorAPos,
@ -838,17 +838,25 @@ void Plot::closeEvent(QCloseEvent *event) {
gs_useOverlays = false; gs_useOverlays = false;
} }
// every 4 steps the zoom doubles (or halves)
#define ZOOM_STEP (1.189207)
// limit zoom to 32 times in either direction
#define ZOOM_LIMIT (32)
void Plot::Zoom(double factor, uint32_t refX) { void Plot::Zoom(double factor, uint32_t refX) {
double g_GraphPixelsPerPointNew = g_GraphPixelsPerPoint * factor;
if (factor >= 1) { // Zoom in if (factor >= 1) { // Zoom in
if (g_GraphPixelsPerPoint <= 25 * factor) { if (g_GraphPixelsPerPointNew <= ZOOM_LIMIT) {
g_GraphPixelsPerPoint *= factor; g_GraphPixelsPerPoint = g_GraphPixelsPerPointNew;
if (refX > g_GraphStart) { if (refX > g_GraphStart) {
g_GraphStart += (refX - g_GraphStart) - ((refX - g_GraphStart) / factor); g_GraphStart += (refX - g_GraphStart) - ((refX - g_GraphStart) / factor);
} }
} }
} else { // Zoom out } else { // Zoom out
if (g_GraphPixelsPerPoint >= 0.01 / factor) { if (g_GraphPixelsPerPointNew >= (1.0 / ZOOM_LIMIT) ) {
g_GraphPixelsPerPoint *= factor; g_GraphPixelsPerPoint = g_GraphPixelsPerPointNew;
// shift graph towards refX when zooming out
if (refX > g_GraphStart) { if (refX > g_GraphStart) {
if (g_GraphStart >= ((refX - g_GraphStart) / factor) - (refX - g_GraphStart)) { if (g_GraphStart >= ((refX - g_GraphStart) / factor) - (refX - g_GraphStart)) {
g_GraphStart -= ((refX - g_GraphStart) / factor) - (refX - g_GraphStart); g_GraphStart -= ((refX - g_GraphStart) / factor) - (refX - g_GraphStart);
@ -885,7 +893,6 @@ void Plot::Move(int offset) {
void Plot::Trim(void) { void Plot::Trim(void) {
uint32_t lref, rref; uint32_t lref, rref;
const double zoom_offset = 1.148698354997035; // 2**(1/5)
if ((CursorAPos == 0) || (CursorBPos == 0)) { // if we don't have both cursors set if ((CursorAPos == 0) || (CursorBPos == 0)) { // if we don't have both cursors set
lref = g_GraphStart; lref = g_GraphStart;
rref = g_GraphStop; rref = g_GraphStop;
@ -902,12 +909,12 @@ void Plot::Trim(void) {
} else { } else {
lref = CursorAPos < CursorBPos ? CursorAPos : CursorBPos; lref = CursorAPos < CursorBPos ? CursorAPos : CursorBPos;
rref = CursorAPos < CursorBPos ? CursorBPos : CursorAPos; rref = CursorAPos < CursorBPos ? CursorBPos : CursorAPos;
// g_GraphPixelsPerPoint mush remain a power of zoom_offset // g_GraphPixelsPerPoint must remain a power of ZOOM_STEP
double GPPPtarget = g_GraphPixelsPerPoint * (g_GraphStop - g_GraphStart) / (rref - lref); double GPPPtarget = g_GraphPixelsPerPoint * (g_GraphStop - g_GraphStart) / (rref - lref);
while (g_GraphPixelsPerPoint < GPPPtarget) { while (g_GraphPixelsPerPoint < GPPPtarget) {
g_GraphPixelsPerPoint *= zoom_offset; g_GraphPixelsPerPoint *= ZOOM_STEP;
} }
g_GraphPixelsPerPoint /= zoom_offset; g_GraphPixelsPerPoint /= ZOOM_STEP;
CursorAPos -= lref; CursorAPos -= lref;
CursorBPos -= lref; CursorBPos -= lref;
} }
@ -925,34 +932,26 @@ void Plot::wheelEvent(QWheelEvent *event) {
const float move_offset = 0.05; const float move_offset = 0.05;
// -120+shift => zoom in (5 times = *2) // -120+shift => zoom in (5 times = *2)
// 120+shift => zoom out (5 times = /2) // 120+shift => zoom out (5 times = /2)
const double zoom_offset = 1.148698354997035; // 2**(1/5)
if (event->modifiers() & Qt::ShiftModifier) {
// event->position doesn't exist in QT5.12.8, both exist in 5.14.2 and event->x doesn't exist in 5.15.0
#if QT_VERSION >= 0x050d00 #if QT_VERSION >= 0x050d00
uint32_t x = event->position().x(); // event->position doesn't exist in QT5.12.8, both exist in 5.14.2 and event->x doesn't exist in 5.15.0
uint32_t x = event->position().x();
// event->angleDelta doesn't exist in QT4, both exist in 5.12.8 and 5.14.2 and event->delta doesn't exist in 5.15.0
float delta = -event->angleDelta().y();
#else #else
uint32_t x = event->x(); uint32_t x = event->x();
float delta = -event->delta();
#endif #endif
if (event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier)) {
x -= WIDTH_AXES; x -= WIDTH_AXES;
x = (int)(x / g_GraphPixelsPerPoint); x = (int)(x / g_GraphPixelsPerPoint);
x += g_GraphStart; x += g_GraphStart;
// event->angleDelta doesn't exist in QT4, both exist in 5.12.8 and 5.14.2 and event->delta doesn't exist in 5.15.0
#if QT_VERSION >= 0x050d00
float delta = event->angleDelta().y();
#else
float delta = event->delta();
#endif
if (delta < 0) { if (delta < 0) {
Zoom(zoom_offset, x); Zoom(ZOOM_STEP, x);
} else { } else {
Zoom(1.0 / zoom_offset, x); Zoom(1.0 / ZOOM_STEP, x);
} }
} else { } else {
#if QT_VERSION >= 0x050d00 Move(PageWidth * delta * move_offset / 120 );
Move(PageWidth * (-(float)event->angleDelta().y() / (120 / move_offset)));
#else
Move(PageWidth * (-(float)event->delta() / (120 / move_offset)));
#endif
} }
this->update(); this->update();
} }
@ -972,7 +971,6 @@ void Plot::mouseMoveEvent(QMouseEvent *event) {
void Plot::keyPressEvent(QKeyEvent *event) { void Plot::keyPressEvent(QKeyEvent *event) {
uint32_t offset; // Left/right movement offset (in sample size) uint32_t offset; // Left/right movement offset (in sample size)
const double zoom_offset = 1.148698354997035; // 2**(1/5)
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
if (g_PlotGridX) if (g_PlotGridX)
@ -983,22 +981,22 @@ void Plot::keyPressEvent(QKeyEvent *event) {
if (event->modifiers() & Qt::ControlModifier) if (event->modifiers() & Qt::ControlModifier)
offset = 1; offset = 1;
else else
offset = (int)(20 / g_GraphPixelsPerPoint); offset = int(ZOOM_LIMIT/g_GraphPixelsPerPoint);
} }
switch (event->key()) { switch (event->key()) {
case Qt::Key_Down: case Qt::Key_Down:
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
Zoom(zoom_offset, CursorBPos); Zoom(ZOOM_STEP, CursorBPos);
} else { } else {
Zoom(2, CursorBPos); Zoom(ZOOM_STEP*2, CursorBPos);
} }
} else { } else {
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
Zoom(zoom_offset, CursorAPos); Zoom(ZOOM_STEP, CursorAPos);
} else { } else {
Zoom(2, CursorAPos); Zoom(ZOOM_STEP*2, CursorAPos);
} }
} }
break; break;
@ -1006,15 +1004,15 @@ void Plot::keyPressEvent(QKeyEvent *event) {
case Qt::Key_Up: case Qt::Key_Up:
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
Zoom(1.0 / zoom_offset, CursorBPos); Zoom(1.0 / ZOOM_STEP, CursorBPos);
} else { } else {
Zoom(0.5, CursorBPos); Zoom(1.0 / (ZOOM_STEP*2), CursorBPos);
} }
} else { } else {
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
Zoom(1.0 / zoom_offset, CursorAPos); Zoom(1.0 / ZOOM_STEP, CursorAPos);
} else { } else {
Zoom(0.5, CursorAPos); Zoom(1.0 / (ZOOM_STEP*2), CursorAPos);
} }
} }
break; break;