SubGhz: automatically select path based on frequency for static code emulation (#419)
This commit is contained in:
		
							parent
							
								
									239c174610
								
							
						
					
					
						commit
						1ae3bc1a2d
					
				| @ -6,6 +6,7 @@ | ||||
| #include "subghz_static.h" | ||||
| 
 | ||||
| #include <furi.h> | ||||
| #include <api-hal.h> | ||||
| #include <gui/gui.h> | ||||
| #include <gui/view_dispatcher.h> | ||||
| #include <gui/modules/submenu.h> | ||||
| @ -24,6 +25,20 @@ static const uint32_t subghz_frequencies[] = { | ||||
|     925000000, | ||||
| }; | ||||
| 
 | ||||
| static const ApiHalSubGhzPath subghz_frequencies_paths[] = { | ||||
|     ApiHalSubGhzPath2, | ||||
|     ApiHalSubGhzPath2, | ||||
|     ApiHalSubGhzPath2, | ||||
|     ApiHalSubGhzPath2, | ||||
|     ApiHalSubGhzPath1, | ||||
|     ApiHalSubGhzPath1, | ||||
|     ApiHalSubGhzPath1, | ||||
|     ApiHalSubGhzPath3, | ||||
|     ApiHalSubGhzPath3, | ||||
|     ApiHalSubGhzPath3, | ||||
|     ApiHalSubGhzPath3, | ||||
| }; | ||||
| 
 | ||||
| static const uint32_t subghz_frequencies_count = sizeof(subghz_frequencies) / sizeof(uint32_t); | ||||
| 
 | ||||
| struct SubGhz { | ||||
|  | ||||
| @ -22,6 +22,7 @@ typedef enum { | ||||
| } SubghzStaticStatus; | ||||
| 
 | ||||
| typedef struct { | ||||
|     uint8_t frequency; | ||||
|     uint32_t real_frequency; | ||||
|     ApiHalSubGhzPath path; | ||||
|     uint8_t button; | ||||
| @ -71,18 +72,28 @@ bool subghz_static_input(InputEvent* event, void* context) { | ||||
| 
 | ||||
|     with_view_model( | ||||
|         subghz_static->view, (SubghzStaticModel * model) { | ||||
|             bool reconfigure = false; | ||||
|             if(event->type == InputTypeShort) { | ||||
|                 if(event->key == InputKeyLeft) { | ||||
|                     if(model->button > 0) model->button--; | ||||
|                     if(model->frequency > 0) model->frequency--; | ||||
|                     reconfigure = true; | ||||
|                 } else if(event->key == InputKeyRight) { | ||||
|                     if(model->button < 2) model->button++; | ||||
| 
 | ||||
|                     if(model->frequency < subghz_frequencies_count - 1) model->frequency++; | ||||
|                     reconfigure = true; | ||||
|                 } else if(event->key == InputKeyDown) { | ||||
|                     if(model->path > 0) model->path--; | ||||
|                     if(model->button > 0) model->button--; | ||||
|                 } else if(event->key == InputKeyUp) { | ||||
|                     if(model->path < ApiHalSubGhzPath3) model->path++; | ||||
|                     if(model->button < 2) model->button++; | ||||
|                 } | ||||
|                 model->path = subghz_frequencies_paths[model->frequency]; | ||||
|             } | ||||
| 
 | ||||
|             if(reconfigure) { | ||||
|                 api_hal_subghz_idle(); | ||||
|                 model->real_frequency = | ||||
|                     api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]); | ||||
|                 api_hal_subghz_set_path(model->path); | ||||
|                 api_hal_subghz_tx(); | ||||
|             } | ||||
| 
 | ||||
|             if(event->key == InputKeyOk) { | ||||
| @ -138,9 +149,12 @@ void subghz_static_enter(void* context) { | ||||
| 
 | ||||
|     with_view_model( | ||||
|         subghz_static->view, (SubghzStaticModel * model) { | ||||
|             model->real_frequency = api_hal_subghz_set_frequency(433920000); | ||||
|             model->path = ApiHalSubGhzPathIsolate; // isolate
 | ||||
|             model->frequency = 4; | ||||
|             model->real_frequency = | ||||
|                 api_hal_subghz_set_frequency(subghz_frequencies[model->frequency]); | ||||
|             model->path = subghz_frequencies_paths[model->frequency]; | ||||
|             model->button = 0; | ||||
|             api_hal_subghz_set_path(model->path); | ||||
|             return true; | ||||
|         }); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 あく
						あく