From 3d3955414e34ce602f053f507660155b8427b9c3 Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Mon, 12 Dec 2022 13:51:12 -0500 Subject: [PATCH] IR Remote --- ReadMe.md | 1 + applications/plugins/ir_remote/README.md | 63 +++ .../plugins/ir_remote/application.fam | 14 + applications/plugins/ir_remote/example.txt | 12 + .../ir_remote/images/ButtonDown_7x4.png | Bin 0 -> 102 bytes .../ir_remote/images/ButtonLeft_4x7.png | Bin 0 -> 1415 bytes .../ir_remote/images/ButtonRight_4x7.png | Bin 0 -> 1839 bytes .../plugins/ir_remote/images/ButtonUp_7x4.png | Bin 0 -> 102 bytes .../plugins/ir_remote/images/Ok_btn_9x9.png | Bin 0 -> 3605 bytes .../plugins/ir_remote/images/back_10px.png | Bin 0 -> 154 bytes .../plugins/ir_remote/images/sub1_10px.png | Bin 0 -> 299 bytes .../plugins/ir_remote/infrared_remote.c | 188 +++++++ .../plugins/ir_remote/infrared_remote.h | 29 + .../plugins/ir_remote/infrared_remote_app.c | 499 ++++++++++++++++++ .../ir_remote/infrared_remote_button.c | 37 ++ .../ir_remote/infrared_remote_button.h | 14 + .../plugins/ir_remote/infrared_signal.c | 300 +++++++++++ .../plugins/ir_remote/infrared_signal.h | 45 ++ applications/plugins/ir_remote/ir.png | Bin 0 -> 1514 bytes applications/plugins/ir_remote/ir2.png | Bin 0 -> 3109 bytes applications/plugins/ir_remote/ir_10px.png | Bin 0 -> 305 bytes assets/resources/infrared/Roku.ir | 116 ++++ assets/resources/infrared/ir_remote/Roku.txt | 12 + 23 files changed, 1330 insertions(+) create mode 100644 applications/plugins/ir_remote/README.md create mode 100644 applications/plugins/ir_remote/application.fam create mode 100644 applications/plugins/ir_remote/example.txt create mode 100644 applications/plugins/ir_remote/images/ButtonDown_7x4.png create mode 100644 applications/plugins/ir_remote/images/ButtonLeft_4x7.png create mode 100644 applications/plugins/ir_remote/images/ButtonRight_4x7.png create mode 100644 applications/plugins/ir_remote/images/ButtonUp_7x4.png create mode 100644 applications/plugins/ir_remote/images/Ok_btn_9x9.png create mode 100644 applications/plugins/ir_remote/images/back_10px.png create mode 100644 applications/plugins/ir_remote/images/sub1_10px.png create mode 100644 applications/plugins/ir_remote/infrared_remote.c create mode 100644 applications/plugins/ir_remote/infrared_remote.h create mode 100644 applications/plugins/ir_remote/infrared_remote_app.c create mode 100644 applications/plugins/ir_remote/infrared_remote_button.c create mode 100644 applications/plugins/ir_remote/infrared_remote_button.h create mode 100644 applications/plugins/ir_remote/infrared_signal.c create mode 100644 applications/plugins/ir_remote/infrared_signal.h create mode 100644 applications/plugins/ir_remote/ir.png create mode 100644 applications/plugins/ir_remote/ir2.png create mode 100644 applications/plugins/ir_remote/ir_10px.png create mode 100644 assets/resources/infrared/Roku.ir create mode 100644 assets/resources/infrared/ir_remote/Roku.txt diff --git a/ReadMe.md b/ReadMe.md index 9aae945f7..3eac21459 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -23,6 +23,7 @@ Thank you to all the supporters! - Fixed snake scoring showing +7 - Added: [POCSAG (By Shmuma)](https://github.com/Shmuma/flipper-zero-pocsag) - Updated: [Intravelometer (By theageoflove)](https://github.com/theageoflove/flipperzero-zeitraffer) +- Added: [IR Remote (By Hong5489)](https://github.com/Hong5489/ir_remote) ## Install from Release FLASH STOCK FIRST BEFORE UPDATING TO CUSTOM FIRMWARE! diff --git a/applications/plugins/ir_remote/README.md b/applications/plugins/ir_remote/README.md new file mode 100644 index 000000000..4e490042a --- /dev/null +++ b/applications/plugins/ir_remote/README.md @@ -0,0 +1,63 @@ +# Alternative Infrared Remote for Flipperzero + +It is a plugin like [UniversalRF Remix](https://github.com/ESurge/flipperzero-firmware-unirfremix) but for infrared files. I do this plugin for convenience, because the main IR app need to navigate for different button abit troublesome (buttons like up,down,left,right,back). I found it useful for TV and TV box. + +It supports short press and long press input for different ir remote buttons. Tested on the [unleashed firmware version unlshd-015](https://github.com/DarkFlippers/unleashed-firmware/releases/tag/unlshd-015) + + +## How to install + +1. Update unleashed firmware to the version unlshd-015, then download the `ir_remote.fap` from [releases](https://github.com/Hong5489/ir_remote/tags) + +2. Put the `ir_remote.fap` file in your flipper's SD card, under `apps` folder + +## How to use + +1. Similar to UniRF app, put the path of the ir file and the ir button for each button on flipper (UP,DOWN,LEFT,RIGHT,BACK) + +The format With `HOLD` one is long press, without is short press + +Example of the configuration file: +``` +REMOTE: /ext/infrared/Philips_32PFL4208T.ir +UP: Up +DOWN: Down +LEFT: Left +RIGHT: Right +OK: +BACK: Back +UPHOLD: VOL+ +DOWNHOLD: VOL- +LEFTHOLD: Source +RIGHTHOLD: SmartTV +OKHOLD: POWER +``` + +Leave it empty for the button you don't need + +2. Save it as `.txt` file, then create a new folder in your SD card `ir_remote`, put it inside the folder + +3. Lastly, you can open the app, choose the configuration file, then you can try out the ir for each buttons + +4. Long press back button to exit the app + +## How to build + +You can clone this repo and put it inside the `applications_user` folder, then build it with the command: +``` +./fbt fap_ir_remote +``` +Or you can build and run it on your flipper with the command: +``` +./fbt launch_app APPSRC=applications_user/ir_remote +``` + +## Screenshots + +Choose config file to map + +![image](ir.png) + +Show all button name in the config file (If empty will show N/A). Upper part short press, Lower part long press + +![image2](ir2.png) \ No newline at end of file diff --git a/applications/plugins/ir_remote/application.fam b/applications/plugins/ir_remote/application.fam new file mode 100644 index 000000000..e74ea9131 --- /dev/null +++ b/applications/plugins/ir_remote/application.fam @@ -0,0 +1,14 @@ +App( + appid="IR_Remote", + name="IR Remote", + apptype=FlipperAppType.EXTERNAL, + entry_point="infrared_remote_app", + stack_size=3 * 1024, + requires=[ + "gui", + "dialogs", + ], + fap_category="Tools", + fap_icon="ir_10px.png", + fap_icon_assets="images", +) diff --git a/applications/plugins/ir_remote/example.txt b/applications/plugins/ir_remote/example.txt new file mode 100644 index 000000000..ffd192b8d --- /dev/null +++ b/applications/plugins/ir_remote/example.txt @@ -0,0 +1,12 @@ +REMOTE: /ext/infrared/Philips_32PFL4208T.ir +UP: Up +DOWN: Down +LEFT: Left +RIGHT: Right +OK: +BACK: Back +UPHOLD: VOL+ +DOWNHOLD: VOL- +LEFTHOLD: Source +RIGHTHOLD: SmartTV +OKHOLD: POWER \ No newline at end of file diff --git a/applications/plugins/ir_remote/images/ButtonDown_7x4.png b/applications/plugins/ir_remote/images/ButtonDown_7x4.png new file mode 100644 index 0000000000000000000000000000000000000000..2954bb6a67d1c23c0bb5d765e8d2aa04b9b5adec GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)I!3HFqj;YoHDIHH2#}J9|(o>FH3<^BV2haYO z-y5_sM4;GPjq%Ck6>60csmUj6EiNa>ORduPH4*)h!w|e3sE@(Z)z4*}Q$iC10Gods AV*mgE literal 0 HcmV?d00001 diff --git a/applications/plugins/ir_remote/images/ButtonLeft_4x7.png b/applications/plugins/ir_remote/images/ButtonLeft_4x7.png new file mode 100644 index 0000000000000000000000000000000000000000..0b4655d43247083aa705620e9836ac415b42ca46 GIT binary patch literal 1415 zcmbVM+iKK67*5rq)>aU2M7$VM1Vxif;vTv~W2u`S7ED{V3s&&L*<`XiG|9wd+THd> z5CnY!sdyuJtrvQyAo>KpiLcV|{Tkc)riAbluXfwSZCApL`ztB&p zx6LGKvks4K_4~)qD&oGa-YdJlW)hAKMNJd7<=t?6c^RI1>c$ifyjaM>^|&8!ey zB4!nh9u>5uen6Ve@<H5rru6h<2Ef#GQdQ*CmZOlQi~N!?9H`Rp;C% zU}CB21#?;r`&0|6C0}b-=jODa5|nEJ#ntxQ&{~jpgtwDta4hftr~G=#p@V36e4Zjh zq%J~{y26Jjn=1Nw-l*3%QW5YFE*v4z3gt0$&(*xf2en34c?JpH8+FYldo+Alvg8af-pG4(=!fyUi-Wsg z`g#n9VUcf(DFr{poMSNzw-lz>w+HV+n1ELr&SLA#LHUb0p(xWQ(1*vJ-i+1!`swxZ Z!O7;c$;lT_->m1Ovaz)0yuI`A$q$F8u*d)a literal 0 HcmV?d00001 diff --git a/applications/plugins/ir_remote/images/ButtonRight_4x7.png b/applications/plugins/ir_remote/images/ButtonRight_4x7.png new file mode 100644 index 0000000000000000000000000000000000000000..8e1c74c1c0038ea55172f19ac875003fc80c2d06 GIT binary patch literal 1839 zcmcIlO>f*p7#Yw)M6zw!O+@VZ{?d|D~WYi~8rHRY?X-&T}Yen`g$^+EJ;z+|RV zE@PoDvZ9%#+_}3bC_5Cj8jDGq541mi{7F+&KF}W65sr$Xn5H|YrMQ2(J7%Yc%;(zO z57ax000=TsQ+1Ke@+w#iw3au3cGGQWY740k2ijH>P(6tD)S)be>gX6Tj7`<`b>di- zgWp$8Y+?i31~CzF0&E4uRlA=C(Mp~K`{74jEchB|)4DDK!ZVhSwdFyw0YIZ1cDh0S{OvfO-U_~ zvmRF*m9sWDXNH)GOyqS1Skhxbr6}s*7t&@~kFM(NW5}qh?Lu@lJ}HE;FDiLdGO>LO z5pS*%E2grR)l^;|?O5b_?u0me&c1U}%jrk8*%=Wk%i)8yp2P|kuxmKg<=(u_`oQRI_0 zS`-DNysBx=#3&qSkgA@hJP>~D+ZM(s5jI6Owp`?yE=3e`YGUqkVOp#Cp=3wR3O4hX zX6BLsN3UBzV(vI5;|SZHgOb=HD0VFjpTyfFW}GnQuh>2*Q`k>*cAmA#iUT7EXSpo# zkPm5~#I-o^cpgfe#P$=4-Pi*SpT!-@nJgp8L347xe>5EKl`=_ZFc8XGy+_j=_R_7! z@vZZMowS1GJ?Zw)eetks%~G{BTR>T}9|jt0j3Btyb*C3-`C?fwY3EY`q*oYZ39DpM z&uJ;PCZPLs4QO1Jd_|A1PF)azZJ)RZ`^-VMWr6e#XUOA%3eLG_Ch@BDOHzMk*MF0G zCo7xMd?Mg*HMIXw%nNz?%60fZiZPlqb?GqUpXO`F&Yi!okZl(n>P@r1P2i)yk3DgRwbHeNn6e|;J^SK4TM LH~i+q&mR8;k>NTA literal 0 HcmV?d00001 diff --git a/applications/plugins/ir_remote/images/ButtonUp_7x4.png b/applications/plugins/ir_remote/images/ButtonUp_7x4.png new file mode 100644 index 0000000000000000000000000000000000000000..1be79328b40a93297a5609756328406565c437c0 GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)I!3HFqj;YoHDIHH2#}J8d-yTOk1_O>mFaFD) zeWb+ZHz{mGZZ1QpXe09^4tcYT#4oe=UbmGC^A-KE*|F&zP#=S*tDnm{r-UX30HgpM AM*si- literal 0 HcmV?d00001 diff --git a/applications/plugins/ir_remote/images/Ok_btn_9x9.png b/applications/plugins/ir_remote/images/Ok_btn_9x9.png new file mode 100644 index 0000000000000000000000000000000000000000..9a1539da2049f12f7b25f96b11a9c40cd8227302 GIT binary patch literal 3605 zcmaJ@c{r5q+kR|?vSeS9G2*Q(Gqz$f_GQ#q8r!JE7=ytqjlqnNNGaK}Wlbolp-q`& zs|bxHiiEP0&{#s&zVZIv-rx7f*Y_O9^W67+-RF5;*L_{ra~$^-2RmyaK{-JH0EBE1 z7AVdru>JD$aK0bym%#uaXpT2Gcd#)x2azcxAABGV0BC)Aj-lw(6)B^^6`Y8RS?}DV z%)ko(See1!Eb3M$dL6)A6csaRjExg?k&xVzi*Rm;?iNJk#f=mkVEUR~jXN3dd|Lmz z;y}sMh%ol-?E1&`>dD;6jdps6NYoxN)s%@sf4~40YY6LAOtMEbwA4g#OCpANL823^ zSH66W05Hcxr$tg98gFntAOYL}xm$C;Skv&Ym?{TVR{)d(41vWacX1`7fM!jnW(lBK z26*WB#9I(Z1Ast!xEUC@Cj`v=urcBTdP`FWq=DYTy`}s>0vC{VzHdNRvxNFy}ir1|g=xDsrFP&l1P<-Sv zXLqYVYz{b^ZIV@1Ulg->7DEgvM*Min&Y8{8QW! z$_pA434?^wCTq$4%^>Zo8&|8XwbCv;KEd;WJJ{s;T}8R8Zwi7ssk$QWQ5l5+opKfX z;8D*COFEB#4W^*FIrRU%PDSc?B(}+9ZV?N9(yH>0uSnM?xg!>+>;e z{{7tXQQ|ZFXD*7q3XD!pwnih-=66+Qlqtl9;N-D|PHoI&B5d8>^V#i{mE>V0gQgu3+(DG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o(LvDUbW?CgwgE3G~h=Hk +#include +#include +#include +#include +#include +#include + +#define TAG "InfraredRemote" + +ARRAY_DEF(InfraredButtonArray, InfraredRemoteButton*, M_PTR_OPLIST); + +struct InfraredRemote { + InfraredButtonArray_t buttons; + FuriString* name; + FuriString* path; +}; + +static void infrared_remote_clear_buttons(InfraredRemote* remote) { + InfraredButtonArray_it_t it; + for(InfraredButtonArray_it(it, remote->buttons); !InfraredButtonArray_end_p(it); + InfraredButtonArray_next(it)) { + infrared_remote_button_free(*InfraredButtonArray_cref(it)); + } + InfraredButtonArray_reset(remote->buttons); +} + +InfraredRemote* infrared_remote_alloc() { + InfraredRemote* remote = malloc(sizeof(InfraredRemote)); + InfraredButtonArray_init(remote->buttons); + remote->name = furi_string_alloc(); + remote->path = furi_string_alloc(); + return remote; +} + +void infrared_remote_free(InfraredRemote* remote) { + infrared_remote_clear_buttons(remote); + InfraredButtonArray_clear(remote->buttons); + furi_string_free(remote->path); + furi_string_free(remote->name); + free(remote); +} + +void infrared_remote_reset(InfraredRemote* remote) { + infrared_remote_clear_buttons(remote); + furi_string_reset(remote->name); + furi_string_reset(remote->path); +} + +void infrared_remote_set_name(InfraredRemote* remote, const char* name) { + furi_string_set(remote->name, name); +} + +const char* infrared_remote_get_name(InfraredRemote* remote) { + return furi_string_get_cstr(remote->name); +} + +void infrared_remote_set_path(InfraredRemote* remote, const char* path) { + furi_string_set(remote->path, path); +} + +const char* infrared_remote_get_path(InfraredRemote* remote) { + return furi_string_get_cstr(remote->path); +} + +size_t infrared_remote_get_button_count(InfraredRemote* remote) { + return InfraredButtonArray_size(remote->buttons); +} + +InfraredRemoteButton* infrared_remote_get_button(InfraredRemote* remote, size_t index) { + furi_assert(index < InfraredButtonArray_size(remote->buttons)); + return *InfraredButtonArray_get(remote->buttons, index); +} + +bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index) { + for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) { + InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i); + if(!strcmp(infrared_remote_button_get_name(button), name)) { + *index = i; + return true; + } + } + return false; +} + +bool infrared_remote_add_button(InfraredRemote* remote, const char* name, InfraredSignal* signal) { + InfraredRemoteButton* button = infrared_remote_button_alloc(); + infrared_remote_button_set_name(button, name); + infrared_remote_button_set_signal(button, signal); + InfraredButtonArray_push_back(remote->buttons, button); + return infrared_remote_store(remote); +} + +bool infrared_remote_rename_button(InfraredRemote* remote, const char* new_name, size_t index) { + furi_assert(index < InfraredButtonArray_size(remote->buttons)); + InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, index); + infrared_remote_button_set_name(button, new_name); + return infrared_remote_store(remote); +} + +bool infrared_remote_delete_button(InfraredRemote* remote, size_t index) { + furi_assert(index < InfraredButtonArray_size(remote->buttons)); + InfraredRemoteButton* button; + InfraredButtonArray_pop_at(&button, remote->buttons, index); + infrared_remote_button_free(button); + return infrared_remote_store(remote); +} + +bool infrared_remote_store(InfraredRemote* remote) { + Storage* storage = furi_record_open(RECORD_STORAGE); + FlipperFormat* ff = flipper_format_file_alloc(storage); + const char* path = furi_string_get_cstr(remote->path); + + FURI_LOG_I(TAG, "store file: \'%s\'", path); + + bool success = flipper_format_file_open_always(ff, path) && + flipper_format_write_header_cstr(ff, "IR signals file", 1); + if(success) { + InfraredButtonArray_it_t it; + for(InfraredButtonArray_it(it, remote->buttons); !InfraredButtonArray_end_p(it); + InfraredButtonArray_next(it)) { + InfraredRemoteButton* button = *InfraredButtonArray_cref(it); + success = infrared_signal_save( + infrared_remote_button_get_signal(button), + ff, + infrared_remote_button_get_name(button)); + if(!success) { + break; + } + } + } + + flipper_format_free(ff); + furi_record_close(RECORD_STORAGE); + return success; +} + +bool infrared_remote_load(InfraredRemote* remote, FuriString* path) { + Storage* storage = furi_record_open(RECORD_STORAGE); + FlipperFormat* ff = flipper_format_buffered_file_alloc(storage); + + FuriString* buf; + buf = furi_string_alloc(); + + FURI_LOG_I(TAG, "load file: \'%s\'", furi_string_get_cstr(path)); + bool success = flipper_format_buffered_file_open_existing(ff, furi_string_get_cstr(path)); + + if(success) { + uint32_t version; + success = flipper_format_read_header(ff, buf, &version) && + !furi_string_cmp(buf, "IR signals file") && (version == 1); + } + + if(success) { + path_extract_filename(path, buf, true); + infrared_remote_clear_buttons(remote); + infrared_remote_set_name(remote, furi_string_get_cstr(buf)); + infrared_remote_set_path(remote, furi_string_get_cstr(path)); + + for(bool can_read = true; can_read;) { + InfraredRemoteButton* button = infrared_remote_button_alloc(); + can_read = infrared_signal_read(infrared_remote_button_get_signal(button), ff, buf); + if(can_read) { + infrared_remote_button_set_name(button, furi_string_get_cstr(buf)); + InfraredButtonArray_push_back(remote->buttons, button); + } else { + infrared_remote_button_free(button); + } + } + } + + furi_string_free(buf); + flipper_format_free(ff); + furi_record_close(RECORD_STORAGE); + return success; +} + +bool infrared_remote_remove(InfraredRemote* remote) { + Storage* storage = furi_record_open(RECORD_STORAGE); + + FS_Error status = storage_common_remove(storage, furi_string_get_cstr(remote->path)); + infrared_remote_reset(remote); + + furi_record_close(RECORD_STORAGE); + return (status == FSE_OK || status == FSE_NOT_EXIST); +} diff --git a/applications/plugins/ir_remote/infrared_remote.h b/applications/plugins/ir_remote/infrared_remote.h new file mode 100644 index 000000000..6eac193d3 --- /dev/null +++ b/applications/plugins/ir_remote/infrared_remote.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "infrared_remote_button.h" + +typedef struct InfraredRemote InfraredRemote; + +InfraredRemote* infrared_remote_alloc(); +void infrared_remote_free(InfraredRemote* remote); +void infrared_remote_reset(InfraredRemote* remote); + +void infrared_remote_set_name(InfraredRemote* remote, const char* name); +const char* infrared_remote_get_name(InfraredRemote* remote); + +void infrared_remote_set_path(InfraredRemote* remote, const char* path); +const char* infrared_remote_get_path(InfraredRemote* remote); + +size_t infrared_remote_get_button_count(InfraredRemote* remote); +InfraredRemoteButton* infrared_remote_get_button(InfraredRemote* remote, size_t index); +bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index); + +bool infrared_remote_add_button(InfraredRemote* remote, const char* name, InfraredSignal* signal); +bool infrared_remote_rename_button(InfraredRemote* remote, const char* new_name, size_t index); +bool infrared_remote_delete_button(InfraredRemote* remote, size_t index); + +bool infrared_remote_store(InfraredRemote* remote); +bool infrared_remote_load(InfraredRemote* remote, FuriString* path); +bool infrared_remote_remove(InfraredRemote* remote); diff --git a/applications/plugins/ir_remote/infrared_remote_app.c b/applications/plugins/ir_remote/infrared_remote_app.c new file mode 100644 index 000000000..05c13ee59 --- /dev/null +++ b/applications/plugins/ir_remote/infrared_remote_app.c @@ -0,0 +1,499 @@ +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "infrared_signal.h" +#include "infrared_remote.h" +#include "infrared_remote_button.h" +#define TAG "IR_Remote" + +#include + +typedef struct { + int status; + ViewPort* view_port; + FuriString* up_button; + FuriString* down_button; + FuriString* left_button; + FuriString* right_button; + FuriString* ok_button; + FuriString* back_button; + FuriString* up_hold_button; + FuriString* down_hold_button; + FuriString* left_hold_button; + FuriString* right_hold_button; + FuriString* ok_hold_button; +}IRApp; + +// Screen is 128x64 px +static void app_draw_callback(Canvas* canvas, void* ctx) { + // Show config is incorrect when cannot read the remote file + // Showing button string in the screen, upper part is short press, lower part is long press + IRApp* app = ctx; + if(app->status){ + canvas_clear(canvas); + view_port_set_orientation(app->view_port, ViewPortOrientationHorizontal); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Config is incorrect."); + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "Please configure map."); + canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit."); + }else{ + canvas_clear(canvas); + view_port_set_orientation(app->view_port, ViewPortOrientationVertical); + canvas_draw_icon(canvas, 1, 5, &I_ButtonUp_7x4); + canvas_draw_icon(canvas, 1, 15, &I_ButtonDown_7x4); + canvas_draw_icon(canvas, 2, 23, &I_ButtonLeft_4x7); + canvas_draw_icon(canvas, 2, 33, &I_ButtonRight_4x7); + canvas_draw_icon(canvas, 0, 42, &I_Ok_btn_9x9); + canvas_draw_icon(canvas, 0, 53, &I_back_10px); + + //Labels + canvas_set_font(canvas, FontSecondary); + + canvas_draw_str_aligned(canvas, 32, 8,AlignCenter,AlignCenter, furi_string_get_cstr(app->up_button)); + canvas_draw_str_aligned(canvas, 32, 18,AlignCenter,AlignCenter, furi_string_get_cstr(app->down_button)); + canvas_draw_str_aligned(canvas, 32, 28,AlignCenter,AlignCenter, furi_string_get_cstr(app->left_button)); + canvas_draw_str_aligned(canvas, 32, 38,AlignCenter,AlignCenter, furi_string_get_cstr(app->right_button)); + canvas_draw_str_aligned(canvas, 32, 48,AlignCenter,AlignCenter, furi_string_get_cstr(app->ok_button)); + canvas_draw_str_aligned(canvas, 32, 58, AlignCenter, AlignCenter, furi_string_get_cstr(app->back_button)); + + canvas_draw_line(canvas, 0, 65, 64, 65); + + canvas_draw_icon(canvas, 1, 70, &I_ButtonUp_7x4); + canvas_draw_icon(canvas, 1, 80, &I_ButtonDown_7x4); + canvas_draw_icon(canvas, 2, 88, &I_ButtonLeft_4x7); + canvas_draw_icon(canvas, 2, 98, &I_ButtonRight_4x7); + canvas_draw_icon(canvas, 0, 107, &I_Ok_btn_9x9); + canvas_draw_icon(canvas, 0, 118, &I_back_10px); + + canvas_draw_str_aligned(canvas, 32, 73,AlignCenter,AlignCenter, furi_string_get_cstr(app->up_hold_button)); + canvas_draw_str_aligned(canvas, 32, 83,AlignCenter,AlignCenter, furi_string_get_cstr(app->down_hold_button)); + canvas_draw_str_aligned(canvas, 32, 93,AlignCenter,AlignCenter, furi_string_get_cstr(app->left_hold_button)); + canvas_draw_str_aligned(canvas, 32, 103,AlignCenter,AlignCenter, furi_string_get_cstr(app->right_hold_button)); + canvas_draw_str_aligned(canvas, 32, 113,AlignCenter,AlignCenter, furi_string_get_cstr(app->ok_hold_button)); + canvas_draw_str_aligned(canvas, 32, 123, AlignCenter, AlignCenter, "Exit App"); + } + + +} + +static void app_input_callback(InputEvent* input_event, void* ctx) { + furi_assert(ctx); + + FuriMessageQueue* event_queue = ctx; + furi_message_queue_put(event_queue, input_event, FuriWaitForever); +} + +int32_t infrared_remote_app(void* p) { + UNUSED(p); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); + + // App button string + IRApp* app = malloc(sizeof(IRApp)); + app->up_button = furi_string_alloc(); + app->down_button = furi_string_alloc(); + app->left_button = furi_string_alloc(); + app->right_button = furi_string_alloc(); + app->ok_button = furi_string_alloc(); + app->back_button = furi_string_alloc(); + app->up_hold_button = furi_string_alloc(); + app->down_hold_button = furi_string_alloc(); + app->left_hold_button = furi_string_alloc(); + app->right_hold_button = furi_string_alloc(); + app->ok_hold_button = furi_string_alloc(); + app->view_port = view_port_alloc(); + + // Configure view port + view_port_draw_callback_set(app->view_port, app_draw_callback, app); + view_port_input_callback_set(app->view_port, app_input_callback, event_queue); + + // Register view port in GUI + Gui* gui = furi_record_open(RECORD_GUI); + gui_add_view_port(gui, app->view_port, GuiLayerFullscreen); + + InputEvent event; + + Storage* storage = furi_record_open(RECORD_STORAGE); + FlipperFormat* ff = flipper_format_file_alloc(storage); + + DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); + DialogsFileBrowserOptions browser_options; + dialog_file_browser_set_basic_options(&browser_options, ".txt", &I_sub1_10px); + FuriString* map_file = furi_string_alloc(); + furi_string_set(map_file,"/ext/infrared/ir_remote"); + + bool res = dialog_file_browser_show(dialogs, map_file, map_file, &browser_options); + + furi_record_close(RECORD_DIALOGS); + + // if user didn't choose anything, free everything and exit + if(!res){ + FURI_LOG_I(TAG, "exit"); + flipper_format_free(ff); + furi_record_close(RECORD_STORAGE); + + furi_string_free(app->up_button); + furi_string_free(app->down_button); + furi_string_free(app->left_button); + furi_string_free(app->right_button); + furi_string_free(app->ok_button); + furi_string_free(app->back_button); + furi_string_free(app->up_hold_button); + furi_string_free(app->down_hold_button); + furi_string_free(app->left_hold_button); + furi_string_free(app->right_hold_button); + furi_string_free(app->ok_hold_button); + + view_port_enabled_set(app->view_port, false); + gui_remove_view_port(gui, app->view_port); + view_port_free(app->view_port); + free(app); + furi_message_queue_free(event_queue); + + furi_record_close(RECORD_GUI); + return 255; + } + + + InfraredRemote* remote = infrared_remote_alloc(); + FuriString* remote_path = furi_string_alloc(); + + InfraredSignal* up_signal = infrared_signal_alloc(); + InfraredSignal* down_signal = infrared_signal_alloc(); + InfraredSignal* left_signal = infrared_signal_alloc(); + InfraredSignal* right_signal = infrared_signal_alloc(); + InfraredSignal* ok_signal = infrared_signal_alloc(); + InfraredSignal* back_signal = infrared_signal_alloc(); + InfraredSignal* up_hold_signal = infrared_signal_alloc(); + InfraredSignal* down_hold_signal = infrared_signal_alloc(); + InfraredSignal* left_hold_signal = infrared_signal_alloc(); + InfraredSignal* right_hold_signal = infrared_signal_alloc(); + InfraredSignal* ok_hold_signal = infrared_signal_alloc(); + + bool up_enabled = false; + bool down_enabled = false; + bool left_enabled = false; + bool right_enabled = false; + bool ok_enabled = false; + bool back_enabled = false; + bool up_hold_enabled = false; + bool down_hold_enabled = false; + bool left_hold_enabled = false; + bool right_hold_enabled = false; + bool ok_hold_enabled = false; + + if(!flipper_format_file_open_existing(ff, furi_string_get_cstr(map_file))) { + FURI_LOG_E(TAG, "Could not open MAP file %s",furi_string_get_cstr(map_file)); + app->status = 1; + } else { + //Filename Assignment/Check Start + + if(!flipper_format_read_string(ff, "REMOTE", remote_path)) { + FURI_LOG_E(TAG, "Could not read REMOTE string"); + app->status = 1; + } else { + if(!infrared_remote_load(remote, remote_path)){ + FURI_LOG_E(TAG, "Could not load ir file: %s",furi_string_get_cstr(remote_path)); + app->status = 1; + }else{ + FURI_LOG_I(TAG, "Loaded REMOTE file: %s", furi_string_get_cstr(remote_path)); + } + } + + + //assign variables to values within map file + //set missing filenames to N/A + //assign button signals + size_t index = 0; + if(!flipper_format_read_string(ff, "UP", app->up_button)) { + FURI_LOG_W(TAG, "Could not read UP string"); + furi_string_set(app->up_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->up_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + up_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + up_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "DOWN", app->down_button)) { + FURI_LOG_W(TAG, "Could not read DOWN string"); + furi_string_set(app->down_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->down_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + down_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + down_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "LEFT", app->left_button)) { + FURI_LOG_W(TAG, "Could not read LEFT string"); + furi_string_set(app->left_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->left_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + left_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + left_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "RIGHT", app->right_button)) { + FURI_LOG_W(TAG, "Could not read RIGHT string"); + furi_string_set(app->right_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->right_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + right_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + right_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "OK", app->ok_button)) { + FURI_LOG_W(TAG, "Could not read OK string"); + furi_string_set(app->ok_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->ok_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + ok_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + ok_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "BACK", app->back_button)) { + FURI_LOG_W(TAG, "Could not read BACK string"); + furi_string_set(app->back_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->back_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + back_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + back_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "UPHOLD", app->up_hold_button)) { + FURI_LOG_W(TAG, "Could not read UPHOLD string"); + furi_string_set(app->up_hold_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->up_hold_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + up_hold_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + up_hold_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "DOWNHOLD", app->down_hold_button)) { + FURI_LOG_W(TAG, "Could not read DOWNHOLD string"); + furi_string_set(app->down_hold_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->down_hold_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + down_hold_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + down_hold_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "LEFTHOLD", app->left_hold_button)) { + FURI_LOG_W(TAG, "Could not read LEFTHOLD string"); + furi_string_set(app->left_hold_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->left_hold_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + left_hold_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + left_hold_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "RIGHTHOLD", app->right_hold_button)) { + FURI_LOG_W(TAG, "Could not read RIGHTHOLD string"); + furi_string_set(app->right_hold_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->right_hold_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + right_hold_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + right_hold_enabled = true; + } + } + + if(!flipper_format_read_string(ff, "OKHOLD", app->ok_hold_button)) { + FURI_LOG_W(TAG, "Could not read OKHOLD string"); + furi_string_set(app->ok_hold_button,"N/A"); + } else { + if(!infrared_remote_find_button_by_name(remote,furi_string_get_cstr(app->ok_hold_button),&index)){ + FURI_LOG_W(TAG,"Error"); + }else{ + ok_hold_signal = infrared_remote_button_get_signal(infrared_remote_get_button(remote, index)); + ok_hold_enabled = true; + } + } + + } + + furi_string_free(remote_path); + + flipper_format_free(ff); + furi_record_close(RECORD_STORAGE); + + bool running = true; + NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); + + if(app->status){ + view_port_update(app->view_port); + while(running) { + if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) { + if(event.type == InputTypeShort) { + switch(event.key) { + case InputKeyBack: + running = false; + break; + default: + break; + } + } + } + } + }else{ + view_port_update(app->view_port); + while(running) { + if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) { + // short press signal + if(event.type == InputTypeShort) { + switch(event.key) { + case InputKeyUp: + if(up_enabled){ + infrared_signal_transmit(up_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "up"); + } + break; + case InputKeyDown: + if(down_enabled){ + infrared_signal_transmit(down_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "down"); + } + break; + case InputKeyRight: + if(right_enabled){ + infrared_signal_transmit(right_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "right"); + } + break; + case InputKeyLeft: + if(left_enabled){ + infrared_signal_transmit(left_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "left"); + } + break; + case InputKeyOk: + if(ok_enabled){ + infrared_signal_transmit(ok_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "ok"); + } + break; + case InputKeyBack: + if(back_enabled){ + infrared_signal_transmit(back_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "back"); + } + break; + default: + running = false; + break; + } + // long press signal + }else if (event.type == InputTypeLong){ + switch(event.key) { + case InputKeyUp: + if(up_hold_enabled){ + infrared_signal_transmit(up_hold_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "up!"); + } + break; + case InputKeyDown: + if(down_hold_enabled){ + infrared_signal_transmit(down_hold_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "down!"); + } + break; + case InputKeyRight: + if(right_hold_enabled){ + infrared_signal_transmit(right_hold_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "right!"); + } + break; + case InputKeyLeft: + if(left_hold_enabled){ + infrared_signal_transmit(left_hold_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "left!"); + } + break; + case InputKeyOk: + if(ok_hold_enabled){ + infrared_signal_transmit(ok_hold_signal); + notification_message(notification, &sequence_blink_start_magenta); + FURI_LOG_I(TAG, "ok!"); + } + break; + default: + running = false; + break; + } + }else if(event.type == InputTypeRelease){ + notification_message(notification, &sequence_blink_stop); + } + } + } + } + + // Free all things + furi_string_free(app->up_button); + furi_string_free(app->down_button); + furi_string_free(app->left_button); + furi_string_free(app->right_button); + furi_string_free(app->ok_button); + furi_string_free(app->back_button); + furi_string_free(app->up_hold_button); + furi_string_free(app->down_hold_button); + furi_string_free(app->left_hold_button); + furi_string_free(app->right_hold_button); + furi_string_free(app->ok_hold_button); + + infrared_remote_free(remote); + view_port_enabled_set(app->view_port, false); + gui_remove_view_port(gui, app->view_port); + view_port_free(app->view_port); + free(app); + furi_message_queue_free(event_queue); + + furi_record_close(RECORD_NOTIFICATION); + furi_record_close(RECORD_GUI); + + return 0; +} \ No newline at end of file diff --git a/applications/plugins/ir_remote/infrared_remote_button.c b/applications/plugins/ir_remote/infrared_remote_button.c new file mode 100644 index 000000000..1f6315ec5 --- /dev/null +++ b/applications/plugins/ir_remote/infrared_remote_button.c @@ -0,0 +1,37 @@ +#include "infrared_remote_button.h" + +#include + +struct InfraredRemoteButton { + FuriString* name; + InfraredSignal* signal; +}; + +InfraredRemoteButton* infrared_remote_button_alloc() { + InfraredRemoteButton* button = malloc(sizeof(InfraredRemoteButton)); + button->name = furi_string_alloc(); + button->signal = infrared_signal_alloc(); + return button; +} + +void infrared_remote_button_free(InfraredRemoteButton* button) { + furi_string_free(button->name); + infrared_signal_free(button->signal); + free(button); +} + +void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name) { + furi_string_set(button->name, name); +} + +const char* infrared_remote_button_get_name(InfraredRemoteButton* button) { + return furi_string_get_cstr(button->name); +} + +void infrared_remote_button_set_signal(InfraredRemoteButton* button, InfraredSignal* signal) { + infrared_signal_set_signal(button->signal, signal); +} + +InfraredSignal* infrared_remote_button_get_signal(InfraredRemoteButton* button) { + return button->signal; +} diff --git a/applications/plugins/ir_remote/infrared_remote_button.h b/applications/plugins/ir_remote/infrared_remote_button.h new file mode 100644 index 000000000..f25b759b5 --- /dev/null +++ b/applications/plugins/ir_remote/infrared_remote_button.h @@ -0,0 +1,14 @@ +#pragma once + +#include "infrared_signal.h" + +typedef struct InfraredRemoteButton InfraredRemoteButton; + +InfraredRemoteButton* infrared_remote_button_alloc(); +void infrared_remote_button_free(InfraredRemoteButton* button); + +void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name); +const char* infrared_remote_button_get_name(InfraredRemoteButton* button); + +void infrared_remote_button_set_signal(InfraredRemoteButton* button, InfraredSignal* signal); +InfraredSignal* infrared_remote_button_get_signal(InfraredRemoteButton* button); diff --git a/applications/plugins/ir_remote/infrared_signal.c b/applications/plugins/ir_remote/infrared_signal.c new file mode 100644 index 000000000..d4d66af06 --- /dev/null +++ b/applications/plugins/ir_remote/infrared_signal.c @@ -0,0 +1,300 @@ +#include "infrared_signal.h" + +#include +#include +#include +#include +#include + +#define TAG "InfraredSignal" + +struct InfraredSignal { + bool is_raw; + union { + InfraredMessage message; + InfraredRawSignal raw; + } payload; +}; + +static void infrared_signal_clear_timings(InfraredSignal* signal) { + if(signal->is_raw) { + free(signal->payload.raw.timings); + signal->payload.raw.timings_size = 0; + signal->payload.raw.timings = NULL; + } +} + +static bool infrared_signal_is_message_valid(InfraredMessage* message) { + if(!infrared_is_protocol_valid(message->protocol)) { + FURI_LOG_E(TAG, "Unknown protocol"); + return false; + } + + uint32_t address_length = infrared_get_protocol_address_length(message->protocol); + uint32_t address_mask = (1UL << address_length) - 1; + + if(message->address != (message->address & address_mask)) { + FURI_LOG_E( + TAG, + "Address is out of range (mask 0x%08lX): 0x%lX\r\n", + address_mask, + message->address); + return false; + } + + uint32_t command_length = infrared_get_protocol_command_length(message->protocol); + uint32_t command_mask = (1UL << command_length) - 1; + + if(message->command != (message->command & command_mask)) { + FURI_LOG_E( + TAG, + "Command is out of range (mask 0x%08lX): 0x%lX\r\n", + command_mask, + message->command); + return false; + } + + return true; +} + +static bool infrared_signal_is_raw_valid(InfraredRawSignal* raw) { + if((raw->frequency > INFRARED_MAX_FREQUENCY) || (raw->frequency < INFRARED_MIN_FREQUENCY)) { + FURI_LOG_E( + TAG, + "Frequency is out of range (%X - %X): %lX", + INFRARED_MIN_FREQUENCY, + INFRARED_MAX_FREQUENCY, + raw->frequency); + return false; + + } else if((raw->duty_cycle <= 0) || (raw->duty_cycle > 1)) { + FURI_LOG_E(TAG, "Duty cycle is out of range (0 - 1): %f", (double)raw->duty_cycle); + return false; + + } else if((raw->timings_size <= 0) || (raw->timings_size > MAX_TIMINGS_AMOUNT)) { + FURI_LOG_E( + TAG, + "Timings amount is out of range (0 - %X): %X", + MAX_TIMINGS_AMOUNT, + raw->timings_size); + return false; + } + + return true; +} + +static inline bool infrared_signal_save_message(InfraredMessage* message, FlipperFormat* ff) { + const char* protocol_name = infrared_get_protocol_name(message->protocol); + return flipper_format_write_string_cstr(ff, "type", "parsed") && + flipper_format_write_string_cstr(ff, "protocol", protocol_name) && + flipper_format_write_hex(ff, "address", (uint8_t*)&message->address, 4) && + flipper_format_write_hex(ff, "command", (uint8_t*)&message->command, 4); +} + +static inline bool infrared_signal_save_raw(InfraredRawSignal* raw, FlipperFormat* ff) { + furi_assert(raw->timings_size <= MAX_TIMINGS_AMOUNT); + return flipper_format_write_string_cstr(ff, "type", "raw") && + flipper_format_write_uint32(ff, "frequency", &raw->frequency, 1) && + flipper_format_write_float(ff, "duty_cycle", &raw->duty_cycle, 1) && + flipper_format_write_uint32(ff, "data", raw->timings, raw->timings_size); +} + +static inline bool infrared_signal_read_message(InfraredSignal* signal, FlipperFormat* ff) { + FuriString* buf; + buf = furi_string_alloc(); + bool success = false; + + do { + if(!flipper_format_read_string(ff, "protocol", buf)) break; + + InfraredMessage message; + message.protocol = infrared_get_protocol_by_name(furi_string_get_cstr(buf)); + + success = flipper_format_read_hex(ff, "address", (uint8_t*)&message.address, 4) && + flipper_format_read_hex(ff, "command", (uint8_t*)&message.command, 4) && + infrared_signal_is_message_valid(&message); + + if(!success) break; + + infrared_signal_set_message(signal, &message); + } while(0); + + furi_string_free(buf); + return success; +} + +static inline bool infrared_signal_read_raw(InfraredSignal* signal, FlipperFormat* ff) { + uint32_t timings_size, frequency; + float duty_cycle; + + bool success = flipper_format_read_uint32(ff, "frequency", &frequency, 1) && + flipper_format_read_float(ff, "duty_cycle", &duty_cycle, 1) && + flipper_format_get_value_count(ff, "data", &timings_size); + + if(!success || timings_size > MAX_TIMINGS_AMOUNT) { + return false; + } + + uint32_t* timings = malloc(sizeof(uint32_t) * timings_size); + success = flipper_format_read_uint32(ff, "data", timings, timings_size); + + if(success) { + infrared_signal_set_raw_signal(signal, timings, timings_size, frequency, duty_cycle); + } + + free(timings); + return success; +} + +static bool infrared_signal_read_body(InfraredSignal* signal, FlipperFormat* ff) { + FuriString* tmp = furi_string_alloc(); + + bool success = false; + + do { + if(!flipper_format_read_string(ff, "type", tmp)) break; + if(furi_string_equal(tmp, "raw")) { + success = infrared_signal_read_raw(signal, ff); + } else if(furi_string_equal(tmp, "parsed")) { + success = infrared_signal_read_message(signal, ff); + } else { + FURI_LOG_E(TAG, "Unknown signal type"); + } + } while(false); + + furi_string_free(tmp); + return success; +} + +InfraredSignal* infrared_signal_alloc() { + InfraredSignal* signal = malloc(sizeof(InfraredSignal)); + + signal->is_raw = false; + signal->payload.message.protocol = InfraredProtocolUnknown; + + return signal; +} + +void infrared_signal_free(InfraredSignal* signal) { + infrared_signal_clear_timings(signal); + free(signal); +} + +bool infrared_signal_is_raw(InfraredSignal* signal) { + return signal->is_raw; +} + +bool infrared_signal_is_valid(InfraredSignal* signal) { + return signal->is_raw ? infrared_signal_is_raw_valid(&signal->payload.raw) : + infrared_signal_is_message_valid(&signal->payload.message); +} + +void infrared_signal_set_signal(InfraredSignal* signal, const InfraredSignal* other) { + if(other->is_raw) { + const InfraredRawSignal* raw = &other->payload.raw; + infrared_signal_set_raw_signal( + signal, raw->timings, raw->timings_size, raw->frequency, raw->duty_cycle); + } else { + const InfraredMessage* message = &other->payload.message; + infrared_signal_set_message(signal, message); + } +} + +void infrared_signal_set_raw_signal( + InfraredSignal* signal, + const uint32_t* timings, + size_t timings_size, + uint32_t frequency, + float duty_cycle) { + infrared_signal_clear_timings(signal); + + signal->is_raw = true; + + signal->payload.raw.timings_size = timings_size; + signal->payload.raw.frequency = frequency; + signal->payload.raw.duty_cycle = duty_cycle; + + signal->payload.raw.timings = malloc(timings_size * sizeof(uint32_t)); + memcpy(signal->payload.raw.timings, timings, timings_size * sizeof(uint32_t)); +} + +InfraredRawSignal* infrared_signal_get_raw_signal(InfraredSignal* signal) { + furi_assert(signal->is_raw); + return &signal->payload.raw; +} + +void infrared_signal_set_message(InfraredSignal* signal, const InfraredMessage* message) { + infrared_signal_clear_timings(signal); + + signal->is_raw = false; + signal->payload.message = *message; +} + +InfraredMessage* infrared_signal_get_message(InfraredSignal* signal) { + furi_assert(!signal->is_raw); + return &signal->payload.message; +} + +bool infrared_signal_save(InfraredSignal* signal, FlipperFormat* ff, const char* name) { + if(!flipper_format_write_comment_cstr(ff, "") || + !flipper_format_write_string_cstr(ff, "name", name)) { + return false; + } else if(signal->is_raw) { + return infrared_signal_save_raw(&signal->payload.raw, ff); + } else { + return infrared_signal_save_message(&signal->payload.message, ff); + } +} + +bool infrared_signal_read(InfraredSignal* signal, FlipperFormat* ff, FuriString* name) { + FuriString* tmp = furi_string_alloc(); + + bool success = false; + + do { + if(!flipper_format_read_string(ff, "name", tmp)) break; + furi_string_set(name, tmp); + if(!infrared_signal_read_body(signal, ff)) break; + success = true; + } while(0); + + furi_string_free(tmp); + return success; +} + +bool infrared_signal_search_and_read( + InfraredSignal* signal, + FlipperFormat* ff, + const FuriString* name) { + bool success = false; + FuriString* tmp = furi_string_alloc(); + + do { + bool is_name_found = false; + while(flipper_format_read_string(ff, "name", tmp)) { + is_name_found = furi_string_equal(name, tmp); + if(is_name_found) break; + } + if(!is_name_found) break; + if(!infrared_signal_read_body(signal, ff)) break; + success = true; + } while(false); + + furi_string_free(tmp); + return success; +} + +void infrared_signal_transmit(InfraredSignal* signal) { + if(signal->is_raw) { + InfraredRawSignal* raw_signal = &signal->payload.raw; + infrared_send_raw_ext( + raw_signal->timings, + raw_signal->timings_size, + true, + raw_signal->frequency, + raw_signal->duty_cycle); + } else { + InfraredMessage* message = &signal->payload.message; + infrared_send(message, 1); + } +} diff --git a/applications/plugins/ir_remote/infrared_signal.h b/applications/plugins/ir_remote/infrared_signal.h new file mode 100644 index 000000000..637d859b0 --- /dev/null +++ b/applications/plugins/ir_remote/infrared_signal.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include + +#include +#include + +typedef struct InfraredSignal InfraredSignal; + +typedef struct { + size_t timings_size; + uint32_t* timings; + uint32_t frequency; + float duty_cycle; +} InfraredRawSignal; + +InfraredSignal* infrared_signal_alloc(); +void infrared_signal_free(InfraredSignal* signal); + +bool infrared_signal_is_raw(InfraredSignal* signal); +bool infrared_signal_is_valid(InfraredSignal* signal); + +void infrared_signal_set_signal(InfraredSignal* signal, const InfraredSignal* other); + +void infrared_signal_set_raw_signal( + InfraredSignal* signal, + const uint32_t* timings, + size_t timings_size, + uint32_t frequency, + float duty_cycle); +InfraredRawSignal* infrared_signal_get_raw_signal(InfraredSignal* signal); + +void infrared_signal_set_message(InfraredSignal* signal, const InfraredMessage* message); +InfraredMessage* infrared_signal_get_message(InfraredSignal* signal); + +bool infrared_signal_save(InfraredSignal* signal, FlipperFormat* ff, const char* name); +bool infrared_signal_read(InfraredSignal* signal, FlipperFormat* ff, FuriString* name); +bool infrared_signal_search_and_read( + InfraredSignal* signal, + FlipperFormat* ff, + const FuriString* name); + +void infrared_signal_transmit(InfraredSignal* signal); diff --git a/applications/plugins/ir_remote/ir.png b/applications/plugins/ir_remote/ir.png new file mode 100644 index 0000000000000000000000000000000000000000..71bb60fa34c08e9924578e1ebd75903082cae694 GIT binary patch literal 1514 zcmeAS@N?(olHy`uVBq!ia0y~yU;;8388|?c*QZDWAjMhW5n0T@AXEavjQ7&yD;OA9 z=Xkm}hE&XXdpB_1Wh)Vfz%B{C$H@Xc?|Ywj^4B#@P@R3u^Y-3r`aAb7^~m|TqfqYu z|3Cj&8|JMq-_OYKPLY8jkcmM+6%X|__X~S`{h#uuzZnuHU!0jAhEUu8IOoJ2`3IZ- zeyso3`<}T$nv=m{3Il_S?YSz&YEFjr=jA}Y2mqPx|CX`m+;odg@(drW-Y_yKFffDy z?cKVE-N5*}{6=|(0{vNi08OZyddB)6(@s+&4fBac^ z63PBob`6WKR(^a@$((kU;rk{gh7KWy1`S4rj;MRg5|Xz572ns?fBpV$M|on(*UHnz z*XMt&3%mREJ@*?VYfEp*9hmygDn8@*y#vPU?RPy}bN+~>--nxPAbtdSb=r4^u;=Gi zUtcq8=Fa|m&F{CJkN!KS@p?Lv+wU+(*dDJxKGViHto~a0?f<>!8SVN-A&~|QmMd3k z8LXe}Pe1#2{U5#muYUe3w|s3}c%G%kOdH~0pu1Nb@7w&T|4hgFhxb?$rXuu$;vE{Y zAd@n`GctULLvkH3BB1dBqL$6$-1B%%<@4*zcTOXPRE5}uGd=%KWxKsmW%whFWa-M^ z41Hng?~Z4mdCeHtjy_?&_JS=|yUky-|2T{A3X)%eK7aMF`XhrcQqDn5y}{?1E$rOCuldbZwnvTOGg7Fv zr8AyA^J4v;XQF#f|7Mwyh!mHl@&_)ylKE57D`|D$^#;^LWqIy*5a>DYrj4_#CYZhLeZ(H@uu5D(v-ODv95B5eNatJ7x(k`T*JyKq5 zCU^ij;~%zdxElHMm8IEwgZl0A3{%j9O6}j7>~-_@*MG@Me|P>*>>E!8Yb0}R&&|@G z9nZW+91-@Q+yKoKpfq;*9Ww)pQxGW&HJuG^-d`qO=PsMif$|f8g*StztDnm{r-UW| D?#1+} literal 0 HcmV?d00001 diff --git a/applications/plugins/ir_remote/ir2.png b/applications/plugins/ir_remote/ir2.png new file mode 100644 index 0000000000000000000000000000000000000000..133b1c8667675631cdc58cc9c635b39b1d1cc060 GIT binary patch literal 3109 zcma)8dr(tn7QX?NDid*aSR@OiJ50B`n-L!|OnC&bx&=!GtF94*1QCcdq97VVLLPRf zcD2+^x0C#1F#;XH#o;mZ(+?A6Swx~pIb?=h{R$)kf3 zU8R!Iv$wu~{XODuYK1s0W#Zo2+|9s$7B=^;C>~F6xr*(RDNEMrT}ADSwgdm2O4k{v z2bed>Rvl_tfFXY5h)Qdl$%YT4Qa)+G;%hN;&JRE|WBOnKl zdVb9-v=CtCQ?FtP@MocLlGdzJoD!=$$|%(UmvIvG9l+xC*9eRrG5yyjp%G3T3kyPR zlC63!!@JB?IadsBcRqkG*)io=!#c-f7vO6!8er`|jlI)j7b2D}m8pZ1_tM3FW*>XU z_bnUp1BYmpjjNuU49cw%t0KZjvF~lUx9h#;{OGnP5^E??t}#a)@~qj9GJ(|g-D3u| ze%13UO59L52#k3QyLZd%6KNLA423&b3;`P3WfGJPzIsEC*YrU^AL6ZFgJPA9-NJrm zYcsOw@>8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P!_ZDPdRbhiRYx2WswUlmGw# literal 0 HcmV?d00001 diff --git a/applications/plugins/ir_remote/ir_10px.png b/applications/plugins/ir_remote/ir_10px.png new file mode 100644 index 0000000000000000000000000000000000000000..22c986180a2bed76dbe4ff439df1cf9177533c32 GIT binary patch literal 305 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2xkYHHq`AGmsv7|ftIx;Y9?C1WI$O_~uBzpw; zGB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpafHrx4R1i<>&pI=m5)bWC*+s&X`qmbr;B3<$Ms~3f`-KX%+5*7 zhxan`%;z`w!#>%c-@wM^z<~n{3>VXQv+hhNs0FH5Epd$~Nl7e8wMs5Z1yT$~21bUu z2Bx}(CLxAKR>lTa#unNJ237_J>nn=CplHa=PsvQHglaGb>IpG01*)?$HiBr_e$xf$ PHwFezS3j3^P6