Skip to content

Commit

Permalink
Display short pulse length.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Dec 29, 2022
1 parent 04826a8 commit bdaebc5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
3 changes: 1 addition & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Core improvements
=================

- Remove processing from rendering callback, put it into timer.
- 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.
- 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.

Features
========
Expand Down
40 changes: 38 additions & 2 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extern const SubGhzProtocolRegistry protoview_protocol_registry;
* The 'idx' argument is the first sample to render in the circular
* buffer. */
void render_signal(Canvas *const canvas, RawSamplesBuffer *buf, uint32_t idx) {
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, 0, 0, 127, 63);
canvas_set_color(canvas, ColorBlack);

int rows = 8;
Expand Down Expand Up @@ -151,9 +149,47 @@ void scan_for_signal(ProtoViewApp *app) {
raw_samples_free(copy);
}

/* Draw some white text with a black border. */
void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str)
{
struct {
uint8_t x; uint8_t y;
} dir[8] = {
{-1,-1},
{0,-1},
{1,-1},
{1,0},
{1,1},
{0,1},
{-1,1},
{-1,0}
};

/* Rotate in all the directions writing the same string in black
* to create a border, then write the actaul string in white in the
* middle. */
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontSecondary);
for (int j = 0; j < 8; j++)
canvas_draw_str(canvas,x+dir[j].x,y+dir[j].y,str);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str(canvas,x,y,str);
}

static void render_callback(Canvas *const canvas, void *ctx) {
UNUSED(ctx);

/* Clear screen. */
canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, 0, 0, 127, 63);

/* Show signal. */
render_signal(canvas, DetectedSamples, 0);

/* Show signal information. */
char buf[64];
snprintf(buf,sizeof(buf),"%luus", (unsigned long)DetectedSamples->short_pulse_dur);
canvas_draw_str_with_border(canvas, 100, 63, buf);
}

/* Here all we do is putting the events into the queue that will be handled
Expand Down
1 change: 1 addition & 0 deletions app_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void raw_samples_copy(RawSamplesBuffer *dst, RawSamplesBuffer *src) {
furi_mutex_acquire(src->mutex,FuriWaitForever);
furi_mutex_acquire(dst->mutex,FuriWaitForever);
dst->idx = src->idx;
dst->short_pulse_dur = src->short_pulse_dur;
memcpy(dst->level,src->level,sizeof(dst->level));
memcpy(dst->dur,src->dur,sizeof(dst->dur));
furi_mutex_release(src->mutex);
Expand Down

0 comments on commit bdaebc5

Please sign in to comment.