Fixed makefile. Fixed some chars. Fixed printing
This commit is contained in:
parent
24ba7eab98
commit
4cf149a7f1
@ -5,4 +5,4 @@ build:
|
|||||||
avr-gcc main.c i2c_master.c -o counter -mmcu=attiny85
|
avr-gcc main.c i2c_master.c -o counter -mmcu=attiny85
|
||||||
|
|
||||||
program:
|
program:
|
||||||
avrdude
|
avrdude -p attiny85 -c usbtiny -U flash:w:counter
|
||||||
|
|||||||
47
code/main.c
47
code/main.c
@ -96,7 +96,7 @@ const uint8_t PROGMEM unfold_table[16] =
|
|||||||
|
|
||||||
const uint8_t PROGMEM symbols[80] =
|
const uint8_t PROGMEM symbols[80] =
|
||||||
{
|
{
|
||||||
0x3D, 0x51, 0x49, 0x45, 0x3D, // 0
|
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
|
||||||
0x00, 0x42, 0x7F, 0x40, 0x00, // 1
|
0x00, 0x42, 0x7F, 0x40, 0x00, // 1
|
||||||
0x42, 0x61, 0x51, 0x49, 0x46, // 2
|
0x42, 0x61, 0x51, 0x49, 0x46, // 2
|
||||||
0x21, 0x41, 0x45, 0x4B, 0x31, // 3
|
0x21, 0x41, 0x45, 0x4B, 0x31, // 3
|
||||||
@ -105,7 +105,7 @@ const uint8_t PROGMEM symbols[80] =
|
|||||||
0x3C, 0x4A, 0x49, 0x49, 0x30, // 6
|
0x3C, 0x4A, 0x49, 0x49, 0x30, // 6
|
||||||
0x03, 0x71, 0x09, 0x05, 0x03, // 7
|
0x03, 0x71, 0x09, 0x05, 0x03, // 7
|
||||||
0x36, 0x49, 0x49, 0x49, 0x36, // 8
|
0x36, 0x49, 0x49, 0x49, 0x36, // 8
|
||||||
0x06, 0x49, 0x49, 0x29, 0x1D, // 9
|
0x06, 0x49, 0x49, 0x29, 0x1E, // 9
|
||||||
0x7C, 0x04, 0x78, 0x04, 0x78, // m
|
0x7C, 0x04, 0x78, 0x04, 0x78, // m
|
||||||
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
|
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
|
||||||
0x00, 0x60, 0x60, 0x00, 0x00, // .
|
0x00, 0x60, 0x60, 0x00, 0x00, // .
|
||||||
@ -218,7 +218,8 @@ int main()
|
|||||||
eeprom_idx = 0;
|
eeprom_idx = 0;
|
||||||
state = STATE_SETTING;
|
state = STATE_SETTING;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
read_eeprom_val(eeprom_idx, &eeprom_value, &move_dir);
|
read_eeprom_val(eeprom_idx, &eeprom_value, &move_dir);
|
||||||
if (0 == eeprom_value)
|
if (0 == eeprom_value)
|
||||||
{
|
{
|
||||||
@ -229,12 +230,14 @@ int main()
|
|||||||
count_value = eeprom_value;
|
count_value = eeprom_value;
|
||||||
count_value_fine = eeprom_value;
|
count_value_fine = eeprom_value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (STATE_COUNTING == state)
|
if (STATE_COUNTING == state)
|
||||||
{
|
{
|
||||||
display_enable(0);
|
display_enable(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sei();
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
switch (state)
|
switch (state)
|
||||||
@ -325,6 +328,8 @@ int main()
|
|||||||
display_enable(0);
|
display_enable(0);
|
||||||
do_sleep();
|
do_sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// STATE_COUNTING
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_SETTING:
|
case STATE_SETTING:
|
||||||
@ -376,6 +381,8 @@ int main()
|
|||||||
update_display(count_value, highlight, move_dir, dir_highlight);
|
update_display(count_value, highlight, move_dir, dir_highlight);
|
||||||
}
|
}
|
||||||
long_press_when_ms = 0;
|
long_press_when_ms = 0;
|
||||||
|
|
||||||
|
// EVENT_BUTTON_UP
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -406,6 +413,7 @@ int main()
|
|||||||
long_press_when_ms = 0;
|
long_press_when_ms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// STATE_SETTING
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -558,6 +566,11 @@ void get_symbol16(uint8_t index, uint8_t *out)
|
|||||||
out[i] = 0;
|
out[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index > sizeof(symbols) / 5)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < CHAR_SIZE; ++i)
|
for (i = 0; i < CHAR_SIZE; ++i)
|
||||||
{
|
{
|
||||||
data_byte = pgm_read_byte(&(symbols[index * CHAR_SIZE + i]));
|
data_byte = pgm_read_byte(&(symbols[index * CHAR_SIZE + i]));
|
||||||
@ -642,19 +655,23 @@ void print_mm(uint32_t value, uint32_t highlight)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to print (for leading zeroes)
|
// Check if we need to print (for leading zeroes)
|
||||||
if (!(is_first && (0 == highlight) && (0 == symbol)))
|
if (is_first && (0 == highlight) && (0 == symbol))
|
||||||
|
{
|
||||||
|
symbol = 0xFF;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
is_first = 0;
|
is_first = 0;
|
||||||
print_symbol(symbol * CHAR_SIZE, x, y, invert);
|
|
||||||
}
|
}
|
||||||
|
print_symbol(symbol, x, y, invert);
|
||||||
x += (CHAR_SIZE + 1) * 2;
|
x += (CHAR_SIZE + 1) * 2;
|
||||||
div_factor /= 10;
|
div_factor /= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print 'mm'
|
// Print 'mm'
|
||||||
print_symbol(10 * CHAR_SIZE, x, y, 0);
|
print_symbol(10, x, y, 0);
|
||||||
x += (CHAR_SIZE + 1) * 2;
|
x += (CHAR_SIZE + 1) * 2;
|
||||||
print_symbol(10 * CHAR_SIZE, x, y, 0);
|
print_symbol(10, x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_direction(uint8_t is_up, uint8_t invert)
|
void print_direction(uint8_t is_up, uint8_t invert)
|
||||||
@ -663,13 +680,13 @@ void print_direction(uint8_t is_up, uint8_t invert)
|
|||||||
|
|
||||||
if (is_up)
|
if (is_up)
|
||||||
{
|
{
|
||||||
symbol_index[0] = 14 * CHAR_SIZE;
|
symbol_index[0] = 14;
|
||||||
symbol_index[1] = 13 * CHAR_SIZE;
|
symbol_index[1] = 13;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
symbol_index[0] = 13 * CHAR_SIZE;
|
symbol_index[0] = 13;
|
||||||
symbol_index[1] = 15 * CHAR_SIZE;
|
symbol_index[1] = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_symbol(symbol_index[0], OLED_X_SIZE - CHAR_SIZE * 2, 0, invert);
|
print_symbol(symbol_index[0], OLED_X_SIZE - CHAR_SIZE * 2, 0, invert);
|
||||||
@ -695,7 +712,7 @@ void print_voltage(uint16_t value)
|
|||||||
symbol = value / div_factor;
|
symbol = value / div_factor;
|
||||||
value %= div_factor;
|
value %= div_factor;
|
||||||
|
|
||||||
print_symbol(symbol * CHAR_SIZE, x, y, 0);
|
print_symbol(symbol, x, y, 0);
|
||||||
if (0 == x)
|
if (0 == x)
|
||||||
{
|
{
|
||||||
x += (CHAR_SIZE + 1) * 2;
|
x += (CHAR_SIZE + 1) * 2;
|
||||||
@ -705,11 +722,11 @@ void print_voltage(uint16_t value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print 'V'
|
// Print 'V'
|
||||||
print_symbol(11 * CHAR_SIZE, x, y, 0);
|
print_symbol(11, x, y, 0);
|
||||||
|
|
||||||
// Print '.'
|
// Print '.'
|
||||||
x = (CHAR_SIZE + 1) * 2;
|
x = (CHAR_SIZE + 1) * 2;
|
||||||
print_symbol(12 * CHAR_SIZE, x, y, 0);
|
print_symbol(12, x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t adc_measure()
|
uint16_t adc_measure()
|
||||||
@ -737,7 +754,7 @@ uint16_t measure_voltage()
|
|||||||
uint16_t result;
|
uint16_t result;
|
||||||
|
|
||||||
val = 110;
|
val = 110;
|
||||||
val *= 1023;
|
val *= 1024;
|
||||||
val /= adc_measure();
|
val /= adc_measure();
|
||||||
result = val;
|
result = val;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user