Skip to content

Commit 235bb2a

Browse files
authored
Merge pull request #3 from prplecake/ir_decoder
2 parents 317a740 + bbbd1fb commit 235bb2a

File tree

4 files changed

+45
-36
lines changed

4 files changed

+45
-36
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "bit_ops.h"
2+
3+
// https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/746382#746382
4+
int bit_reversal(uint32_t input) {
5+
int s = sizeof(input) * 2;
6+
int i, x, y, p;
7+
int rtn = 0;
8+
9+
for(i = 0; i < (s / 2); i++) {
10+
// extract bit on the left, from MSB
11+
p = s - i - 1;
12+
x = input & (1 << p);
13+
x = x >> p;
14+
15+
// extract bit on the right, from LSB
16+
y = input & (1 << i);
17+
y = y >> i;
18+
19+
rtn = rtn | (x << i);
20+
rtn = rtn | (y << p);
21+
}
22+
return rtn;
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <stdint.h>
4+
5+
int bit_reversal(uint32_t input);

infrared/apps/ir_decoder/ir_decoder.c

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,4 @@
1-
#include <furi.h>
2-
#include <furi_hal.h>
3-
#include <infrared.h>
4-
#include <infrared_worker.h>
5-
#include <furi_hal_infrared.h>
6-
#include <gui/gui.h>
7-
8-
#define TAG "IR Decoder"
9-
10-
typedef struct {
11-
InfraredMessage* decoded_signal;
12-
FuriMutex* mutex;
13-
ViewPort* view_port;
14-
} IRDecoderState;
15-
16-
// https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/746382#746382
17-
static int bit_reversal(uint32_t input) {
18-
int s = sizeof(input) * 2;
19-
int i, x, y, p;
20-
int rtn = 0;
21-
22-
for(i = 0; i < (s / 2); i++) {
23-
// extract bit on the left, from MSB
24-
p = s - i - 1;
25-
x = input & (1 << p);
26-
x = x >> p;
27-
28-
// extract bit on the right, from LSB
29-
y = input & (1 << i);
30-
y = y >> i;
31-
32-
rtn = rtn | (x << i);
33-
rtn = rtn | (y << p);
34-
}
35-
return rtn;
36-
}
1+
#include "ir_decoder.h"
372

383
static void render_callback(Canvas* canvas, void* ctx) {
394
FURI_LOG_T(TAG, "Render callback");

infrared/apps/ir_decoder/ir_decoder.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <furi.h>
2+
#include <furi_hal.h>
3+
#include <infrared.h>
4+
#include <infrared_worker.h>
5+
#include <furi_hal_infrared.h>
6+
#include <gui/gui.h>
7+
8+
#include "helpers/bit_ops.h"
9+
10+
#define TAG "IR Decoder"
11+
12+
typedef struct {
13+
InfraredMessage* decoded_signal;
14+
FuriMutex* mutex;
15+
ViewPort* view_port;
16+
} IRDecoderState;

0 commit comments

Comments
 (0)