|
|
@ -55,53 +55,99 @@ void main() |
|
|
|
char charbuf[21]; |
|
|
|
char charbuf[21]; |
|
|
|
|
|
|
|
|
|
|
|
int dots = 0; |
|
|
|
int dots = 0; |
|
|
|
|
|
|
|
bool signal = false, last_signal; |
|
|
|
while (1) { |
|
|
|
while (1) { |
|
|
|
bool signal = ow_reset(OW_PIN); |
|
|
|
last_signal = signal; |
|
|
|
|
|
|
|
signal = ow_reset(OW_PIN); |
|
|
|
if (!signal) { |
|
|
|
if (!signal) { |
|
|
|
|
|
|
|
if (last_signal) { |
|
|
|
lcd_clear(); |
|
|
|
lcd_clear(); |
|
|
|
lcd_puts("No 1-Wire detected..."); |
|
|
|
} |
|
|
|
|
|
|
|
lcd_puts_xy(0,0,"No 1-Wire detected.."); |
|
|
|
dots = 0; |
|
|
|
dots = 0; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if (!last_signal) { |
|
|
|
|
|
|
|
lcd_clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ow_write(OW_PIN, 0x33); |
|
|
|
ow_write(OW_PIN, 0x33); |
|
|
|
ow_read_arr(OW_PIN, addr, 8); |
|
|
|
ow_read_arr(OW_PIN, addr, 8); |
|
|
|
|
|
|
|
|
|
|
|
lcd_clear(); |
|
|
|
// Show chip type
|
|
|
|
|
|
|
|
switch (addr[0]) { |
|
|
|
|
|
|
|
case 0x10: |
|
|
|
|
|
|
|
sprintf(charbuf, "18S20 "); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 0x28: |
|
|
|
|
|
|
|
sprintf(charbuf, "18B20 "); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 0x01: |
|
|
|
|
|
|
|
sprintf(charbuf, "iButton"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
sprintf(charbuf, "UNKNOWN"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lcd_puts_xy(12, 0, charbuf); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Show address
|
|
|
|
char *p = charbuf; |
|
|
|
char *p = charbuf; |
|
|
|
for(uint8_t i = 0; i < 4; i++) { |
|
|
|
for(uint8_t i = 0; i < 4; i++) { |
|
|
|
p += sprintf(p, "%02X", addr[i]); |
|
|
|
p += sprintf(p, "%02X", addr[i]); |
|
|
|
if (i < 3) *p++ = ':'; |
|
|
|
if (i < 3) *p++ = ':'; |
|
|
|
} |
|
|
|
} |
|
|
|
lcd_puts(charbuf); |
|
|
|
lcd_puts_xy(0, 0, charbuf); |
|
|
|
lcd_xy(0, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p = charbuf; |
|
|
|
p = charbuf; |
|
|
|
for(uint8_t i = 0; i < 4; i++) { |
|
|
|
for(uint8_t i = 0; i < 4; i++) { |
|
|
|
p += sprintf(p, "%02X", addr[4+i]); |
|
|
|
p += sprintf(p, "%02X", addr[4+i]); |
|
|
|
if (i < 3) *p++ = ':'; |
|
|
|
if (i < 3) *p++ = ':'; |
|
|
|
} |
|
|
|
} |
|
|
|
lcd_puts(charbuf); |
|
|
|
lcd_puts_xy(0, 1, charbuf); |
|
|
|
|
|
|
|
|
|
|
|
ds1820_single_measure(OW_PIN); |
|
|
|
// Measure temperature
|
|
|
|
uint16_t cels = ds1820_read_temp_c(OW_PIN); |
|
|
|
int16_t cels; |
|
|
|
|
|
|
|
if (addr[0] == 0x10 || addr[0] == 0x28) { |
|
|
|
|
|
|
|
ds18x20_single_measure(OW_PIN); |
|
|
|
|
|
|
|
if (addr[0] == 0x10) { |
|
|
|
|
|
|
|
// 18S20
|
|
|
|
|
|
|
|
cels = ds18s20_read_temp_c(OW_PIN); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 18B20
|
|
|
|
|
|
|
|
cels = ds18b20_read_temp_c(OW_PIN); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cels == 850) { |
|
|
|
if (cels == TEMP_ERROR || cels == 850) { |
|
|
|
lcd_xy(12, 0); |
|
|
|
lcd_xy(12, 1); |
|
|
|
for(uint8_t i = 0; i <= dots; i++) { |
|
|
|
for (uint8_t i = 0; i <= dots; i++) { |
|
|
|
lcd_putc('.'); |
|
|
|
lcd_putc('.'); |
|
|
|
} |
|
|
|
} |
|
|
|
dots = (dots+1)%3; |
|
|
|
dots = (dots + 1) % 3; |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
p = charbuf; |
|
|
|
p = charbuf; |
|
|
|
p += sprintf(p, "%d", cels/10); |
|
|
|
|
|
|
|
|
|
|
|
if (cels < 0) { |
|
|
|
|
|
|
|
*p++ = '-'; |
|
|
|
|
|
|
|
cels = -cels; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p += sprintf(p, "%d", cels / 10); |
|
|
|
*p++ = '.'; |
|
|
|
*p++ = '.'; |
|
|
|
p += sprintf(p, "%d", cels%10); |
|
|
|
p += sprintf(p, "%d", cels % 10); |
|
|
|
*p++ = 0xDF; |
|
|
|
*p++ = 0xDF; // ring symbol
|
|
|
|
*p++ = 'C'; |
|
|
|
*p++ = 'C'; |
|
|
|
*p++ = 0; |
|
|
|
*p++ = ' '; // padding to prevent artifacts if the number shrinks (we're not clearing screen when 1w is connected)
|
|
|
|
|
|
|
|
*p++ = ' '; |
|
|
|
|
|
|
|
*p++ = ' '; |
|
|
|
|
|
|
|
*p = 0; |
|
|
|
|
|
|
|
|
|
|
|
lcd_xy(12, 0); |
|
|
|
lcd_puts_xy(12, 1, charbuf); |
|
|
|
lcd_puts(charbuf); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|