Minor changes
This commit is contained in:
parent
17f212cf43
commit
a56e47eb7f
12
calculator.c
12
calculator.c
@ -5,8 +5,8 @@ void handleCalc(struct calculator *calc, int input) {
|
|||||||
case NUMBER_FIRST:
|
case NUMBER_FIRST:
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case 0:
|
case 0:
|
||||||
calc->num1 = (calc->num1 * 10) + 7;
|
calc->num1 = (calc->num1 * 10) + 7;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
calc->num1 = (calc->num1 * 10) + 8;
|
calc->num1 = (calc->num1 * 10) + 8;
|
||||||
break;
|
break;
|
||||||
@ -124,16 +124,18 @@ void handleCalc(struct calculator *calc, int input) {
|
|||||||
break;
|
break;
|
||||||
case RESULT:
|
case RESULT:
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case 13:
|
|
||||||
clearCalc(calc);
|
|
||||||
case 14:
|
case 14:
|
||||||
clearCalc(calc);
|
clearCalc(calc);
|
||||||
break;
|
break;
|
||||||
|
case 13:
|
||||||
|
clearCalc(calc);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void clearCalc(struct calculator* calc) {
|
|
||||||
|
void clearCalc(struct calculator *calc) {
|
||||||
calc->state = NUMBER_FIRST;
|
calc->state = NUMBER_FIRST;
|
||||||
calc->operation = NO_OP;
|
calc->operation = NO_OP;
|
||||||
calc->num1 = 0;
|
calc->num1 = 0;
|
||||||
|
12
calculator.h
12
calculator.h
@ -1,3 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* calculator.h
|
||||||
|
*
|
||||||
|
* Created: 29.05.2023 12:01:39
|
||||||
|
* Author: mrnek
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CALCULATOR_H_
|
||||||
|
#define CALCULATOR_H_
|
||||||
|
|
||||||
enum calculator_state {
|
enum calculator_state {
|
||||||
NUMBER_FIRST,
|
NUMBER_FIRST,
|
||||||
@ -27,3 +37,5 @@ struct calculator {
|
|||||||
void clearCalc(struct calculator *calc);
|
void clearCalc(struct calculator *calc);
|
||||||
|
|
||||||
void handleCalc(struct calculator *calc, int input);
|
void handleCalc(struct calculator *calc, int input);
|
||||||
|
|
||||||
|
#endif /* CALCULATOR_H_ */
|
@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
#include "func.h"
|
||||||
|
|
||||||
#define MASK_PIND 0b11110000
|
#define MASK_PIND 0b11110000
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ void get_physical_keys(struct key *keys) {
|
|||||||
uint8_t row;
|
uint8_t row;
|
||||||
for (int i = 0; i < KEYS_AMOUNT / 4; i++) {
|
for (int i = 0; i < KEYS_AMOUNT / 4; i++) {
|
||||||
PORTC &= ~(1 << i);
|
PORTC &= ~(1 << i);
|
||||||
for(volatile long i = 0; i < 1000; i++){};
|
delay();
|
||||||
row = PIND & MASK_PIND;
|
row = PIND & MASK_PIND;
|
||||||
if (row & (1 << 4)) keys[i * 4].physical = false; else keys[i * 4].physical = true;
|
if (row & (1 << 4)) keys[i * 4].physical = false; else keys[i * 4].physical = true;
|
||||||
if (row & (1 << 5)) keys[i * 4 + 1].physical = false; else keys[i * 4 + 1].physical = true;
|
if (row & (1 << 5)) keys[i * 4 + 1].physical = false; else keys[i * 4 + 1].physical = true;
|
||||||
@ -36,8 +37,9 @@ void get_logical_keys(struct key *undc_keys) {
|
|||||||
undc_keys[i].logical = undc_keys[i].physical;
|
undc_keys[i].logical = undc_keys[i].physical;
|
||||||
set_key_event(&undc_keys[i]);
|
set_key_event(&undc_keys[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
undc_keys[i].time = timestamp;
|
undc_keys[i].time = timestamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,6 +50,9 @@ void fill_buttons_names(struct key *buttons) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
/* */
|
||||||
|
/************************************************************************/
|
||||||
static void set_key_event(struct key *button) {
|
static void set_key_event(struct key *button) {
|
||||||
if (button->logical == true) {
|
if (button->logical == true) {
|
||||||
button->on_down = true;
|
button->on_down = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user