 bdba15b366
			
		
	
	
		bdba15b366
		
			
		
	
	
	
	
		
			
			* iButton: getting started on the worker concept * Hal delay: added global instructions_per_us variable * iButton: one wire slave * iButton: ibutton key setter * iButton: one wire host, use ibutton_hal * iButton\RFID: common pulse decoder concept * iButton: cyfral decoder * iButton: worker thread concept * iButton: metakom decoder * iButton: write key through worker * iButton: worker mode holder * iButton: worker improvements * iButton: Cyfral encoder * iButton: Metakom encoder * lib: pulse protocol helpers * iButton: Metakom decoder * iButton: Cyfral decoder * iButton worker: separate modes * iButton: libs documentation * HAL: iButton gpio modes * iButton worker: rename modes file * iButton worker, hal: move to LL * iButton CLI: worker for reading and emulation commands * iButton HAL: correct init and emulation sequence * iButton cli: moved to plain C * iButton: move to worker, small step to plain C * Libs, one wire: move to plain C * Libs: added forgotten files to compilation * iButton writer: get rid of manual disable/enable irq
		
			
				
	
	
		
			62 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "ibutton_scene_read.h"
 | |
| #include "../ibutton_app.h"
 | |
| #include <dolphin/dolphin.h>
 | |
| 
 | |
| static void read_callback(void* context) {
 | |
|     iButtonApp* app = static_cast<iButtonApp*>(context);
 | |
|     iButtonEvent event = {.type = iButtonEvent::Type::EventTypeWorkerRead};
 | |
|     app->get_view_manager()->send_event(&event);
 | |
| }
 | |
| 
 | |
| void iButtonSceneRead::on_enter(iButtonApp* app) {
 | |
|     iButtonAppViewManager* view_manager = app->get_view_manager();
 | |
|     Popup* popup = view_manager->get_popup();
 | |
|     iButtonKey* key = app->get_key();
 | |
|     iButtonWorker* worker = app->get_key_worker();
 | |
|     DOLPHIN_DEED(DolphinDeedIbuttonRead);
 | |
| 
 | |
|     popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
 | |
|     popup_set_text(popup, "waiting\nfor key ...", 95, 30, AlignCenter, AlignTop);
 | |
|     popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
 | |
| 
 | |
|     view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
 | |
|     ibutton_key_set_name(key, "");
 | |
| 
 | |
|     ibutton_worker_read_set_callback(worker, read_callback, app);
 | |
|     ibutton_worker_read_start(worker, key);
 | |
| }
 | |
| 
 | |
| bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
 | |
|     bool consumed = false;
 | |
| 
 | |
|     if(event->type == iButtonEvent::Type::EventTypeWorkerRead) {
 | |
|         consumed = true;
 | |
| 
 | |
|         iButtonKey* key = app->get_key();
 | |
|         if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
 | |
|             if(!ibutton_key_dallas_crc_is_valid(key)) {
 | |
|                 app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
 | |
|             } else if(!ibutton_key_dallas_is_1990_key(key)) {
 | |
|                 app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
 | |
|             } else {
 | |
|                 app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
 | |
|             }
 | |
|         } else {
 | |
|             app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
 | |
|         }
 | |
|     } else if(event->type == iButtonEvent::Type::EventTypeTick) {
 | |
|         consumed = true;
 | |
|         app->notify_red_blink();
 | |
|     }
 | |
| 
 | |
|     return consumed;
 | |
| }
 | |
| 
 | |
| void iButtonSceneRead::on_exit(iButtonApp* app) {
 | |
|     Popup* popup = app->get_view_manager()->get_popup();
 | |
|     ibutton_worker_stop(app->get_key_worker());
 | |
|     popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
 | |
|     popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
 | |
|     popup_set_icon(popup, 0, 0, NULL);
 | |
| }
 |