view code_part1/OSTC_code_asm_part1/menu_reset.asm @ 83:3e351e25f5d1

adding anti-aliased fonts frame and merging some patches from Jeando
author heinrichsweikamp
date Tue, 07 Dec 2010 22:36:19 +0100
parents 69c462400279
children b40a0a6284da
line wrap: on
line source


; OSTC - diving computer code
; Copyright (C) 2008 HeinrichsWeikamp GbR

;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    (at your option) any later version.

;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.

;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.


; Menu "Reset all"
; written by: Matthias Heinrichs, info@heinrichsweikamp.com
; written: 10/30/05
; last updated: 08/08/31
; known bugs:
; ToDo: 

; routines to reset external EEPROM (currently inactvated!)
; routines to reset custom function, gases and decompression values
; does not reset clock

;=============================================================================
; CF default values
;

; Macro to check values, and construct PROM CF default table.
; If in types mode, set flags into hi. If not, clear it.
CF_DEFAULT	macro	type, value
			if ( type == CF_INT15 )
				if (HIGH value) > .127
					error "15bit default too big:", value
				endif
				DB		LOW value, 0x80 + (HIGH value)
			else
			    ; Basic sanity check for 8bit values:
				if ( HIGH value ) > 0
					error "8bit default too big:", value
				endif
				if (type==CF_BOOL) && (value > 1)
					error "BOOL default too big:", value
				endif
                ifdef	NO_CF_TYPES
				    DB		LOW value, HIGH value
                else
				    DB		LOW value, type
                endif
			endif
			endm

; resets all customfunctions to the following default values
cf_default_table:
    ;---- BANK0 custom function defaults -------------------------------------
	CF_DEFAULT    CF_CENTI,	    d'100' 		; dive_threshold	        100cm
	CF_DEFAULT    CF_CENTI,	    d'30' 		; surf_threshold        	30cm
	CF_DEFAULT    CF_SEC,	    d'240' 		; diveloop_timeout      	240s
	CF_DEFAULT    CF_SEC,	    d'120' 		; surfloop_timeout	        120s
	CF_DEFAULT    CF_SEC,	    d'5' 		; premenu_timeout	        5s

	CF_DEFAULT    CF_INT8, 	    d'7' 		; minimum_velocity		    7min/min
	CF_DEFAULT    CF_INT15,	    d'1160' 	; pressure_offset_divemode	1160mBar
	CF_DEFAULT    CF_INT15,	    d'1100' 	; max_surfpressure		    1100mBar
	CF_DEFAULT    CF_PERCENT,	d'20' 		; min_gradient_factor		20%
	CF_DEFAULT    CF_PERCENT,	d'20' 		; oxygen_threshold			20%

	CF_DEFAULT    CF_SEC,	    d'30' 		; dive_menu_timeout		    30s
	CF_DEFAULT    CF_PERCENT,   d'110' 		; saturation_multiplier		x1.10
	CF_DEFAULT    CF_PERCENT,   d'90' 		; desaturation_multiplier	x0.90
	CF_DEFAULT    CF_PERCENT,	d'60' 		; nofly_time_ratio			60%
	CF_DEFAULT    CF_PERCENT,	d'100' 		; gradient_factor_alarm1	100%

	CF_DEFAULT    CF_PERCENT,	d'10' 		; cns_display_surface		10%
	CF_DEFAULT    CF_INT8,	    d'10' 		; deco_distance_for_sim		1m
	CF_DEFAULT    CF_CENTI,     d'019' 		; ppo2_warning_low			0.19 Bar
	CF_DEFAULT    CF_CENTI,     d'160' 		; ppo2_warning_high			1.60 Bar
	CF_DEFAULT    CF_CENTI,     d'150' 		; ppo2_display_high			1.50 Bar
    
	CF_DEFAULT    CF_INT8,	    d'10' 		; sampling_rate				10s
	CF_DEFAULT    CF_INT8,	    d'6' 		; sampling_divisor_temp		/6
	CF_DEFAULT    CF_INT8,	    d'6' 		; sampling_divisor_deco		/6
	CF_DEFAULT    CF_INT8,	    d'0' 		; sampling_divisor_tank		never
	CF_DEFAULT    CF_INT8,	    d'0' 		; sampling_divisor_ppo2		never

	CF_DEFAULT    CF_INT8,	    d'0' 		; sampling_divisor_deco2	never
	CF_DEFAULT    CF_INT8,	    d'0' 		; sampling_divisor_nyu2		never
	CF_DEFAULT    CF_PERCENT,	d'20' 		; cns_display_high			20%
	CF_DEFAULT    CF_INT8,	    d'0' 		; logbook_offset			No Offset, but 15Bit value
	CF_DEFAULT    CF_INT8,	    d'3' 		; last_deco_depth			3m

	CF_DEFAULT    CF_SEC,	    d'10' 		; timeout_apnoe_mode		10min
	CF_DEFAULT    CF_BOOL,	    d'0' 		; show_voltage_value		=1 Show value instead of symbol, =0 Show Symbol

    ;---- BANK1 custom function defaults -------------------------------------
	CF_DEFAULT    CF_PERCENT,	d'30' 		; GF_low_default			30%
	CF_DEFAULT    CF_PERCENT,	d'90' 		; GF_high_default			90%
	CF_DEFAULT    CF_COLOR,     d'199' 		; color_battery_surface		Color Battery sign: Deep blue
	CF_DEFAULT    CF_COLOR,     d'255' 		; color_standard1			Color Standard: White
	CF_DEFAULT    CF_COLOR,     d'62' 		; color_divemask			Color Divemask: Light green
	CF_DEFAULT    CF_COLOR,     d'224' 		; color_warnings			Color Warnings: Red
    
	CF_DEFAULT    CF_BOOL,	    d'0' 		; show_seconds_divemode		=1 Show the seconds in Divemode
	CF_DEFAULT    CF_BOOL,	    d'0' 		; show_clock_divemode		=1 Show the clock in Divemode
	CF_DEFAULT    CF_BOOL,	    d'1' 		; warn_ceiling_divemode		=1 Warn ceiling violation in divemode
	CF_DEFAULT    CF_BOOL, 	    d'0' 		; start_with_stopwatch		=1 start with stopwatch
	CF_DEFAULT    CF_BOOL,	    d'0' 		; blink_gas_divemode 		=1 Show (resetable) average Depth instead of temperature
    
	CF_DEFAULT    CF_INT15,     d'13000' 	; color_warn_depth_mBar		Warn depths
	CF_DEFAULT    CF_PERCENT,	d'101' 		; color_warn_cns_percent    Warn-%
	CF_DEFAULT    CF_PERCENT,	d'101' 		; color_warn_gf_percent		Warn-%
	CF_DEFAULT    CF_CENTI,     d'161' 		; color_warn_ppo2_cbar		ppO2 warn
	CF_DEFAULT    CF_INT8,	    d'15' 		; color_warn_celocity_mmin	warn at xx m/min
    
	CF_DEFAULT    CF_SEC,	    d'42'   	; time_correction_value_default	Adds to Seconds on Midnight
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	                
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	                
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	                
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
	CF_DEFAULT    CF_INT15,     0           ; UNUSED
;=============================================================================

menu_reset:
	movlw	d'1'
	movwf	menupos

	call	PLED_ClearScreen
	call	PLED_reset_menu_mask

menu_reset2:
	clrf	timeout_counter2
	bcf		sleepmode
	bcf		menubit2
	bcf		menubit3
	bsf		menubit
	bsf		cursor
	call	PLED_reset_menu_mask
	call	PLED_menu_cursor
	bcf		switch_left
	bcf		switch_right
menu_reset_loop:
	call	check_switches_menu
	btfsc	menubit2
	bra		do_menu_reset					; call submenu
	btfss	menubit
	bra		menu							; exit setup menu and return to main menu
	btfsc	onesecupdate
	call	timeout_surfmode
	btfsc	onesecupdate
	call	set_dive_modes
	btfsc	onesecupdate
	call	test_charger				; check if charger IC is active
	btfsc	onesecupdate
	call	get_battery_voltage			; get battery voltage
	bcf		onesecupdate				; End of one second tasks
	btfsc	sleepmode
	goto	menu
	btfsc	divemode
	goto	restart						; exit menu, restart and enter divemode
	bra		menu_reset_loop
do_menu_reset:						; calls submenu
	dcfsnz	menupos,F
	bra		do_menu_reset_exit				; Cancel, exit
	dcfsnz	menupos,F
	bra		do_menu_reset_all				; Reset all settings
	dcfsnz	menupos,F
	bra		do_menu_reset_logbook			; Reset Logbook Memory!
	dcfsnz	menupos,F
	bra		do_menu_reset_reboot			; Reboot OSTC
	dcfsnz	menupos,F
	bra		do_menu_reset_decodata			; Reset Decodata
do_menu_reset_exit:
	movlw	d'3'
	movwf	menupos
	bra		menu2							; exit...


do_menu_reset_reboot:
	call	PLED_confirmbox				; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK!
	movwf	menupos						; Used as temp
	tstfsz	menupos
	bra		do_menu_reset_reboot2		; Delete now!
	bra		do_menu_reset_exit			; Cancel!

do_menu_reset_reboot2:
	call	PLED_DisplayOff					; Power-down OLED 
	movlw	b'00000000'						; Bit6: PPL Disable
	movwf	OSCTUNE
	movlw	b'01111110'						; 8MHz
	movwf	OSCCON
	reset
	goto	0x00000							; restart to 0x00000

do_menu_reset_logbook:
	call	PLED_confirmbox				; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK!
	movwf	menupos						; Used as temp
	tstfsz	menupos
	bra		do_menu_reset_logbook2		; Delete Logbook now!
	bra		do_menu_reset_exit			; Cancel!

do_menu_reset_logbook2:
	call	PLED_ClearScreen
	DISPLAYTEXT	.25					; "Reset..."
	call	reset_external_eeprom		; delete profile memory
	bra		do_menu_reset_exit

do_menu_reset_decodata:
	call	PLED_confirmbox				; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK!
	movwf	menupos						; Used as temp
	tstfsz	menupos
	bra		do_menu_reset_decodata2		; Reset Deco Data now!
	bra		do_menu_reset_exit			; Cancel!

do_menu_reset_decodata2:
; reset deco data
	call	PLED_ClearScreen
	DISPLAYTEXT	.25					; "Reset..."
	movff	amb_pressure+0,int_I_pres_respiration+0		; copy surface air pressure to deco routine
	movff	amb_pressure+1,int_I_pres_respiration+1		
	call	deco_main_clear_tissue	;
	movlb	b'00000001'				; RAM Bank1 selected
	goto	restart					; done. quit to surfmode

do_menu_reset_all:
	call	PLED_confirmbox				; Returns WREG=0 for Cancel (Or Timeout) and WREG=1 for OK!
	movwf	menupos						; Used as temp
	tstfsz	menupos
	bra		do_menu_reset_all2			; Reset all now!
	bra		do_menu_reset_exit			; Cancel!

do_menu_reset_all2:
	call	PLED_ClearScreen
	DISPLAYTEXT	.25					; "Reset..."

reset_start:
; reset deco data
	movff	amb_pressure+0,int_I_pres_respiration+0		; copy surface air pressure to deco routine
	movff	amb_pressure+1,int_I_pres_respiration+1		
	call	deco_main_clear_tissue	;
	movlb	b'00000001'				; RAM Bank1 selected

; reset gases
	clrf	EEADRH					; EEPROM BANK 0 !

	movlw	d'3'					; address of first gas-1
	movwf	EEADR
	clrf	hi						; He part (default for all gases: 0%)
	movlw	d'21'					; O2 part (21%)
	rcall	reset_customfunction	; saves default and current value for gas #1
	movlw	d'21'					; O2 part (21%)
	rcall	reset_customfunction	; saves default and current value for gas #2
	movlw	d'21'					; O2 part (21%)
	rcall	reset_customfunction	; saves default and current value for gas #3
	movlw	d'21'					; O2 part (21%)
	rcall	reset_customfunction	; saves default and current value for gas #4
	movlw	d'21'					; O2 part (21%)
	rcall	reset_customfunction	; saves default and current value for gas #5
	movlw	d'21'					; O2 part (21%)
	rcall	reset_customfunction	; saves default and current value for gas #6

reset_all_cf:
	movlw	d'1'
	movwf	EEDATA
	write_int_eeprom	d'33'		; reset start gas
	clrf	EEDATA
	write_int_eeprom	d'34'		; reset deco model to ZH-L16
	clrf	EEDATA
	write_int_eeprom	d'35'		; Do not use O2 Sensor in CC Modes

	movlw	d'0'
	clrf	EEDATA
	write_int_eeprom	d'39'		; Disable Debugbode
	clrf	EEDATA
	write_int_eeprom	d'90'		; Disable Brightness offset? (Dim=1, Normal = 0)
	clrf	EEDATA
	write_int_eeprom	d'91'		; Reset Date format to MM/DD/YY

	movlw	d'100'
	write_int_eeprom	d'26'		; Salinity default: 1.00 kg/l

	movlw	b'00011111'	
	movwf	EEDATA
	write_int_eeprom	d'27'		; reset active gas flags

	clrf	EEDATA
	write_int_eeprom	d'28'		; reset change depth gas #1
	clrf	EEDATA
	write_int_eeprom	d'29'		; reset change depth gas #2
	clrf	EEDATA
	write_int_eeprom	d'30'		; reset change depth gas #3
	clrf	EEDATA
	write_int_eeprom	d'31'		; reset change depth gas #4
	clrf	EEDATA
	write_int_eeprom	d'32'		; reset change depth gas #5

	movlw	d'100'
	movwf	EEDATA
	write_int_eeprom	d'36'		; reset mix1 to ppO2=1.00Bar
	write_int_eeprom	d'37'		; reset mix2 to ppO2=1.00Bar
	write_int_eeprom	d'38'		; reset mix3 to ppO2=1.00Bar

	movlw	d'1'
	movwf	nofly_time+0			; Clear nofly time
	clrf	nofly_time+1			; Clear nofly time

reset_all_cf_bank0:
    clrf    EEADRH
	movlw	d'127'					; address of low byte of first custom function
	movwf	EEADR

    movlw   LOW cf_default_table    ; Load PROM pointer.
    movwf   TBLPTRL,A
    movlw   HIGH cf_default_table
    movwf   TBLPTRH,A
    movlw   UPPER cf_default_table
    movwf   TBLPTRU,A

cf_bank0_loop:
	; Did we already read 32 (decimal) bytes ?
	movf    TBLPTRL,W
	sublw   LOW (cf_default_table+.64)
	bz      reset_all_cf_bank1

    tblrd*+
    movf    TABLAT, W               ; Low byte in WREG,
    tblrd*+
    movff   TABLAT, hi              ; High byte in hi
	rcall	reset_customfunction	; saves default and current value
	bra     cf_bank0_loop
	
reset_all_cf_bank1:
	movlw	d'1'
	movwf	EEADRH					; EEPROM BANK 1 !!
	movlw	d'127'					; address of low byte of first custom function
	movwf	EEADR

cf_bank1_loop:
	; Did we already read another 32 (decimal) bytes ?
	movf    TBLPTRL,W
	sublw   LOW (cf_default_table+.128)
	bz     cf_bank1_end

    tblrd*+
    movf    TABLAT, W               ; Low byte in WREG,
    tblrd*+
    movff   TABLAT, hi              ; High byte in hi
	rcall	reset_customfunction	; saves default and current value
	bra     cf_bank1_loop

cf_bank1_end:
	clrf	EEADRH					; EEPROM BANK 0 !

;call	reset_external_eeprom	; delete profile memory
	goto	restart					; all reset, quit to surfmode

; Write the four bytes lo:hi:lo:(hi w/o type flags) into EEPROM
; Don't change hi:lo values...
reset_customfunction:
	movwf	lo
	incf	EEADR,F
	movff	lo, EEDATA					; Lowbyte Defaul value
	call	write_eeprom
	incf	EEADR,F
	movff	hi, EEDATA					; Highbyte default value
	call	write_eeprom
	incf	EEADR,F
	movff	lo, EEDATA					; Lowbyte current value
	call	write_eeprom
	incf	EEADR,F
	movff	hi, EEDATA					; Highbyte current value
#ifdef NO_CF_TYPES
	bcf		EEDATA,7					; This bit will only be written for the default value
#else
	btfss	EEDATA,7					; A 15bit value ?
	clrf	EEDATA						; Nope: clear type flag.
#endif
	call	write_eeprom
	return
	

reset_external_eeprom:				; deletes complete external eeprom!
	clrf	eeprom_address+0
	clrf	eeprom_address+1

	movlw	d'2'
	movwf	temp3
reset_eeprom02:
	clrf	temp4
reset_eeprom01:
	movlw	d'64'
	movwf	temp2
	bcf		eeprom_blockwrite		; Blockwrite start
reset_eeprom1:
	setf	ext_ee_temp1			; byte for Blockwrite....
	movf	ext_ee_temp1,W			; So, 1st. Byte of block is fine, too
	call	write_external_eeprom_block
	decfsz	temp2,F		; 64 Byte done
	bra		reset_eeprom1
	bsf		SSPCON2,PEN					; Stop condition
	call	WaitMSSP	
	WAITMS	d'7'
	decfsz	temp4,F
	bra		reset_eeprom01				; do this 256 times
	decfsz	temp3,F
	bra		reset_eeprom02				; and this all 2 times -> 512 *64Bytes = 32KB

	bcf		eeprom_blockwrite			; clear blockwrite flag

	clrf	eeprom_address+0
	clrf	eeprom_address+1

	movlw	0xFD						; With these three bytes the OSTC will find the free area in the EEPROM faster
	call	write_external_eeprom
	movlw	0xFD
	call	write_external_eeprom
	movlw	0xFE						
	call	write_external_eeprom	

	clrf	eeprom_address+0
	clrf	eeprom_address+1
	return