Skip to content

Commit

Permalink
Long press left/right for panning in raw view.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 1, 2023
1 parent 999cc48 commit 9503bde
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ Core improvements

- Detection of non Manchester and non RZ encoded signals. Not sure if there are any signals that are not self clocked widely used in RF. Note that the current approach already detects encodings using short high + long low and long high + short low to encode 0 and 1. In addition to the current classifier, it is possible to add one that checks for a sequence of pulses that are all multiples of some base length. This should detect, for instance, even NRZ encodings where 1 and 0 are just clocked as they are.

- Views on-enter on-exit.

Features
========

- Help screen (with press ok for next page).
- Detect the line code used and try to decode the message as hex dump.
- Pressing right/left you browse different modes:
* Current best signal pulse classes.
Expand Down
62 changes: 39 additions & 23 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void render_signal(ProtoViewApp *app, Canvas *const canvas, RawSamplesBuffer *bu

int rows = 8;
uint32_t time_per_pixel = app->us_scale;
uint32_t start_idx = idx;
bool level = 0;
uint32_t dur = 0, sample_num = 0;
for (int row = 0; row < rows ; row++) {
Expand All @@ -42,7 +43,7 @@ void render_signal(ProtoViewApp *app, Canvas *const canvas, RawSamplesBuffer *bu

/* Write a small triangle under the last sample detected. */
if (app->signal_bestlen != 0 &&
sample_num == app->signal_bestlen+1)
sample_num+start_idx == app->signal_bestlen+1)
{
canvas_draw_dot(canvas,x,y+2);
canvas_draw_dot(canvas,x-1,y+3);
Expand Down Expand Up @@ -211,7 +212,7 @@ void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const cha
/* Raw pulses rendering. This is our default view. */
void render_view_raw_pulses(Canvas *const canvas, ProtoViewApp *app) {
/* Show signal. */
render_signal(app, canvas, DetectedSamples, 0);
render_signal(app, canvas, DetectedSamples, app->signal_offset);

/* Show signal information. */
char buf[64];
Expand Down Expand Up @@ -280,10 +281,8 @@ static void input_callback(InputEvent* input_event, void* ctx)
{
ProtoViewApp *app = ctx;

if (input_event->type == InputTypePress) {
furi_message_queue_put(app->event_queue,input_event,FuriWaitForever);
FURI_LOG_E(TAG, "INPUT CALLBACK %d", (int)input_event->key);
}
furi_message_queue_put(app->event_queue,input_event,FuriWaitForever);
FURI_LOG_E(TAG, "INPUT CALLBACK %d", (int)input_event->key);
}

/* Allocate the application state and initialize a number of stuff.
Expand All @@ -297,7 +296,7 @@ ProtoViewApp* protoview_app_alloc() {

//init setting
app->setting = subghz_setting_alloc();
subghz_setting_load(app->setting, EXT_PATH("protoview/settings.txt"));
subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user"));

// GUI
app->gui = furi_record_open(RECORD_GUI);
Expand All @@ -311,6 +310,7 @@ ProtoViewApp* protoview_app_alloc() {
// Signal found and visualization defaults
app->signal_bestlen = 0;
app->us_scale = 100;
app->signal_offset = 0;

//init Worker & Protocol
app->txrx = malloc(sizeof(ProtoViewTxRx));
Expand Down Expand Up @@ -382,18 +382,27 @@ static void timer_callback(void *ctx) {

/* Handle input for the raw pulses view. */
void process_input_raw_pulses(ProtoViewApp *app, InputEvent input) {
if (input.key == InputKeyOk) {
/* Reset the current sample to capture the next. */
app->signal_bestlen = 0;
raw_samples_reset(DetectedSamples);
raw_samples_reset(RawSamples);
} else if (input.key == InputKeyDown) {
/* Rescaling. The set becomes finer under 50us per pixel. */
uint32_t scale_step = app->us_scale >= 50 ? 50 : 10;
if (app->us_scale < 500) app->us_scale += scale_step;
} else if (input.key == InputKeyUp) {
uint32_t scale_step = app->us_scale > 50 ? 50 : 10;
if (app->us_scale > 10) app->us_scale -= scale_step;
if (input.type == InputTypeRepeat) {
/* Handle panning of the signal window. Long pressing
* right will show successive samples, long pressing left
* previous samples. */
if (input.key == InputKeyRight) app->signal_offset++;
else if (input.key == InputKeyLeft) app->signal_offset--;
} else if (input.type == InputTypeShort) {
if (input.key == InputKeyOk) {
/* Reset the current sample to capture the next. */
app->signal_bestlen = 0;
app->signal_offset = 0;
raw_samples_reset(DetectedSamples);
raw_samples_reset(RawSamples);
} else if (input.key == InputKeyDown) {
/* Rescaling. The set becomes finer under 50us per pixel. */
uint32_t scale_step = app->us_scale >= 50 ? 50 : 10;
if (app->us_scale < 500) app->us_scale += scale_step;
} else if (input.key == InputKeyUp) {
uint32_t scale_step = app->us_scale > 50 ? 50 : 10;
if (app->us_scale > 10) app->us_scale -= scale_step;
}
}
}

Expand Down Expand Up @@ -465,18 +474,25 @@ int32_t protoview_app_entry(void* p) {
while(app->running) {
FuriStatus qstat = furi_message_queue_get(app->event_queue, &input, 100);
if (qstat == FuriStatusOk) {
FURI_LOG_E(TAG, "Main Loop - Input: %u", input.key);
FURI_LOG_E(TAG, "Main Loop - Input: type %d key %u",
input.type, input.key);

/* Handle navigation here. Then handle view-specific inputs
* in the view specific handling function. */
if (input.key == InputKeyBack) {
if (input.type == InputTypeShort &&
input.key == InputKeyBack)
{
/* Exit the app. */
app->running = 0;
} else if (input.key == InputKeyRight) {
} else if (input.type == InputTypeShort &&
input.key == InputKeyRight)
{
/* Go to the next view. */
app->current_view++;
if (app->current_view == ViewLast) app->current_view = 0;
} else if (input.key == InputKeyLeft) {
} else if (input.type == InputTypeShort &&
input.key == InputKeyLeft)
{
/* Go to the previous view. */
if (app->current_view == 0)
app->current_view = ViewLast-1;
Expand Down
1 change: 1 addition & 0 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct ProtoViewApp {
int running; /* Once false exists the app. */
uint32_t signal_bestlen; /* Longest coherent signal observed so far. */
uint32_t us_scale; /* microseconds per pixel. */
uint32_t signal_offset; /* Long press left/right panning in raw view. */
uint32_t frequency; /* Current frequency. */
uint8_t modulation; /* Current modulation ID, array index in the
ProtoViewModulations table. */
Expand Down

0 comments on commit 9503bde

Please sign in to comment.