Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
acegoal07 committed Feb 9, 2024
1 parent 3f42ba6 commit df60e6e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
8 changes: 4 additions & 4 deletions lib/led/nfc_playlist_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ NotificationMessage blink_message_normal = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightBlue | LightGreen,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100,
.data.led_blink.period = 100
};
const NotificationSequence blink_sequence_normal = {
&blink_message_normal,
&message_do_not_reset,
NULL,
NULL
};

NotificationMessage blink_message_error = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightRed,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100,
.data.led_blink.period = 100
};

const NotificationSequence blink_sequence_error = {
&blink_message_error,
&message_do_not_reset,
NULL,
NULL
};

void start_blink(NfcPlaylist* nfc_playlist, int state) {
Expand Down
89 changes: 44 additions & 45 deletions lib/worker/nfc_playlist_worker.c
Original file line number Diff line number Diff line change
@@ -1,80 +1,79 @@
#include "nfc_playlist_worker.h"

NfcPlaylistWorker* nfc_playlist_worker_alloc() {
NfcPlaylistWorker* nfc_playlist_worker = malloc(sizeof(NfcPlaylistWorker));
// Worker thread attributes
nfc_playlist_worker->thread = furi_thread_alloc_ex(
"NfcPlaylistWorker", 8192, nfc_playlist_worker_task, nfc_playlist_worker);
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped;
NfcPlaylistWorker* nfc_playlist_worker = malloc(sizeof(NfcPlaylistWorker));

nfc_playlist_worker->nfc = nfc_alloc();
nfc_playlist_worker->nfc_device = nfc_device_alloc();
nfc_playlist_worker->thread = furi_thread_alloc_ex("NfcPlaylistWorker", 8192, nfc_playlist_worker_task, nfc_playlist_worker);
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped;

return nfc_playlist_worker;
nfc_playlist_worker->nfc = nfc_alloc();
nfc_playlist_worker->nfc_device = nfc_device_alloc();

return nfc_playlist_worker;
}

void nfc_playlist_worker_free(NfcPlaylistWorker* nfc_playlist_worker) {
furi_assert(nfc_playlist_worker);
furi_thread_free(nfc_playlist_worker->thread);
furi_assert(nfc_playlist_worker);
furi_thread_free(nfc_playlist_worker->thread);

nfc_free(nfc_playlist_worker->nfc);
nfc_device_free(nfc_playlist_worker->nfc_device);
nfc_free(nfc_playlist_worker->nfc);
nfc_device_free(nfc_playlist_worker->nfc_device);

free(nfc_playlist_worker);
free(nfc_playlist_worker);
}

void nfc_playlist_worker_stop(NfcPlaylistWorker* nfc_playlist_worker) {
furi_assert(nfc_playlist_worker);
if(nfc_playlist_worker->state != NfcPlaylistWorkerState_Stopped) {
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped;
furi_thread_join(nfc_playlist_worker->thread);
}
furi_assert(nfc_playlist_worker);
if (nfc_playlist_worker->state != NfcPlaylistWorkerState_Stopped) {
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped;
furi_thread_join(nfc_playlist_worker->thread);
}
}

void nfc_playlist_worker_start(NfcPlaylistWorker* nfc_playlist_worker) {
furi_assert(nfc_playlist_worker);
nfc_playlist_worker->state = NfcPlaylistWorkerState_Emulating;
furi_thread_start(nfc_playlist_worker->thread);
furi_assert(nfc_playlist_worker);
nfc_playlist_worker->state = NfcPlaylistWorkerState_Emulating;
furi_thread_start(nfc_playlist_worker->thread);
}

int32_t nfc_playlist_worker_task(void* context) {
NfcPlaylistWorker* nfc_playlist_worker = context;
NfcPlaylistWorker* nfc_playlist_worker = context;

if(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) {
if (nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) {

nfc_playlist_worker->nfc_listener =
nfc_listener_alloc(nfc_playlist_worker->nfc,
nfc_playlist_worker->nfc_protocol,
nfc_device_get_data(nfc_playlist_worker->nfc_device, nfc_playlist_worker->nfc_protocol)
);
nfc_listener_start(nfc_playlist_worker->nfc_listener, NULL, NULL);
nfc_playlist_worker->nfc_listener =
nfc_listener_alloc(nfc_playlist_worker->nfc,
nfc_playlist_worker->nfc_protocol,
nfc_device_get_data(nfc_playlist_worker->nfc_device, nfc_playlist_worker->nfc_protocol)
);
nfc_listener_start(nfc_playlist_worker->nfc_listener, NULL, NULL);

while(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) {
furi_delay_ms(50);
}
while(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) {
furi_delay_ms(50);
}

nfc_listener_stop(nfc_playlist_worker->nfc_listener);
nfc_listener_free(nfc_playlist_worker->nfc_listener);
}
nfc_listener_stop(nfc_playlist_worker->nfc_listener);
nfc_listener_free(nfc_playlist_worker->nfc_listener);
}

nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped;
nfc_playlist_worker->state = NfcPlaylistWorkerState_Stopped;

return 0;
return 0;
}

bool nfc_playlist_worker_is_emulating(NfcPlaylistWorker* nfc_playlist_worker) {
if(nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) {
return true;
}
return false;
if (nfc_playlist_worker->state == NfcPlaylistWorkerState_Emulating) {
return true;
}
return false;
}

void nfc_playlist_worker_set_nfc_data(NfcPlaylistWorker* nfc_playlist_worker, char* file_path) {
nfc_device_clear(nfc_playlist_worker->nfc_device);
nfc_device_load(nfc_playlist_worker->nfc_device, file_path);
nfc_playlist_worker->nfc_protocol = nfc_device_get_protocol(nfc_playlist_worker->nfc_device);
nfc_device_clear(nfc_playlist_worker->nfc_device);
nfc_device_load(nfc_playlist_worker->nfc_device, file_path);
nfc_playlist_worker->nfc_protocol = nfc_device_get_protocol(nfc_playlist_worker->nfc_device);
}

NfcDeviceData* nfc_playlist_worker_get_nfc_data(NfcPlaylistWorker* nfc_playlist_worker) {
return nfc_playlist_worker->nfc_data;
return nfc_playlist_worker->nfc_data;
}

0 comments on commit df60e6e

Please sign in to comment.