void Timer::step (std::string text) { stopTime(); stopMemory(); clock_t clickNb = eTime - iTime; time = ((float)clickNb)/CLOCKS_PER_SEC; memory = eMemory - iMemory; if (text != "") { std::cout << text << ": "; } std::cout << "STEP TIMER " << id << " (" << time << " sec, " << memory << " bytes)" << std::endl; iTime = clock(); iMemory = getMemory(); }
void doSteuerung(unsigned long* RfButtons) { union Ergomation_keys_t keys; static union Ergomation_keys_t lastKeys; // static unsigned char storePosKeyCount; // static unsigned char storeComfortKeyCount; static unsigned char nasKeyCount = 0; static unsigned char lastNasTaster; // static unsigned char lastMemKey = 0; // static unsigned char lastComfortMemKey = 0; // enum KeyState_t lastState; union MData_t mData; static union MData_t mDataCurrent; unsigned char i; unsigned char drive; int16_t lastMemPos[NUM_MEM_DRIVES]; //static signed char memoryStopped = 0; //static enum {none, memKeyPressed, memKeyStored} blinkMode; // static enum state_t currentState; // static enum usageMode_t oldSyncUsageMode = unknown; #ifdef USE_TIMECOUNT unsigned int lastTimePos1; unsigned int lastTimePos2; static signed char useTimer[2]; #if (NUM_DRIVES != 2) #error todo... #endif if (((driveState[0] == moveDown) || (driveState[0] == moveUp)) && (inRushTimer[0] == 0)) { if ((pulseTime[0] >= MIN_PULSE_TIME) // normal ist 16 oder 17.... || ((syncActive != 0) && (syncPulseTime[0] >= MIN_PULSE_TIME))) { useTimer[0] = -1; } else { useTimer[0] = 0; } } if (((driveState[1] == moveDown) || (driveState[1] == moveUp)) && (inRushTimer[1] == 0)) { if ((pulseTime[1] >= MIN_PULSE_TIME) // normal ist 16 oder 17.... || ((syncActive != 0) && (syncPulseTime[1] >= MIN_PULSE_TIME))) { useTimer[1] = -1; } else { useTimer[1] = 0; } } #endif #ifdef __ICCAVR__ TIMSK0 = 0; #else // TODO pr黤en welche IRQs tats鋍hlich abgeschaltet werden m黶sen... //__disable_irq(); #endif if (syncActive == 0) { keys.data = *RfButtons;//getRFbuttons(); } else { keys.data = syncKeysTransmitted; keys.data |= syncKeysReceived; }; if (btActive != 0) keys.data |= syncBtKeysReceived; /////////////////////////////////// moving ///////////////////////////////////// #if (NUM_DRIVES < 4) mData.data = 0; #endif mData.m1up = keys.m1up; mData.m1down = keys.m1down; mData.m2up = keys.m2up; mData.m2down = keys.m2down; #if (NUM_DRIVES >= 3) mData.m3up = keys.m3up; mData.m3down = keys.m3down; #endif #if (NUM_DRIVES >= 4) mData.m4up = keys.m4up; mData.m4down = keys.m4down; #endif /* if (keys.resetUp != 0) { mData.m1up = 1; mData.m2up = 1; mData.m3up = 1; mData.m4up = 1; }; */ if (/*(keys.resetDown != 0) || */(NAS_KEY == 0) || (allFlatTimer != 0)) { mData.m1down = 1; mData.m2down = 1; mData.m3down = 1; mData.m4down = 1; }; /////////////////////////////////// memory ///////////////////////////////////// memcpy(lastMemPos, memPos, sizeof(lastMemPos)); #ifdef USE_TIMECOUNT lastTimePos1 = timePos[0]; lastTimePos2 = timePos[1]; #endif #ifdef REPROGRAMMABLE_MEMORY_POSITIONS #ifdef USE_TIMECOUNT #error USE_TIMECOUNT wird nicht unterst姒涚─t! #endif #ifdef ZERO_G_ONLY #error ZERO_G_ONLY wird nicht unterst姒涚─t! #endif if (lastKeys.data != keys.data) { if ((keys.data != 0) && ((getMemoryActive() != 0) || (allFlatTimer != 0) || (automaticMovementIsActive != 0))) { stopMemory(); allFlatTimer = 0; memset((void *)syncTimeout, 0, sizeof(syncTimeout)); stopAll = active; memoryStopped = -1; } if ((keys.data & (KEY_MEMORY2 | KEY_MEMORY3 | KEY_MEMORY4)) != 0) { memTimer = MEM_STORE_DELAY; // Wartezeit f姒涳拷das Speichern setzen... blinkMode = none; } else if (keys.data != 0) { memTimer = 0; #ifndef NEW_TIMER_LED_STATUS blinkMode = none; #endif }; }; if (((keys.data & (KEY_ZERO_G | KEY_ALLFLAT)) == (KEY_ZERO_G | KEY_ALLFLAT)) && ((lastKeys.data & (KEY_ZERO_G | KEY_ALLFLAT)) != (KEY_ZERO_G | KEY_ALLFLAT))) { memoryStopped = -1; memTimer = MEM_RESTORE_DELAY; blinkMode = none; } if (((keys.data & (KEY_ZERO_G | KEY_ALLFLAT)) != (KEY_ZERO_G | KEY_ALLFLAT)) && ((lastKeys.data & (KEY_ZERO_G | KEY_ALLFLAT)) == (KEY_ZERO_G | KEY_ALLFLAT))) { memoryStopped = -1; memTimer = 0; #ifndef NEW_TIMER_LED_STATUS blinkMode = none; #endif } if (keys.data == 0) { memTimer = 0; #ifndef NEW_TIMER_LED_STATUS blinkMode = none; #endif }; if (memTimer == 1) { if ((keys.data & (KEY_ZERO_G | KEY_ALLFLAT)) == (KEY_ZERO_G | KEY_ALLFLAT)) { restoreMemory(1); restoreMemory(2); restoreMemory(3); } else { /* if (keys.zeroG != 0) { storeMemory(0); }; */ if (keys.memory2 != 0) { storeMemory(1); }; if (keys.memory3 != 0) { storeMemory(2); }; if (keys.memory4 != 0) { storeMemory(3); }; }; memTimer = 0; blinkMode = memKeyStored; blinkState = 0x2F; // 3 mal blinken... /* } else if ((memTimer < 150) && (memTimer > 1)) { blinkMode = memKeyPressed; */ }; if ((keys.data == 0) && (lastKeys.data != 0)) { if (memoryStopped != 0) { // nichts tun... } else if (lastKeys.zeroG != 0) { loadMemory(0); } else if (lastKeys.memory4 != 0) { loadMemory(3); } else if (lastKeys.memory3 != 0) { loadMemory(2); } else if (lastKeys.memory2 != 0) { loadMemory(1); } else if(lastKeys.angleAdjust != 0) { memPos[0] = syncBtpulseCounter[0]; memPos[1] = syncBtpulseCounter[1]; }else if (lastKeys.allFlat != 0) { allFlatTimer = 255; allFlatTimeoutTimer = 4000; // ca. 40 sekunden... //massageTimer = 0; //memset(massage_status, 0, sizeof(massage_status)); } else if (lastKeys.data != 0) { stopMemory(); allFlatTimer = 0; }; }; if (keys.data == 0) { memoryStopped = 0; }; #else // #ifdef REPROGRAMMABLE_MEMORY_POSITIONS if (lastKeys.data == 0) { if ((keys.data != 0) && ((getMemoryActive() != 0) || (allFlatTimer != 0) || (automaticMovementIsActive != 0))) { stopMemory(); allFlatTimer = 0; memset((void *)syncTimeout, 0, sizeof(syncTimeout)); stopAll = active; } else if (keys.zeroG != 0) { loadMemory(0); #ifdef USE_TIMECOUNT ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[0], sizeof(timePos)); #endif #ifndef ZERO_G_ONLY } else if (keys.memory4 != 0) { loadMemory(3); #ifdef USE_TIMECOUNT ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[3], sizeof(timePos)); #endif } else if (keys.memory3 != 0) { loadMemory(2); #ifdef USE_TIMECOUNT ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[2], sizeof(timePos)); #endif } else if (keys.memory2 != 0) { loadMemory(1); #ifdef USE_TIMECOUNT ee2memcpy((char*) timePos, (__eeprom char*)ee_timePosition[1], sizeof(timePos)); #endif #endif } else if(keys.angleAdjust != 0) { memPos[0] = syncBtpulseCounter[0]; memPos[1] = syncBtpulseCounter[1]; } else if (keys.allFlat != 0) { // if (lastKeys.data == 0) // { // if (allFlatTimer == 0) // { allFlatTimer = 255; #ifdef USE_TIMECOUNT allFlatTimeoutTimer = 3000; // ca. 30 sekunden... #else allFlatTimeoutTimer = 4000; // ca. 40 sekunden... #endif //massageTimer = 0; // MASSAGE_1 = 0; // MASSAGE_2 = 0; //memset(massage_status, 0, sizeof(massage_status)); // } else // { // allFlatTimer = 0; // }; // }; } else if (keys.data != 0) { stopMemory(); allFlatTimer = 0; }; }; #endif // #ifdef REPROGRAMMABLE_MEMORY_POSITIONS #ifdef LP_STYLE_FUNCTIONALITY if (ee_read_value(&ee_usageMode) != pressAndRelease) { if (keys.data == 0) { stopMemory(); allFlatTimer = 0; }; }; #endif #ifdef RAVEN if (ravenM3active == 0) { memPos[2] = MEM_OFF; } #endif // if(keys.angleAdjust != 0 && keys.angleAdjust == lastKeys.angleAdjust) // { // memPos[0] = syncBtpulseCounter[0][0]; // memPos[1] = syncBtpulseCounter[1][0]; //} if ((memcmp(lastMemPos, memPos, sizeof(memPos)) != 0) #ifdef USE_TIMECOUNT || (lastTimePos1 != timePos[0]) || (lastTimePos2 != timePos[1]) #endif ) { mDataCurrent.data = 0; }; for (i = 0; i < NUM_MEM_DRIVES; i++) { if (memPos[i] == MEM_OFF) { mDataCurrent.m1 = 0; } else { mData.m1 = 0; if (mDataCurrent.m1 == 0) { #ifdef USE_TIMECOUNT if (useTimer[i] != 0) { if (timePos[i] < timerCountGetCounter(i) - TIME_DIFF) mData.m1down = 1; if (timePos[i] > timerCountGetCounter(i) + TIME_DIFF) mData.m1up = 1; } else { if (memPos[i] < getPulseCounter(i) - POS_DIFF) mData.m1down = 1; if (memPos[i] > getPulseCounter(i) + POS_DIFF) mData.m1up = 1; } #else if (memPos[i] < getPulseCounter(i) - POS_DIFF) mData.m1down = 1; if (memPos[i] > getPulseCounter(i) + POS_DIFF) mData.m1up = 1; #endif mDataCurrent.m1 = mData.m1; moveToTimer[i] = 255; } else { mData.m1 = mDataCurrent.m1; #ifdef USE_TIMECOUNT if (useTimer[i] != 0) { if (timePos[i] >= timerCountGetCounter(i)) mData.m1down = 0; if (timePos[i] <= timerCountGetCounter(i)) mData.m1up = 0; moveToTimer[i] = ALL_FLAT_PULSE_TIMEOUT; } else { if (memPos[i] >= getPulseCounter(i)) mData.m1down = 0; if (memPos[i] <= getPulseCounter(i)) mData.m1up = 0; if ((pulseTime[i] < PULSE_TIMEOUT) || (driveState[i] == waitUp) || (driveState[i] == waitDown)) moveToTimer[i] = ALL_FLAT_PULSE_TIMEOUT; } #else if (memPos[i] >= getPulseCounter(i)) mData.m1down = 0; if (memPos[i] <= getPulseCounter(i)) mData.m1up = 0; if ((pulseTime[i] < PULSETIME_MAX_VALUE) || (driveState[i] == waitUp) || (driveState[i] == waitDown)) moveToTimer[i] = ALL_FLAT_PULSE_TIMEOUT; #endif } if (mData.m1 == 0) { memPos[i] = MEM_OFF; } } if (moveToTimer[i] == 0) { memPos[i ] = MEM_OFF; }; mData.data >>= 2; mDataCurrent.data >>= 2; } mData.data <<= (2 * NUM_MEM_DRIVES); mDataCurrent.data <<= (2 * NUM_MEM_DRIVES); if ((keys.data == 0) && (stopAll != inactive)) { stopAll = setInactive; }; if (stopAll != inactive) { stopMemory(); allFlatTimer = 0; memset((void *)syncTimeout, 0, sizeof(syncTimeout)); mData.data = 0; keys.data = 0; }; if (stopAll == setInactive) stopAll = inactive; /////////////////////////////////// massage //////////////////////////////////// /////////////////////////////////// teach-mode ///////////////////////////////// if (keys.data != 0) nasKeyCount = 0; if ((NAS_KEY == 0) && (lastNasTaster != 0)) { strgKeyTimer = KEY_TIMEOUT; if (getTeachMode()) clrTeachMode(); } if ((NAS_KEY != 0) && (lastNasTaster == 0) && (strgKeyTimer != 0)) { nasKeyCount++; strgKeyTimer = KEY_TIMEOUT; switch (nasKeyCount) { case 2: setTeachMode(); break; /* case 3: clrTeachMode(); break; case 4: UBB = 1; break; case 5: nrf_genRandomAddress(); UBB = 0; nasKeyCount = 0; break; */ }; }; lastNasTaster = NAS_KEY; /////////////////////////////////// misc... //////////////////////////////////// if (allFlatTimeoutTimer == 0) { allFlatTimer = 0; }; if ((allFlatTimer != 0) && ((getPulseCounter(0) != 0) || (getPulseCounter(1) != 0) #if (NUM_DRIVES >= 3) || (getPulseCounter(2) != 0) #endif #if (NUM_DRIVES >= 4) || (getPulseCounter(3) != 0) #endif #ifdef USE_TIMECOUNT || (timerCountGetCounter(0) != TIMERCOUNTER_RESETVALUE) || (timerCountGetCounter(1) != TIMERCOUNTER_RESETVALUE) #endif )) { allFlatTimer = ALL_FLAT_PULSE_TIMEOUT; }; if (((keys.ubb != 0) && (lastKeys.ubb == 0)) )// || ((keys.m1up != 0) && (keys.m1down != 0) && ((lastKeys.m1up == 0) || (lastKeys.m1down == 0)))) { //UBB = ~UBB; UBB_toggle(); }; lastKeys.data = keys.data; if (strgKeyTimer == 0) { // storePosKeyCount = 0; // storeComfortKeyCount = 0; // updateLEDs(none); if (nasKeyCount == 4) { //UBB = 0; UBB_disable(); } nasKeyCount = 0; }; /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////// for (drive = 0; drive < NUM_DRIVES; drive++) { if ((mData.m1up != 0) && (mData.m1down == 0)) { setPWMup(drive,255); syncTimeout[drive] = SYNC_TIMEOUT; } else if ((mData.m1up == 0) && (mData.m1down != 0)) { setPWMdown(drive,255); syncTimeout[drive] = SYNC_TIMEOUT; } else { //setPWMdown(0,0); #ifndef NO_SYNC if ((syncActive == 0) || (syncTimeout[drive] == 0) //同步超时1.5S || (pulseTime[drive] >= PULSETIME_MAX_VALUE) //驱动器到两端,电流为0 // || (stopAll != inactive) #ifdef USE_TIMECOUNT || ((useTimer[drive] != 0) && !((driveDirection[drive] == moving_down) && (timeCounterSync[drive] < (timerCountGetCounter(drive) - SYNC_OFFSET))) && !((driveDirection[drive] == moving_up) && (timeCounterSync[drive] > (timerCountGetCounter(drive) + SYNC_OFFSET)))) || ((useTimer[drive] == 0) && !((driveDirection[drive] == moving_down) && (pulseCounterSync[drive] < (getPulseCounter(drive) - SYNC_OFFSET))) && !((driveDirection[drive] == moving_up) && (pulseCounterSync[drive] > (getPulseCounter(drive) + SYNC_OFFSET))))) #else || (!((driveDirection[drive] == moving_down) && (pulseCounterSync[drive] < (getPulseCounter(drive) - SYNC_OFFSET))) && !((driveDirection[drive] == moving_up) && (pulseCounterSync[drive] > (getPulseCounter(drive) + SYNC_OFFSET))))) #endif #endif { setPWMdown(drive,0); } }; mData.data >>= 2; } mData.data = 0; }