[FL-2912] Forced RAW receive option for Infrared CLI #1891
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									4942bd2105
								
							
						
					
					
						commit
						02c27becb0
					
				| @ -71,25 +71,9 @@ static void signal_received_callback(void* context, InfraredWorkerSignal* receiv | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args) { |  | ||||||
|     UNUSED(cli); |  | ||||||
|     UNUSED(args); |  | ||||||
|     InfraredWorker* worker = infrared_worker_alloc(); |  | ||||||
|     infrared_worker_rx_start(worker); |  | ||||||
|     infrared_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli); |  | ||||||
| 
 |  | ||||||
|     printf("Receiving INFRARED...\r\nPress Ctrl+C to abort\r\n"); |  | ||||||
|     while(!cli_cmd_interrupt_received(cli)) { |  | ||||||
|         furi_delay_ms(50); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     infrared_worker_rx_stop(worker); |  | ||||||
|     infrared_worker_free(worker); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static void infrared_cli_print_usage(void) { | static void infrared_cli_print_usage(void) { | ||||||
|     printf("Usage:\r\n"); |     printf("Usage:\r\n"); | ||||||
|     printf("\tir rx\r\n"); |     printf("\tir rx [raw]\r\n"); | ||||||
|     printf("\tir tx <protocol> <address> <command>\r\n"); |     printf("\tir tx <protocol> <address> <command>\r\n"); | ||||||
|     printf("\t<command> and <address> are hex-formatted\r\n"); |     printf("\t<command> and <address> are hex-formatted\r\n"); | ||||||
|     printf("\tAvailable protocols:"); |     printf("\tAvailable protocols:"); | ||||||
| @ -108,6 +92,35 @@ static void infrared_cli_print_usage(void) { | |||||||
|     printf("\tir universal list <tv, ac>\r\n"); |     printf("\tir universal list <tv, ac>\r\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static void infrared_cli_start_ir_rx(Cli* cli, FuriString* args) { | ||||||
|  |     UNUSED(cli); | ||||||
|  | 
 | ||||||
|  |     bool enable_decoding = true; | ||||||
|  | 
 | ||||||
|  |     if(!furi_string_empty(args)) { | ||||||
|  |         if(!furi_string_cmp_str(args, "raw")) { | ||||||
|  |             enable_decoding = false; | ||||||
|  |         } else { | ||||||
|  |             printf("Wrong arguments.\r\n"); | ||||||
|  |             infrared_cli_print_usage(); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     InfraredWorker* worker = infrared_worker_alloc(); | ||||||
|  |     infrared_worker_rx_enable_signal_decoding(worker, enable_decoding); | ||||||
|  |     infrared_worker_rx_start(worker); | ||||||
|  |     infrared_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli); | ||||||
|  | 
 | ||||||
|  |     printf("Receiving %s INFRARED...\r\nPress Ctrl+C to abort\r\n", enable_decoding ? "" : "RAW"); | ||||||
|  |     while(!cli_cmd_interrupt_received(cli)) { | ||||||
|  |         furi_delay_ms(50); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     infrared_worker_rx_stop(worker); | ||||||
|  |     infrared_worker_free(worker); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static bool infrared_cli_parse_message(const char* str, InfraredSignal* signal) { | static bool infrared_cli_parse_message(const char* str, InfraredSignal* signal) { | ||||||
|     char protocol_name[32]; |     char protocol_name[32]; | ||||||
|     InfraredMessage message; |     InfraredMessage message; | ||||||
|  | |||||||
| @ -57,6 +57,7 @@ struct InfraredWorker { | |||||||
|     InfraredDecoderHandler* infrared_decoder; |     InfraredDecoderHandler* infrared_decoder; | ||||||
|     NotificationApp* notification; |     NotificationApp* notification; | ||||||
|     bool blink_enable; |     bool blink_enable; | ||||||
|  |     bool decode_enable; | ||||||
| 
 | 
 | ||||||
|     union { |     union { | ||||||
|         struct { |         struct { | ||||||
| @ -131,7 +132,8 @@ static void infrared_worker_process_timeout(InfraredWorker* instance) { | |||||||
| static void | static void | ||||||
|     infrared_worker_process_timings(InfraredWorker* instance, uint32_t duration, bool level) { |     infrared_worker_process_timings(InfraredWorker* instance, uint32_t duration, bool level) { | ||||||
|     const InfraredMessage* message_decoded = |     const InfraredMessage* message_decoded = | ||||||
|         infrared_decode(instance->infrared_decoder, level, duration); |         instance->decode_enable ? infrared_decode(instance->infrared_decoder, level, duration) : | ||||||
|  |                                   NULL; | ||||||
|     if(message_decoded) { |     if(message_decoded) { | ||||||
|         instance->signal.message = *message_decoded; |         instance->signal.message = *message_decoded; | ||||||
|         instance->signal.timings_cnt = 0; |         instance->signal.timings_cnt = 0; | ||||||
| @ -233,6 +235,7 @@ InfraredWorker* infrared_worker_alloc() { | |||||||
|     instance->infrared_decoder = infrared_alloc_decoder(); |     instance->infrared_decoder = infrared_alloc_decoder(); | ||||||
|     instance->infrared_encoder = infrared_alloc_encoder(); |     instance->infrared_encoder = infrared_alloc_encoder(); | ||||||
|     instance->blink_enable = false; |     instance->blink_enable = false; | ||||||
|  |     instance->decode_enable = true; | ||||||
|     instance->notification = furi_record_open(RECORD_NOTIFICATION); |     instance->notification = furi_record_open(RECORD_NOTIFICATION); | ||||||
|     instance->state = InfraredWorkerStateIdle; |     instance->state = InfraredWorkerStateIdle; | ||||||
| 
 | 
 | ||||||
| @ -316,6 +319,11 @@ void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool | |||||||
|     instance->blink_enable = enable; |     instance->blink_enable = enable; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void infrared_worker_rx_enable_signal_decoding(InfraredWorker* instance, bool enable) { | ||||||
|  |     furi_assert(instance); | ||||||
|  |     instance->decode_enable = enable; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void infrared_worker_tx_start(InfraredWorker* instance) { | void infrared_worker_tx_start(InfraredWorker* instance) { | ||||||
|     furi_assert(instance); |     furi_assert(instance); | ||||||
|     furi_assert(instance->state == InfraredWorkerStateIdle); |     furi_assert(instance->state == InfraredWorkerStateIdle); | ||||||
|  | |||||||
| @ -76,6 +76,14 @@ void infrared_worker_rx_set_received_signal_callback( | |||||||
|  */ |  */ | ||||||
| void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool enable); | void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool enable); | ||||||
| 
 | 
 | ||||||
|  | /** Enable decoding of received infrared signals.
 | ||||||
|  |  * | ||||||
|  |  * @param[in]   instance - instance of InfraredWorker | ||||||
|  |  * @param[in]   enable - true if you want to enable decoding | ||||||
|  |  *                       false otherwise | ||||||
|  |  */ | ||||||
|  | void infrared_worker_rx_enable_signal_decoding(InfraredWorker* instance, bool enable); | ||||||
|  | 
 | ||||||
| /** Clarify is received signal either decoded or raw
 | /** Clarify is received signal either decoded or raw
 | ||||||
|  * |  * | ||||||
|  * @param[in]   signal - received signal |  * @param[in]   signal - received signal | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Georgii Surkov
						Georgii Surkov