Skip to content

Commit

Permalink
Merge pull request #3 from prplecake/ir_decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
prplecake authored Apr 6, 2024
2 parents 317a740 + bbbd1fb commit 235bb2a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
23 changes: 23 additions & 0 deletions infrared/apps/ir_decoder/helpers/bit_ops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "bit_ops.h"

// https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/746382#746382
int bit_reversal(uint32_t input) {
int s = sizeof(input) * 2;
int i, x, y, p;
int rtn = 0;

for(i = 0; i < (s / 2); i++) {
// extract bit on the left, from MSB
p = s - i - 1;
x = input & (1 << p);
x = x >> p;

// extract bit on the right, from LSB
y = input & (1 << i);
y = y >> i;

rtn = rtn | (x << i);
rtn = rtn | (y << p);
}
return rtn;
}
5 changes: 5 additions & 0 deletions infrared/apps/ir_decoder/helpers/bit_ops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <stdint.h>

int bit_reversal(uint32_t input);
37 changes: 1 addition & 36 deletions infrared/apps/ir_decoder/ir_decoder.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
#include <furi.h>
#include <furi_hal.h>
#include <infrared.h>
#include <infrared_worker.h>
#include <furi_hal_infrared.h>
#include <gui/gui.h>

#define TAG "IR Decoder"

typedef struct {
InfraredMessage* decoded_signal;
FuriMutex* mutex;
ViewPort* view_port;
} IRDecoderState;

// https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c/746382#746382
static int bit_reversal(uint32_t input) {
int s = sizeof(input) * 2;
int i, x, y, p;
int rtn = 0;

for(i = 0; i < (s / 2); i++) {
// extract bit on the left, from MSB
p = s - i - 1;
x = input & (1 << p);
x = x >> p;

// extract bit on the right, from LSB
y = input & (1 << i);
y = y >> i;

rtn = rtn | (x << i);
rtn = rtn | (y << p);
}
return rtn;
}
#include "ir_decoder.h"

static void render_callback(Canvas* canvas, void* ctx) {
FURI_LOG_T(TAG, "Render callback");
Expand Down
16 changes: 16 additions & 0 deletions infrared/apps/ir_decoder/ir_decoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <furi.h>
#include <furi_hal.h>
#include <infrared.h>
#include <infrared_worker.h>
#include <furi_hal_infrared.h>
#include <gui/gui.h>

#include "helpers/bit_ops.h"

#define TAG "IR Decoder"

typedef struct {
InfraredMessage* decoded_signal;
FuriMutex* mutex;
ViewPort* view_port;
} IRDecoderState;

0 comments on commit 235bb2a

Please sign in to comment.