diff --git a/src/file.cpp b/src/file.cpp index be0f133e6..93d190061 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -17,6 +17,7 @@ * */ +#define PROGRESS_VERTICAL_BAR #include "gruvin9x.h" #include "stdio.h" @@ -457,7 +458,11 @@ void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_le m_rlc_buf = buf; m_rlc_len = i_len; m_cur_rlc_len = 0; - m_ratio = (typ == FILE_TYP_MODEL ? 60 : 7); +#if defined (PROGRESS_CIRCLE) + m_ratio = (typ == FILE_TYP_MODEL ? 60 : 6); +#elif defined (PROGRESS_VERTICAL_BAR) + m_ratio = (typ == FILE_TYP_MODEL ? 100 : 10); +#endif do { nextRlcWriteStep(); @@ -573,10 +578,9 @@ void RlcFile::flush() s_sync_write = false; } -#define PROGRESS_CIRCLE void RlcFile::DisplayProgressBar(uint8_t x) { - if (s_eeDirtyMsk || m_rlc_len || eeprom_buffer_size) { + if (s_eeDirtyMsk || isWriting() || eeprom_buffer_size) { #if defined (PROGRESS_BAR) uint8_t len = (s_eeDirtyMsk ? 123 : min((uint8_t)123, (uint8_t)((m_rlc_len) / 5 + eeprom_buffer_size))); lcd_filled_rect(2, 1, 125, 5, WHITE); @@ -585,11 +589,17 @@ void RlcFile::DisplayProgressBar(uint8_t x) lcd_filled_rect(x-1, 0, 7, 7, WHITE); uint8_t len = s_eeDirtyMsk ? 1 : limit(1, 12 - (uint8_t)(m_rlc_len/m_ratio), 12); lcd_hline(x+1, 1, min((uint8_t)3, len)); - if (len >= 3) lcd_vline(x+4, 2, min(3, len-3)); - if (len >= 6) lcd_hline(x+4, 1+4, -min(3, len-6)); - if (len >= 9) lcd_vline(x, 5, -min(3, len-9)); + if (len >= 3) { + lcd_vline(x+4, 2, min(3, len-3)); + if (len >= 6) { + lcd_hline(x+4, 1+4, -min(3, len-6)); + if (len >= 9) { + lcd_vline(x, 5, -min(3, len-9)); + } + } + } #elif defined (PROGRESS_VERTICAL_BAR) - uint8_t len = 6 - (s_eeDirtyMsk ? 5 : min((uint8_t)5, (uint8_t)((m_rlc_len / 100) + (eeprom_buffer_size / 10)))); + uint8_t len = s_eeDirtyMsk ? 1 : limit((uint8_t)1, (uint8_t)(7 - (m_rlc_len/m_ratio)), (uint8_t)7); lcd_filled_rect(x+1, 0, 5, FH, WHITE); lcd_filled_rect(x+2, 7-len, 3, len); #elif defined (PROGRESS_FIXED_CIRCLE) diff --git a/src/gruvin9x.cpp b/src/gruvin9x.cpp index 8efbc93e5..aa14e4f7d 100644 --- a/src/gruvin9x.cpp +++ b/src/gruvin9x.cpp @@ -504,7 +504,7 @@ void doSplash() lcd_clear(); lcd_img(0, 0, s9xsplash,0,0); - refreshDiplay(); + refreshDisplay(); lcdSetRefVolt(g_eeGeneral.contrast); clearKeyEvents(); @@ -554,7 +554,7 @@ void alertMessages( const prog_char * s, const prog_char * t ) lcd_puts_P(0,4*FH,s); lcd_puts_P(0,5*FH,t); lcd_puts_P(0,6*FH, PSTR("Press any key to skip") ) ; - refreshDiplay(); + refreshDisplay(); lcdSetRefVolt(g_eeGeneral.contrast); clearKeyEvents(); @@ -638,7 +638,7 @@ void message(const prog_char * s) lcd_clear(); lcd_putsAtt(64-5*FW,0*FH,PSTR("MESSAGE"),DBLSIZE); lcd_puts_P(0,4*FW,s); - refreshDiplay(); + refreshDisplay(); lcdSetRefVolt(g_eeGeneral.contrast); } @@ -648,7 +648,7 @@ void alert(const prog_char * s, bool defaults) lcd_putsAtt(64-5*FW,0*FH,PSTR("ALERT"),DBLSIZE); lcd_puts_P(0,4*FH,s); lcd_puts_P(64-6*FW,7*FH,PSTR("press any Key")); - refreshDiplay(); + refreshDisplay(); lcdSetRefVolt(defaults ? 25 : g_eeGeneral.contrast); beepErr(); clearKeyEvents(); @@ -1708,7 +1708,7 @@ void perMain() ///////////////// g_menuStack[g_menuStackPtr](evt); - refreshDiplay(); + refreshDisplay(); #if defined (PCBV4) // PPM signal on phono-jack. In or out? ... @@ -2125,7 +2125,7 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim s_noStickInputs = false; for (uint8_t i=0; i inline t __attribute__ ((always_inline)) abs(t a){ return a>0?a:-a; } /// liefert das Minimum der Argumente -template inline t min(t a, t b){ return a inline t __attribute__ ((always_inline)) min(t a, t b){ return a inline t max(t a, t b){ return a>b?a:b; } -template inline int8_t sgn(t a){ return a>0 ? 1 : (a < 0 ? -1 : 0); } -template inline t limit(t mi, t x, t ma){ return min(max(mi,x),ma); } +template inline t __attribute__ ((always_inline)) max(t a, t b){ return a>b?a:b; } +template inline int8_t __attribute__ ((always_inline)) sgn(t a){ return a>0 ? 1 : (a < 0 ? -1 : 0); } +template inline t __attribute__ ((always_inline)) limit(t mi, t x, t ma){ return min(max(mi,x),ma); } /// Markiert einen EEPROM-Bereich als dirty. der Bereich wird dann in /// eeCheck ins EEPROM zurueckgeschrieben. diff --git a/src/lcd.cpp b/src/lcd.cpp index e656b5864..9bae322f8 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -29,6 +29,11 @@ uint8_t displayBuf[DISPLAY_W*DISPLAY_H/8]; #include "font_dblsize.lbm" #define font_10x16_x20_x7f (font_dblsize+3) +#ifdef SIMU +bool lcd_refresh = true; +uint8_t lcd_buf[DISPLAY_W*DISPLAY_H/8]; +#endif + void lcd_clear() { memset(displayBuf, 0, sizeof(displayBuf)); @@ -557,8 +562,12 @@ void lcdSetRefVolt(uint8_t val) lcdSendCtl(val); } -void refreshDiplay() +void refreshDisplay() { +#ifdef SIMU + memcpy(lcd_buf, displayBuf, sizeof(displayBuf)); + lcd_refresh = true; +#else uint8_t *p=displayBuf; for(uint8_t y=0; y < 8; y++) { lcdSendCtl(0x04); @@ -578,4 +587,5 @@ void refreshDiplay() PORTC_LCD_CTRL |= (1< g_tmr1Latency_max) g_tmr1Latency_max = dt; - if (dt < g_tmr1Latency_min) g_tmr1Latency_min = dt; // vinceofdrink@gmail harwared ppm // Orginal bitbang for PPM @@ -83,6 +81,9 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation // much change in the code not optimum but will not alter ppm precision #endif + if (dt > g_tmr1Latency_max) g_tmr1Latency_max = dt; + if (dt < g_tmr1Latency_min) g_tmr1Latency_min = dt; + ++pulses2MHzRPtr; if (pulses2MHzRPtr == pulses2MHzWPtr) { @@ -91,7 +92,6 @@ ISR(TIMER1_COMPA_vect) //2MHz pulse generation // channel = 0 ; // PulseTotal = 0 ; - // cli(); // TODO I remove this cli, we are in a blocking interrupt #if defined (PCBV3) TIMSK1 &= ~(1< 480 (just below 500msec - it can still reach 500 with offset) @@ -146,7 +148,7 @@ inline void __attribute__ ((always_inline)) setupPulsesPPM() // changed 10/05/20 rest += (int16_t(g_model.ppmFrameLength))*1000; if(p>9) rest=p*(1720u*2 + q) + 4000u*2; //for more than 9 channels, frame must be longer for (uint8_t i=0; i #include #include @@ -90,3 +93,5 @@ void eeprom_read_block (void *pointer_ram, #undef offsetof #define offsetof(st, m) ((size_t) ( (char *)&((st *)(0))->m - (char *)0 )) #define wdt_reset() + +#endif diff --git a/src/simu.cpp b/src/simu.cpp index 4684e2c9c..fbfac1d39 100644 --- a/src/simu.cpp +++ b/src/simu.cpp @@ -24,7 +24,6 @@ #include "FXPNGImage.h" #include #include "simpgmspace.h" -#include "lcd.h" #include "fxkeys.h" #include "gruvin9x.h" #include "menus.h" @@ -46,7 +45,6 @@ public: Gruvin9xSim(FXApp* a); long onKeypress(FXObject*,FXSelector,void*); long onArrowPress(FXObject*,FXSelector,void*); - long onChore(FXObject*,FXSelector,void*); long onTimeout(FXObject*,FXSelector,void*); void makeSnapshot(const FXDrawable* drawable); void doEvents(); @@ -71,7 +69,6 @@ public: FXDEFMAP(Gruvin9xSim) Gruvin9xSimMap[]={ //________Message_Type_________ID_____________________Message_Handler_______ - FXMAPFUNC(SEL_CHORE, 1, Gruvin9xSim::onChore), FXMAPFUNC(SEL_TIMEOUT, 2, Gruvin9xSim::onTimeout), FXMAPFUNC(SEL_COMMAND, 1000, Gruvin9xSim::onArrowPress), FXMAPFUNC(SEL_KEYPRESS, 0, Gruvin9xSim::onKeypress), @@ -237,35 +234,38 @@ long Gruvin9xSim::onTimeout(FXObject*,FXSelector,void*) } per10ms(); - getApp()->addChore(this,1); + refreshDiplay(); getApp()->addTimeout(this,2,10); return 0; } void Gruvin9xSim::refreshDiplay() { - if(portb & 1<setOffColor(FXRGB(150,200,152)); - else bmf->setOffColor(FXRGB(200,200,200)); + if (lcd_refresh) { + lcd_refresh = false; + if(portb & 1<setOffColor(FXRGB(150,200,152)); + else bmf->setOffColor(FXRGB(200,200,200)); - for(int x=0;xsetData (buf2,0); + bmp->render(); + bmf->setBitmap( bmp ); } - - bmp->setData (buf2,0); - bmp->render(); - bmf->setBitmap( bmp ); if(hasFocus()) { static FXuint keys1[]={ @@ -351,34 +351,22 @@ void Gruvin9xSim::refreshDiplay() } } -int state = 0; -void *init_function(void *) { +void *main_thread(void *) +{ g_menuStack[0] = menuMainView; g_menuStack[1] = menuProcModelSelect; + eeReadAll(); //load general setup and selected model - checkLowEEPROM(); //enough eeprom free? + doSplash(); + checkLowEEPROM(); checkTHR(); - checkSwitches(); //must be last - state = 2; - return 0; -} + checkSwitches(); + checkAlarm(); -long Gruvin9xSim::onChore(FXObject*,FXSelector,void*) -{ - pthread_t pid; - - refreshDiplay(); - - switch (state) { - case 0: - state = 1; - pthread_create(&pid, NULL, &init_function, NULL); - break; - case 2: - perMain(); - break; + while(1) { + perMain(); + usleep(1000); } - return 0; } @@ -397,8 +385,6 @@ int main(int argc,char **argv) } printf("eeprom = %s\n", eepromFile); - InitEepromThread(); - // Each FOX GUI program needs one, and only one, application object. // The application objects coordinates some common stuff shared between // all the widgets; for example, it dispatches events, keeps track of @@ -431,6 +417,11 @@ int main(int argc,char **argv) th9xSim->show(); // Otherwise the main window gets centred across my two monitors, split down the middle. #endif + InitEepromThread(); + + pthread_t pid; + pthread_create(&pid, NULL, &main_thread, NULL); + return application.run(); }