From 10265a90ca1c124fbee1be231476bde1347dea42 Mon Sep 17 00:00:00 2001 From: bsongis Date: Tue, 24 Jul 2012 15:11:00 +0000 Subject: [PATCH] New curves system (XCURVES Makefile option) SmartieParts board v2.2 support (SP22 Makefile option) --- src/Makefile | 16 +++- src/eeprom_arm.cpp | 2 +- src/eeprom_avr.cpp | 17 ++-- src/eeprom_avr.h | 1 - src/frsky.cpp | 2 +- src/general_menus.cpp | 1 + src/lcd.cpp | 2 +- src/model_menus.cpp | 205 ++++++++++++++++++++++++++++++++++++++++-- src/myeeprom.h | 22 ++++- src/open9x.cpp | 75 +++++++++++++++- src/open9x.h | 30 +++++++ src/templates.cpp | 13 +-- src/translations.cpp | 2 + src/translations.h | 6 ++ 14 files changed, 360 insertions(+), 34 deletions(-) diff --git a/src/Makefile b/src/Makefile index 3112903cc..acb9e79d8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -59,6 +59,9 @@ AUDIO = NO # Values = YES, NO HAPTIC = NO +# SmartieParts 2.2 Backlight support (inverted) +SP22 = NO + # SPLASH on START SPLASH = YES @@ -140,6 +143,10 @@ DEBUG = NO # Values = YES, NO FLIGHT_PHASES = YES +# Customizable Curves +# Values = YES, NO +XCURVES = YES + #------- END BUILD OPTIONS --------------------------- # Define programs and commands. @@ -154,6 +161,7 @@ ifeq ($(PCB), STD) TRGT = avr- MCU = atmega64 CPPDEFS += -DF_CPU=$(F_CPU)UL + XCURVES = NO endif ifeq ($(PCB), V4) @@ -277,6 +285,10 @@ ifeq ($(FLIGHT_PHASES), YES) CPPDEFS += -DFLIGHT_PHASES endif +ifeq ($(XCURVES), YES) + CPPDEFS += -DXCURVES +endif + # If STD-Support is enabled ifeq ($(EXT), STD) CPPDEFS += -DEXTSTD @@ -382,7 +394,6 @@ ifeq ($(PCB), V4) CPPDEFS += -DEXTRA_ROTARY_ENCODERS MODS:=${MODS}X endif - endif ifeq ($(PCB), STD) @@ -406,6 +417,9 @@ ifeq ($(PCB), STD) CPPSRC += haptic.cpp endif + ifeq ($(SP22), YES) + CPPDEFS += -DSP22 + endif endif ### Global Build-Option Directives ### diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index ffcde9913..757026013 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -448,7 +448,7 @@ bool ee32LoadGeneral() read32_eeprom_data( ( File_system[0].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&g_eeGeneral, size) ; } - if (g_eeGeneral.myVers == EEPROM_VER) { + if (g_eeGeneral.myVers == EEPROM_VER && g_eeGeneral.variants == EEPROM_VARIANTS) { uint16_t sum = evalChkSum(); if (g_eeGeneral.chkSum == sum) { return true; diff --git a/src/eeprom_avr.cpp b/src/eeprom_avr.cpp index ae38fa07b..4ca339850 100644 --- a/src/eeprom_avr.cpp +++ b/src/eeprom_avr.cpp @@ -186,7 +186,7 @@ int8_t EeFsck() s_sync_write = true; uint8_t *bufp = reusableBuffer.eefs_buffer; - memset(bufp, 0, BLOCKS); + memclear(bufp, BLOCKS); uint8_t blk ; int8_t ret = 0; @@ -232,7 +232,7 @@ void EeFsFormat() { s_sync_write = true; - memset(&eeFs,0, sizeof(eeFs)); + memclear(&eeFs, sizeof(eeFs)); eeFs.version = EEFS_VERS; eeFs.mySize = sizeof(eeFs); eeFs.freeList = 0; @@ -245,7 +245,7 @@ void EeFsFormat() s_sync_write = false; } -bool EeFsOpen() // TODO inline? +inline bool EeFsOpen() // TODO inline? { eeprom_read_block(&eeFs, 0, sizeof(eeFs)); @@ -286,7 +286,7 @@ void EFile::swap(uint8_t i_fileId1, uint8_t i_fileId2) void EFile::rm(uint8_t i_fileId) { uint8_t i = eeFs.files[i_fileId].startBlk; - memset(&eeFs.files[i_fileId], 0, sizeof(eeFs.files[i_fileId])); + memclear(&eeFs.files[i_fileId], sizeof(eeFs.files[i_fileId])); s_sync_write = true; EeFsFlushDirEnt(i_fileId); if (i) EeFsFree(i); //chain in @@ -343,13 +343,13 @@ uint8_t EFile::read(uint8_t*buf,uint16_t i_len) #ifdef TRANSLATIONS uint16_t RlcFile::readRlc12(uint8_t*buf,uint16_t i_len, bool rlc2) #else -uint16_t RlcFile::readRlc(uint8_t*buf,uint16_t i_len) +uint16_t RlcFile::readRlc(uint8_t *buf,uint16_t i_len) #endif { uint16_t i=0; for( ; 1; ){ uint8_t l=min(m_zeroes,i_len-i); - memset(&buf[i],0,l); + memclear(&buf[i], l); i += l; m_zeroes -= l; if(m_zeroes) break; @@ -801,8 +801,7 @@ bool eeLoadGeneral() if (theFile.readRlc((uint8_t*)&g_eeGeneral, 1) == 1 && g_eeGeneral.myVers == EEPROM_VER) { theFile.openRlc(FILE_GENERAL); // TODO include this openRlc inside readRlc if (theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)) <= sizeof(EEGeneral)) { - uint16_t sum = evalChkSum(); - if (g_eeGeneral.chkSum == sum) { + if (g_eeGeneral.variants == EEPROM_VARIANTS && g_eeGeneral.chkSum == evalChkSum()) { return true; } } @@ -813,7 +812,7 @@ bool eeLoadGeneral() uint16_t eeLoadModelName(uint8_t id, char *name) { - memset(name, 0, sizeof(g_model.name)); + memclear(name, sizeof(g_model.name)); if (id='1' && c<='3') ln++; diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 6beffd0bb..5db974b01 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -167,7 +167,7 @@ bool listSdFiles(const char *path, const char *extension) break; } char *menu_entry = &s_bss_menu[s_menu_count*MENU_LINE_LENGTH]; - memset(menu_entry, 0, MENU_LINE_LENGTH); + memclear(menu_entry, MENU_LINE_LENGTH); for (uint8_t i=0; i 0 && IS_DSM2_PROTOCOL(protocol)) @@ -1093,6 +1092,155 @@ void DrawCurve(FnFuncP fn) } } +#if defined(XCURVES) +bool moveCurve(uint8_t index, int8_t shift, int8_t custom=0) +{ + if (g_model.curves[MAX_CURVES-1] + shift > NUM_POINTS-5*MAX_CURVES) { + AUDIO_WARNING2(); + return false; + } + + int8_t *crv = curveaddress(index); + if (shift < 0) { + for (uint8_t i=0; i0 && m_posHorz 4) + m_posHorz = -4; + for (uint8_t i=0; i0) { + if (--s_editMode == 0) + m_posHorz = 0; + } + else + popMenu(); + break; + case EVT_KEY_REPT(KEY_LEFT): + case EVT_KEY_FIRST(KEY_LEFT): + if (s_editMode==1 && m_posHorz>0) m_posHorz--; + if (s_editMode==0) { + if (crv.custom) { + moveCurve(s_curveChan, -crv.points+2); + } + else if (crv.points > MIN_POINTS) { + moveCurve(s_curveChan, -1, (crv.points+1)/2); + } + else { + AUDIO_WARNING2(); + } + return; + } + break; + case EVT_KEY_REPT(KEY_RIGHT): + case EVT_KEY_FIRST(KEY_RIGHT): + if (s_editMode==1 && m_posHorz<(crv.points-1)) m_posHorz++; + if (s_editMode==0) { + if (!crv.custom) { + moveCurve(s_curveChan, crv.points-2, crv.points); + } + else if (crv.points < MAX_POINTS) { + if (moveCurve(s_curveChan, 1)) { + for (int8_t i=crv.points+crv.points-2; i>=0; i--) { + if (i%2) + crv.crv[i] = (crv.crv[i/2] + crv.crv[1+i/2]) / 2; + else + crv.crv[i] = crv.crv[i/2]; + } + } + } + else { + AUDIO_WARNING2(); + } + } + break; + } + + lcd_putsLeft(7*FH, PSTR("Type")); + uint8_t attr = (s_editMode==0 ? INVERS : 0); + lcd_outdezAtt(5*FW-2, 7*FH, crv.points, LEFT|attr); + lcd_putsAtt(lcdLastPos, 7*FH, crv.custom ? PSTR("pt'") : PSTR("pt"), attr); + + for (uint8_t i=0; i0 && i0 && m_posHorz==i) { + if (s_editMode==1 || !BLINK_ON_PHASE) lcd_filled_rect(xx-1, yy-2, 5, 5); // do selection square + + int8_t x = -100 + 200*i/(crv.points-1); + if (crv.custom && i>0 && i FORCEINLINE t abs(t a) { return a>0?a:-a; } /// liefert das Minimum der Argumente @@ -789,6 +811,14 @@ extern MixData *mixaddress(uint8_t idx); extern LimitData *limitaddress(uint8_t idx); extern int8_t *curveaddress(uint8_t idx); extern CustomSwData *cswaddress(uint8_t idx); +#if defined(XCURVES) +struct CurveInfo { + int8_t *crv; + uint8_t points; + bool custom; +}; +extern CurveInfo curveinfo(uint8_t idx); +#endif extern void deleteExpoMix(uint8_t expo, uint8_t idx); diff --git a/src/templates.cpp b/src/templates.cpp index 34ab5e31d..4b5fba07b 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -77,7 +77,7 @@ MixData* setDest(uint8_t dch, uint8_t src, bool clear=false) } memmove(mix+1, mix, (MAX_MIXERS-(i+1))*sizeof(MixData) ); - memset(mix,0,sizeof(MixData)); + memclear(mix, sizeof(MixData)); mix->destCh = dch; mix->srcRaw = src; mix->weight = 100; @@ -86,20 +86,23 @@ MixData* setDest(uint8_t dch, uint8_t src, bool clear=false) void clearMixes() { - memset(g_model.mixData, 0, sizeof(g_model.mixData)); //clear all mixes + memset(g_model.mixData, 0, sizeof(g_model.mixData)); // clear all mixes STORE_MODELVARS; } void clearCurves() { - memset(g_model.curves5, 0, sizeof(g_model.curves5)); //clear all curves - memset(g_model.curves9, 0, sizeof(g_model.curves9)); //clear all curves +#if defined(XCURVES) + memclear(g_model.curves, sizeof(g_model.curves) + sizeof(g_model.points)); // clear all curves +#else + memclear(g_model.curves5, sizeof(g_model.curves5) + sizeof(g_model.curves9)); // clear all curves +#endif } void setCurve(uint8_t c, const pm_int8_t ar[]) { int8_t * cv = curveaddress(c); - for (uint8_t i=0; i<(c