work on Qt GUI, still not working properly

This commit is contained in:
Jeff Wang
2019-04-04 00:33:42 -04:00
parent 8f39958679
commit fc6d8efc5f
17 changed files with 328 additions and 33 deletions

View File

@ -1,4 +1,10 @@
include_directories(${Qt5Widgets_INCLUDE_DIRS} ${QtQml_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS} ${${Qt5Quick_DEFINITIONS}})
add_library(decn decn/decn.c)
add_library(calc main.c calc.c utils.c lcd_emulator.c key.c)
add_library(calc qt_main.cpp calc.c utils.c lcd_emulator.c key.c)
target_link_libraries(calc Qt5::Widgets)
add_executable(keytest key.c)
target_compile_definitions(keytest PRIVATE KEY_TEST_APP=1)

View File

@ -10,6 +10,10 @@
#include <stdint.h>
#include "decn/decn.h"
#ifdef __cplusplus
extern "C" {
#endif
void process_cmd(char cmd);
void push_decn(const char* signif_str, int16_t exponent, uint8_t no_lift);
@ -19,4 +23,8 @@ void set_x(const char* signif_str, int16_t exponent);
__xdata dec80* get_x(void);
__xdata dec80* get_y(void);
#ifdef __cplusplus
}
#endif
#endif /* SRC_CALC_H_ */

View File

@ -10,6 +10,10 @@
#include <stdint.h>
#include "../utils.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEC80_NUM_LSU 9
//allow full range, but reserve -16384 for special numbers
@ -57,4 +61,8 @@ int8_t decn_to_str(char* buf, const dec80* x);
void decn_to_str_complete(char* buf, const dec80* x);
#endif
#ifdef __cplusplus
}
#endif
#endif /* SRC_DEC_DECN_H_ */

View File

@ -237,7 +237,7 @@ const uint8_t* DebugGetKeys(void){
#ifdef DESKTOP
#ifdef KEY_TEST_APP
int main(void){
KeyInit();

View File

@ -7,6 +7,11 @@
#ifndef SRC_KEY_H_
#define SRC_KEY_H_
#ifdef __cplusplus
extern "C" {
#endif
//#define DEBUG_KEYS
void KeyInit(void);
@ -24,4 +29,8 @@ extern uint8_t Keys[TOTAL_ROWS]; //only bottom nibbles get set
extern int8_t NewKeyPressed;
#ifdef __cplusplus
}
#endif
#endif /* SRC_KEY_H_ */

View File

@ -1,6 +1,9 @@
#ifndef LCD_H
#define LCD_H
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_CHARS_PER_LINE 16
#define MAX_ROWS 2
@ -18,5 +21,15 @@ void LCD_ClearToEnd(uint8_t curr_row);
#define CGRAM_EXP 0
#define CGRAM_EXP_NEG 1
#include "utils.h"
#ifdef DESKTOP
const char* get_lcd_buf(void);
void print_lcd(void);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -6,26 +6,44 @@
#include <stdio.h>
#include <stdint.h>
#include <ctype.h>
#include "lcd.h"
#define CR 13 // \r
#define TAB 9 // \n
static int lcd_row, lcd_col;
static uint8_t lcd_row, lcd_col;
static char lcd_buf[MAX_ROWS][MAX_CHARS_PER_LINE];
void LCD_Open(void){
const char* get_lcd_buf(void){
return &lcd_buf[0][0];
}
void print_lcd(void){
printf("(row,col)=(%d,%d)\n", lcd_row, lcd_col);
printf("|---|---|---|---|\n");
for (int i = 0; i < MAX_ROWS; i++){
printf("|");
for (int j = 0; j < MAX_CHARS_PER_LINE; j++){
printf("%c", lcd_buf[i][j]);
}
printf("\n");
}
printf("|---|---|---|---|\n");
}
void LCD_Open(void){
LCD_Clear();
}
void LCD_Clear(void){
lcd_row=0;
lcd_col=0;
for (int i = 0; i < MAX_ROWS; i++){
for (int j = 0; j < MAX_CHARS_PER_LINE; j++){
lcd_buf[i][j] = 0;
lcd_buf[i][j] = ' ';
}
}
lcd_row=0;
lcd_col=0;
}
void LCD_GoTo(unsigned int row, unsigned int col){
@ -53,6 +71,18 @@ void LCD_OutString(const char *string, uint8_t max_chars) {
}
}
static int is_valid_character(char letter){
if (isdigit(letter)){
return 1;
} else if(letter == CGRAM_EXP || letter == CGRAM_EXP_NEG){
return 1;
} else if(letter == '.' || letter == ' '){
return 1;
}
return 0;
}
short TERMIO_PutChar(unsigned char letter) {
if (letter == CR || letter == '\n') {
LCD_Clear();
@ -62,8 +92,14 @@ short TERMIO_PutChar(unsigned char letter) {
} else {
to_row(0);
}
} else {
lcd_buf[lcd_row][lcd_col] = letter;
} else if (is_valid_character(letter)) {
if (letter == CGRAM_EXP){
lcd_buf[lcd_row][lcd_col] = 'E';
} else if (letter == CGRAM_EXP_NEG) {
lcd_buf[lcd_row][lcd_col] = '-';
} else {
lcd_buf[lcd_row][lcd_col] = letter;
}
lcd_col++;
if (lcd_col > MAX_CHARS_PER_LINE) {
if (lcd_row == 0) {
@ -72,6 +108,9 @@ short TERMIO_PutChar(unsigned char letter) {
to_row(0);
}
}
} else {
printf("\nerror @%d,%d, invalid character %d\n",
lcd_row, lcd_col, letter);
}
return 1;

View File

@ -8,7 +8,10 @@
#include "decn/decn.h"
#include "calc.h"
#include "utils.h"
#ifndef DESKTOP
#ifdef DESKTOP
#include <stdio.h>
#include <QMutex>
#else
#include "stc15.h"
#endif
@ -24,10 +27,15 @@ static const char KEY_MAP[20] = {
};
#ifdef DESKTOP
QMutex KeyMutex;
#endif
int8_t NewKeyBuf[4];
volatile uint8_t new_key_write_i;
volatile uint8_t new_key_read_i;
volatile uint8_t NewKeyEmpty;
#define INCR_NEW_KEY_I(i) i = (i + 1) & 3
volatile uint8_t SecCount;
@ -44,7 +52,11 @@ void timer0_isr() SDCC_ISR(1,1)
if (NewKeyPressed != -1){
if (!NewKeyEmpty && (new_key_write_i == new_key_read_i)){
//do not overwrite keymap currently being processed
INCR_NEW_KEY_I(new_key_write_i);
// INCR_NEW_KEY_I(new_key_write_i);
#ifdef DESKTOP
printf("ERROR: key fifo full\n");
#endif
return;
}
NewKeyBuf[new_key_write_i] = NewKeyPressed;
INCR_NEW_KEY_I(new_key_write_i);
@ -106,9 +118,21 @@ char Buf[DECN_BUF_SIZE];
__xdata char EntryBuf[MAX_CHARS_PER_LINE + 1];
__xdata uint8_t ExpBuf[2];
#ifdef DESKTOP
static void print_entry_bufs(void){
printf("EntryBuf:~%s~\n", EntryBuf);
printf("ExpBuf:%c%c\n", '0'+ExpBuf[1], '0'+ExpBuf[0]);
}
#endif
//#define DEBUG_UPTIME
/*********************************************/
#ifdef DESKTOP
uint8_t ExitCalcMain;
int calc_main()
#else
int main()
#endif
{
enum {
ENTERING_DONE,
@ -152,6 +176,11 @@ int main()
if (Keys[0] == 8 && Keys[4] == 8){
TURN_OFF();
}
#ifdef DESKTOP
if (ExitCalcMain){
return 0;
}
#endif
LCD_GoTo(0,0);
#ifdef DEBUG_UPTIME
@ -200,12 +229,21 @@ int main()
///get new key
#ifdef DESKTOP
KeyMutex.lock();
#endif
if (!NewKeyEmpty){
int8_t i_key = NewKeyBuf[new_key_read_i];
INCR_NEW_KEY_I(new_key_read_i);
if (new_key_read_i == new_key_write_i){
NewKeyEmpty = 1;
}
#ifdef DESKTOP
KeyMutex.unlock();
printf("\nprocessing key %c (r=%d, w=%d, e=%d)\n",
KEY_MAP[i_key], new_key_read_i, new_key_write_i, NewKeyEmpty);
printf("entry_i=%d,exp_i=%d\n", entry_i, exp_i);
#endif
#ifdef DEBUG_KEYS
LCD_GoTo(1,j);
TERMIO_PutChar(KEY_MAP[i_key]);
@ -367,10 +405,21 @@ int main()
default: process_cmd(KEY_MAP[i_key]);
//////////
} //switch(KEY_MAP[i_key])
} //if found new key pressed
} else { //else for (if found new key pressed)
//no new key pressed
#ifdef DESKTOP
KeyMutex.unlock();
#endif
continue;
}
//print X
LCD_ClearToEnd(0); //go to 2nd row
#ifdef DESKTOP
print_lcd();
printf("entry_i=%d,exp_i=%d\n", entry_i, exp_i);
print_entry_bufs();
#endif
if (entering_exp == ENTERING_DONE){
disp_exponent = decn_to_str(Buf, get_x());
if (disp_exponent == 0){
@ -419,6 +468,11 @@ int main()
TERMIO_PutChar(ExpBuf[0] + '0');
}
LCD_ClearToEnd(1);
#ifdef DESKTOP
print_lcd();
printf("entry_i=%d,exp_i=%d\n", entry_i, exp_i);
print_entry_bufs();
#endif
//turn backlight back on
BACKLIGHT_ON();
} //while (1)

3
src/qt_main.cpp Normal file
View File

@ -0,0 +1,3 @@
// dummy .cpp file, so that this is c++
#include "main.c"

View File

@ -9,6 +9,10 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void _delay_ms(uint8_t ms);
#define ACCURATE_DELAY_US
@ -44,5 +48,10 @@ char* u32str(uint32_t x, char* buf, uint8_t base);
#define TURN_OFF() P3_2 = 0
#endif
#ifdef __cplusplus
}
#endif
#endif /* SRC_UTILS_H_ */