Mercurial > public > hwos_code
comparison src/tft_outputs.asm @ 552:af84c45429fd
BUGFIX: Display of negative (?C) water temperatures
author | heinrichsweikamp |
---|---|
date | Sun, 19 Nov 2017 17:22:11 +0100 |
parents | 33941d158069 |
children | 2e70700774b9 |
comparison
equal
deleted
inserted
replaced
551:33941d158069 | 552:af84c45429fd |
---|---|
1789 return | 1789 return |
1790 | 1790 |
1791 | 1791 |
1792 ;============================================================================= | 1792 ;============================================================================= |
1793 | 1793 |
1794 global TFT_temp_surfmode | 1794 global TFT_temp_surfmode |
1795 TFT_temp_surfmode: | 1795 TFT_temp_surfmode: |
1796 WIN_SMALL surf_temp_column,surf_temp_row | |
1797 call TFT_standard_color | |
1798 | |
1799 SAFE_2BYTE_COPY temperature, lo | |
1800 | |
1801 TSTOSS opt_units ; 0=°C, 1=°F | |
1802 bra TFT_temp_surfmode_metric | |
1803 | |
1804 ;TFT_temp_surfmode_imperial: | |
1805 rcall TFT_convert_signed_16bit ; converts lo:hi into signed-short and adds '-' to POSTINC2 if required | |
1806 call convert_celsius_to_fahrenheit ; convert value in lo:hi from celsius to fahrenheit | |
1807 lfsr FSR2,buffer ; Overwrite "-" | |
1808 bsf ignore_digit5 ; Full degrees only | |
1809 output_16 | |
1810 STRCAT_PRINT "" | |
1811 call TFT_divemask_color | 1796 call TFT_divemask_color |
1812 WIN_SMALL surf_temp_column+4*8,surf_temp_row | 1797 WIN_SMALL surf_temp_column+3*8,surf_temp_row |
1813 STRCPY_PRINT "°F" | 1798 TSTOSS opt_units ; 0=°C, 1=°F |
1814 return | 1799 bra TFT_temp_surfmode_metric |
1815 | 1800 STRCAT_TEXT tLogTunitF ; °F |
1801 bra TFT_temp_surfmode_common | |
1816 TFT_temp_surfmode_metric: | 1802 TFT_temp_surfmode_metric: |
1817 rcall TFT_convert_signed_16bit ; converts lo:hi into signed-short and adds '-' to POSTINC2 if required | 1803 STRCAT_TEXT tLogTunitC ; °C |
1818 movlw d'3' | 1804 TFT_temp_surfmode_common: |
1819 movwf ignore_digits | 1805 STRCAT_PRINT "" |
1820 bsf ignore_digit5 ; Full degrees only | 1806 WIN_SMALL surf_temp_column,surf_temp_row |
1821 output_16 | 1807 bra TFT_temp_common |
1822 | 1808 |
1823 ; read-back the buffer+4 | 1809 global TFT_temp_divemode |
1824 movff buffer+4,lo | 1810 TFT_temp_divemode: |
1825 movlw " " ; Space | 1811 btfsc divemode_menu ; Is the dive mode menu shown? |
1826 cpfseq lo ; Was it a space (between +1°C and -1°C)? | 1812 return ; Yes, no update of temperature now |
1827 bra TFT_temp_surfmode1 ; No. | 1813 btfsc blinking_better_gas ; blinking better Gas? |
1828 movlw "0" ; Yes, print manual zero | 1814 return ; Yes, no update of temperature now |
1829 movff WREG,buffer+3 | 1815 WIN_SMALL dm_temp_column,dm_temp_row |
1830 bra TFT_temp_surfmode2 | 1816 |
1831 TFT_temp_surfmode1: | 1817 TFT_temp_common: |
1832 ; Test if output was negative (Flag set in TFT_convert_signed_16bit) | 1818 call TFT_standard_color |
1833 btfss neg_flag ; Negative temperature? | 1819 SAFE_2BYTE_COPY temperature, lo ; get current temperature |
1834 bra TFT_temp_surfmode3 ; No, continue | 1820 TSTOSS opt_units ; 0=°C, 1=°F |
1835 ; Yes, negative temperature! | 1821 bra TFT_temp_common_1 |
1836 movff buffer+3,buffer+2 ; remove two spaces manually | 1822 call convert_celsius_to_fahrenheit ; convert value in lo:hi from celsius to fahrenheit |
1837 movff buffer+4,buffer+3 | 1823 TFT_temp_common_1: |
1838 TFT_temp_surfmode2: | 1824 rcall TFT_convert_signed_16bit ; converts lo:hi into signed-short and adds '-' to POSTINC2 if required |
1839 movlw 0x00 | 1825 btfsc neg_flag ; is the temperature negative? |
1840 movff WREG,buffer+4 | 1826 bra TFT_temp_common_2 ; YES - the minus sign has already been written |
1841 TFT_temp_surfmode3: | 1827 PUTC " " ; NO - write a space instead of the minus sign |
1842 STRCAT_PRINT "" | 1828 TFT_temp_common_2: |
1843 call TFT_divemask_color | 1829 bsf ignore_digit5 ; ignore decimal |
1844 WIN_SMALL surf_temp_column+4*8,surf_temp_row | 1830 output_16_3 ; output 0-999 without decimal -> writes ' ' - 99 |
1845 STRCPY_PRINT "°C" | 1831 bcf ignore_digit5 |
1846 return | 1832 movff buffer+2,lo ; get output from unit position |
1847 | 1833 movlw " " ; load code of the space character |
1834 cpfseq lo ; is there a space sign on the unit position? (happens between +1 and -1) | |
1835 bra TFT_temp_common_3 ; NO | |
1836 movff WREG,buffer+0 ; YES - replace potential minus sign with a space (temps from -0.9° to -0.1° else would appear as '- 0') | |
1837 movlw "0" ; load code of the zero character | |
1838 movff WREG,buffer+2 ; replace space with a zero | |
1839 TFT_temp_common_3: | |
1840 btfss divemode ; are we in dive mode? | |
1841 bra TFT_temp_common_5 ; NO - no unit to append | |
1842 TSTOSS opt_units ; YES - check unit type: 0=°C, 1=°F | |
1843 bra TFT_temp_common_4 ; go metric | |
1844 STRCAT_TEXT tLogTunitF ; append °F | |
1845 bra TFT_temp_common_5 | |
1846 TFT_temp_common_4: | |
1847 STRCAT_TEXT tLogTunitC ; append °C | |
1848 TFT_temp_common_5: | |
1849 STRCAT_PRINT "" ; output to screen | |
1850 return | |
1851 | |
1848 ;============================================================================= | 1852 ;============================================================================= |
1849 global TFT_divemode_menu_cursor | 1853 global TFT_divemode_menu_cursor |
1850 TFT_divemode_menu_cursor: | 1854 TFT_divemode_menu_cursor: |
1851 WIN_BOX_BLACK dm_menu_row+.1, dm_menu_lower-.1, dm_menu_item1_column-.8, dm_menu_item1_column-.1 | 1855 WIN_BOX_BLACK dm_menu_row+.1, dm_menu_lower-.1, dm_menu_item1_column-.8, dm_menu_item1_column-.1 |
1852 WIN_BOX_BLACK dm_menu_row+.1, dm_menu_lower-.1, dm_menu_item4_column-.8, dm_menu_item4_column-.1 | 1856 WIN_BOX_BLACK dm_menu_row+.1, dm_menu_lower-.1, dm_menu_item4_column-.8, dm_menu_item4_column-.1 |
1872 movff WREG,win_top | 1876 movff WREG,win_top |
1873 movlw FT_SMALL | 1877 movlw FT_SMALL |
1874 movff WREG,win_font | 1878 movff WREG,win_font |
1875 STRCPY_PRINT "\xb7" ; print cursor | 1879 STRCPY_PRINT "\xb7" ; print cursor |
1876 return | 1880 return |
1877 | |
1878 global TFT_temp_divemode | |
1879 TFT_temp_divemode: | |
1880 btfsc divemode_menu ; Is the dive mode menu shown? | |
1881 return ; Yes, return | |
1882 btfsc blinking_better_gas ; blinking better Gas? | |
1883 return ; Yes, no update of temperature now | |
1884 ; temperature | |
1885 WIN_SMALL dm_temp_column,dm_temp_row | |
1886 call TFT_standard_color | |
1887 bsf leftbind | |
1888 | |
1889 SAFE_2BYTE_COPY temperature, lo | |
1890 TSTOSS opt_units ; 0=°C, 1=°F | |
1891 bra TFT_temp_divemode_metric | |
1892 | |
1893 ;TFT_temp_divemode_imperial: | |
1894 rcall TFT_convert_signed_16bit ; converts lo:hi into signed-short and adds '-' to POSTINC2 if required | |
1895 call convert_celsius_to_fahrenheit ; convert value in lo:hi from celsius to fahrenheit | |
1896 lfsr FSR2,buffer ; Overwrite "-" (There won't be less then -18°C underwater...) | |
1897 bsf ignore_digit5 ; Full degrees only | |
1898 output_16 | |
1899 STRCAT_TEXT tLogTunitF | |
1900 TFT_temp_divemode_common: | |
1901 bcf leftbind | |
1902 movlw .4 ; limit to three chars | |
1903 call TFT_fillup_with_spaces ; Fillup FSR2 with spaces (Total string length in #WREG) | |
1904 STRCAT_PRINT "" | |
1905 return ; Done. | |
1906 | |
1907 TFT_temp_divemode_metric: | |
1908 rcall TFT_convert_signed_16bit ; converts lo:hi into signed-short and adds '-' to POSTINC2 if required | |
1909 movlw d'3' | |
1910 movwf ignore_digits | |
1911 bsf ignore_digit5 ; Full degrees only | |
1912 output_16 | |
1913 STRCAT_TEXT tLogTunitC | |
1914 bra TFT_temp_divemode_common ; Done. | |
1915 | 1881 |
1916 TFT_active_setpoint2: | 1882 TFT_active_setpoint2: |
1917 movff char_I_const_ppO2,lo | 1883 movff char_I_const_ppO2,lo |
1918 TFT_color_code warn_ppo2_hud ; With ppO2 [cbar] in lo | 1884 TFT_color_code warn_ppo2_hud ; With ppO2 [cbar] in lo |
1919 clrf hi | 1885 clrf hi |
4135 | 4101 |
4136 movff xC+0,lo | 4102 movff xC+0,lo |
4137 movff xC+1,hi ; restore lo and hi with updated value | 4103 movff xC+1,hi ; restore lo and hi with updated value |
4138 return | 4104 return |
4139 | 4105 |
4140 global convert_celsius_to_fahrenheit ; convert value in lo:hi from celsius to fahrenheit | 4106 global convert_celsius_to_fahrenheit ; convert value in lo:hi from celsius to fahrenheit |
4141 convert_celsius_to_fahrenheit: ; convert value in lo:hi from celsius to fahrenheit | 4107 convert_celsius_to_fahrenheit: ; convert value in lo:hi from celsius to fahrenheit |
4142 ; Does it work with signed temperature? mH | 4108 movff lo,xA+0 ; temperature in 1/10 of °C |
4143 movff lo,xA+0 | 4109 movff hi,xA+1 |
4144 movff hi,xA+1 | 4110 |
4145 | 4111 movlw LOW d'1000' ; offset °C value by 1000 to get out of any negative numbers |
4146 movlw d'18' ; 1C = 1.8F | 4112 addwf xA+0,F |
4147 movwf xB+0 | 4113 movlw HIGH d'1000' |
4148 clrf xB+1 | 4114 addwfc xA+1,F |
4149 | 4115 |
4150 call mult16x16 ;xA*xB=xC (lo:hi * 18) | 4116 movlw d'18' ; adjust scaling: 1°C = 1.8°F |
4151 | 4117 movwf xB+0 |
4152 movlw d'10' | 4118 clrf xB+1 |
4153 movwf xB+0 | 4119 |
4154 clrf xB+1 | 4120 call mult16x16 ; xA*xB=xC (lo:hi * 18) |
4155 | 4121 |
4156 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 4122 movlw d'10' |
4157 | 4123 movwf xB+0 |
4158 movlw LOW d'320' ; 0C = 32F | 4124 clrf xB+1 |
4159 addwf xC+0,F | 4125 |
4160 movlw HIGH d'320' | 4126 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
4161 addwfc xC+1,F | 4127 |
4162 | 4128 movlw LOW d'1480' ; adjust offset: subtract above offset of 1000 * 1.8 = 1800 now and add 320 => subtract 1480 |
4163 movff xC+0,lo | 4129 subwf xC+0,F |
4164 movff xC+1,hi ; restore lo and hi with updated value | 4130 movlw HIGH d'1480' |
4165 return | 4131 subwfb xC+1,F |
4166 | 4132 |
4133 movff xC+0,lo | |
4134 movff xC+1,hi ; restore lo and hi with updated value | |
4135 return | |
4136 | |
4167 ;============================================================================= | 4137 ;============================================================================= |
4168 global compute_pscr_ppo2 | 4138 global compute_pscr_ppo2 |
4169 compute_pscr_ppo2: | 4139 compute_pscr_ppo2: |
4170 ; (Pressure[mbar]*char_I_O2_ratio)-(100-char_I_O2_ratio)*CF61*CF62*10 | 4140 ; (Pressure[mbar]*char_I_O2_ratio)-(100-char_I_O2_ratio)*CF61*CF62*10 |
4171 movff char_I_O2_ratio,WREG | 4141 movff char_I_O2_ratio,WREG |