ibutton app, only read mode
This commit is contained in:
		
							parent
							
								
									a8fdbc6376
								
							
						
					
					
						commit
						799eefd754
					
				| @ -24,6 +24,7 @@ BUILD_VIBRO_DEMO = 1 | |||||||
| BUILD_SD_TEST = 1 | BUILD_SD_TEST = 1 | ||||||
| BUILD_GPIO_DEMO = 1 | BUILD_GPIO_DEMO = 1 | ||||||
| BUILD_MUSIC_PLAYER = 1 | BUILD_MUSIC_PLAYER = 1 | ||||||
|  | BUILD_IBUTTON = 1 | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
| APP_NFC ?= 0 | APP_NFC ?= 0 | ||||||
| @ -258,6 +259,17 @@ CFLAGS		+= -DBUILD_MUSIC_PLAYER | |||||||
| C_SOURCES	+= $(wildcard $(APP_DIR)/music-player/*.c) | C_SOURCES	+= $(wildcard $(APP_DIR)/music-player/*.c) | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
|  | APP_IBUTTON ?= 0 | ||||||
|  | ifeq ($(APP_IBUTTON), 1) | ||||||
|  | CFLAGS		+= -DAPP_IBUTTON | ||||||
|  | BUILD_IBUTTON = 1 | ||||||
|  | endif | ||||||
|  | BUILD_IBUTTON ?= 0 | ||||||
|  | ifeq ($(BUILD_IBUTTON), 1) | ||||||
|  | CFLAGS		+= -DBUILD_IBUTTON | ||||||
|  | CPP_SOURCES	+= $(wildcard $(APP_DIR)/ibutton/ibutton.cpp) | ||||||
|  | endif | ||||||
|  | 
 | ||||||
| # device drivers
 | # device drivers
 | ||||||
| 
 | 
 | ||||||
| APP_GUI	?= 0 | APP_GUI	?= 0 | ||||||
|  | |||||||
| @ -4,8 +4,12 @@ | |||||||
| 
 | 
 | ||||||
| // start app
 | // start app
 | ||||||
| void AppiButton::run() { | void AppiButton::run() { | ||||||
|  |     acquire_state(); | ||||||
|     mode[0] = new AppiButtonModeDallasRead(this); |     mode[0] = new AppiButtonModeDallasRead(this); | ||||||
|     mode[1] = new AppiButtonModeDallasEmulate(this); |     mode[1] = new AppiButtonModeDallasEmulate(this); | ||||||
|  |     release_state(); | ||||||
|  | 
 | ||||||
|  |     switch_to_mode(0); | ||||||
| 
 | 
 | ||||||
|     // create pin
 |     // create pin
 | ||||||
|     GpioPin red_led = led_gpio[0]; |     GpioPin red_led = led_gpio[0]; | ||||||
| @ -94,6 +98,14 @@ void AppiButton::decrease_mode() { | |||||||
|     release_state(); |     release_state(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void AppiButton::switch_to_mode(uint8_t mode_index) { | ||||||
|  |     acquire_state(); | ||||||
|  |     mode[state.mode_index]->release(); | ||||||
|  |     state.mode_index = mode_index; | ||||||
|  |     mode[state.mode_index]->acquire(); | ||||||
|  |     release_state(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // app enter function
 | // app enter function
 | ||||||
| extern "C" void app_ibutton(void* p) { | extern "C" void app_ibutton(void* p) { | ||||||
|     AppiButton* app = new AppiButton(); |     AppiButton* app = new AppiButton(); | ||||||
|  | |||||||
| @ -8,7 +8,8 @@ typedef uint8_t event_t; | |||||||
| class AppiButtonState { | class AppiButtonState { | ||||||
| public: | public: | ||||||
|     // state data
 |     // state data
 | ||||||
|     uint8_t dallas_address[8] = {0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB}; |     // test key = {0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB};
 | ||||||
|  |     uint8_t dallas_address[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; | ||||||
|     uint8_t mode_index; |     uint8_t mode_index; | ||||||
| 
 | 
 | ||||||
|     // state initializer
 |     // state initializer
 | ||||||
| @ -51,4 +52,5 @@ public: | |||||||
| 
 | 
 | ||||||
|     void increase_mode(); |     void increase_mode(); | ||||||
|     void decrease_mode(); |     void decrease_mode(); | ||||||
|  |     void switch_to_mode(uint8_t mode_index); | ||||||
| }; | }; | ||||||
| @ -25,19 +25,19 @@ public: | |||||||
| 
 | 
 | ||||||
| void AppiButtonModeDallasEmulate::event(AppiButtonEvent* event, AppiButtonState* state) { | void AppiButtonModeDallasEmulate::event(AppiButtonEvent* event, AppiButtonState* state) { | ||||||
|     if(event->type == AppiButtonEvent::EventTypeTick) { |     if(event->type == AppiButtonEvent::EventTypeTick) { | ||||||
|         acquire(); |         app->blink_red(); | ||||||
|         if(onewire_slave->emulate(state->dallas_address, 8)) { |         /*if(onewire_slave->emulate(state->dallas_address, 8)) {
 | ||||||
|             app->blink_green(); |             app->blink_green(); | ||||||
|         } else { |         } else { | ||||||
|              |              | ||||||
|         } |         }*/ | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AppiButtonModeDallasEmulate::render(CanvasApi* canvas, AppiButtonState* state) { | void AppiButtonModeDallasEmulate::render(CanvasApi* canvas, AppiButtonState* state) { | ||||||
|     canvas->set_font(canvas, FontSecondary); |     canvas->set_font(canvas, FontSecondary); | ||||||
|     canvas->draw_str(canvas, 2, 25, "< dallas emulate"); |     canvas->draw_str(canvas, 2, 25, "< dallas emulate"); | ||||||
|     canvas->draw_str(canvas, 2, 37, "give me domophone"); |     canvas->draw_str(canvas, 2, 37, "unimplemented"); | ||||||
|     { |     { | ||||||
|         char buf[24]; |         char buf[24]; | ||||||
|         sprintf( |         sprintf( | ||||||
|  | |||||||
| @ -129,8 +129,7 @@ bool OneWireGpioSlave::receiveBit(void) { | |||||||
|     // wait while bus is HIGH
 |     // wait while bus is HIGH
 | ||||||
|     OneWiteTimeType time = OneWireEmulateTiming::SLOT_MAX[overdrive_mode]; |     OneWiteTimeType time = OneWireEmulateTiming::SLOT_MAX[overdrive_mode]; | ||||||
|     time = wait_while_gpio(time, true); |     time = wait_while_gpio(time, true); | ||||||
|     if (time == 0) |     if(time == 0) { | ||||||
|     { |  | ||||||
|         printf("RESET_IN_PROGRESS\n"); |         printf("RESET_IN_PROGRESS\n"); | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
| @ -144,8 +143,7 @@ bool OneWireGpioSlave::receiveBit(void) { | |||||||
|     // wait while bus is LOW
 |     // wait while bus is LOW
 | ||||||
|     time = OneWireEmulateTiming::MSG_HIGH_TIMEOUT; |     time = OneWireEmulateTiming::MSG_HIGH_TIMEOUT; | ||||||
|     time = wait_while_gpio(time, false); |     time = wait_while_gpio(time, false); | ||||||
|     if (time == 0) |     if(time == 0) { | ||||||
|     { |  | ||||||
|         printf("TIMEOUT_HIGH\n"); |         printf("TIMEOUT_HIGH\n"); | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 DrZlo13
						DrZlo13