Add basic LAMP functionality; Fix comments
- Basic lamp functionality: simply turn on when not in COUNTING or TARGET_REACHED
    state
- Remove unnecessary comments, fix code formatting in several files
			
			
This commit is contained in:
		
							parent
							
								
									2cf1762569
								
							
						
					
					
						commit
						5b49406cb8
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -24,7 +24,6 @@ QueueHandle_t init_encoder(rotary_encoder_info_t * info){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
//====================
 | 
					//====================
 | 
				
			||||||
//==== variables =====
 | 
					//==== variables =====
 | 
				
			||||||
//====================
 | 
					//====================
 | 
				
			||||||
@ -63,7 +62,7 @@ bool autoCutEnabled = false; //store state of toggle switch (no hotswitch)
 | 
				
			|||||||
//function for changing the controlState with log output
 | 
					//function for changing the controlState with log output
 | 
				
			||||||
void changeState (systemState_t stateNew) {
 | 
					void changeState (systemState_t stateNew) {
 | 
				
			||||||
    //only proceed when state actually changed
 | 
					    //only proceed when state actually changed
 | 
				
			||||||
    if (controlState == stateNew){
 | 
					    if (controlState == stateNew) {
 | 
				
			||||||
        return; //already at target state -> nothing to do
 | 
					        return; //already at target state -> nothing to do
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //log change
 | 
					    //log change
 | 
				
			||||||
@ -73,7 +72,8 @@ void changeState (systemState_t stateNew) {
 | 
				
			|||||||
    //update timestamp
 | 
					    //update timestamp
 | 
				
			||||||
    timestamp_changedState = esp_log_timestamp();
 | 
					    timestamp_changedState = esp_log_timestamp();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
                      
 | 
					          
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//===== handle Stop Condition =====
 | 
					//===== handle Stop Condition =====
 | 
				
			||||||
//function that checks whether start button is released or target is reached (used in multiple states)
 | 
					//function that checks whether start button is released or target is reached (used in multiple states)
 | 
				
			||||||
@ -120,7 +120,7 @@ void setDynSpeedLvl(uint8_t lvlMax = 3){
 | 
				
			|||||||
        lvl = 3;
 | 
					        lvl = 3;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //limit to max lvl
 | 
					    //limit to max lvl
 | 
				
			||||||
    if (lvl > lvlMax){
 | 
					    if (lvl > lvlMax) {
 | 
				
			||||||
        lvl = lvlMax;
 | 
					        lvl = lvlMax;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //update vfd speed level
 | 
					    //update vfd speed level
 | 
				
			||||||
@ -182,15 +182,12 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
        // Poll current position and direction
 | 
					        // Poll current position and direction
 | 
				
			||||||
        rotary_encoder_get_state(&encoder, &encoderState);
 | 
					        rotary_encoder_get_state(&encoder, &encoderState);
 | 
				
			||||||
        //--- calculate distance ---
 | 
					        //--- calculate distance ---
 | 
				
			||||||
        //lengthNow = (float)encoderState.position * (MEASURING_ROLL_DIAMETER * PI) / 600; //TODO dont calculate constant factor every time FIXME: ROUNDING ISSUE float-int?
 | 
					 | 
				
			||||||
        lengthNow = (float)encoderState.position * 1000 / STEPS_PER_METER;
 | 
					        lengthNow = (float)encoderState.position * 1000 / STEPS_PER_METER;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //---------------------------
 | 
					        //---------------------------
 | 
				
			||||||
        //--------- buttons ---------
 | 
					        //--------- buttons ---------
 | 
				
			||||||
        //---------------------------
 | 
					        //---------------------------
 | 
				
			||||||
        //TODO: ADD PRESET SWITCHES HERE
 | 
					 | 
				
			||||||
        //--- RESET switch ---
 | 
					        //--- RESET switch ---
 | 
				
			||||||
        if (SW_RESET.risingEdge) {
 | 
					        if (SW_RESET.risingEdge) {
 | 
				
			||||||
            rotary_encoder_reset(&encoder);
 | 
					            rotary_encoder_reset(&encoder);
 | 
				
			||||||
@ -200,7 +197,6 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
            //cutter_stop();
 | 
					            //cutter_stop();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        //--- CUT switch ---
 | 
					        //--- CUT switch ---
 | 
				
			||||||
        //start cut cycle immediately
 | 
					        //start cut cycle immediately
 | 
				
			||||||
        if (SW_CUT.risingEdge) {
 | 
					        if (SW_CUT.risingEdge) {
 | 
				
			||||||
@ -217,14 +213,13 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            //error cant cut while motor is on
 | 
					            //error cant cut while motor is on
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
                buzzer.beep(6, 70, 50);
 | 
					                buzzer.beep(6, 100, 50);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
       
 | 
					       
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //--- AUTO_CUT toggle sw ---
 | 
					        //--- AUTO_CUT toggle sw ---
 | 
				
			||||||
        //beep at change
 | 
					        //beep at change
 | 
				
			||||||
        if (SW_AUTO_CUT.risingEdge){
 | 
					        if (SW_AUTO_CUT.risingEdge) {
 | 
				
			||||||
            buzzer.beep(2, 100, 50);
 | 
					            buzzer.beep(2, 100, 50);
 | 
				
			||||||
        } else if (SW_AUTO_CUT.fallingEdge) {
 | 
					        } else if (SW_AUTO_CUT.fallingEdge) {
 | 
				
			||||||
            buzzer.beep(1, 400, 50);
 | 
					            buzzer.beep(1, 400, 50);
 | 
				
			||||||
@ -233,7 +228,7 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
        if (SW_AUTO_CUT.state) {
 | 
					        if (SW_AUTO_CUT.state) {
 | 
				
			||||||
            //enable autocut when not in target_reached state
 | 
					            //enable autocut when not in target_reached state
 | 
				
			||||||
            //(prevent immediate/unexpected cut)
 | 
					            //(prevent immediate/unexpected cut)
 | 
				
			||||||
            if (controlState != systemState_t::TARGET_REACHED){
 | 
					            if (controlState != systemState_t::TARGET_REACHED) {
 | 
				
			||||||
                autoCutEnabled = true;
 | 
					                autoCutEnabled = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
@ -241,7 +236,6 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
            autoCutEnabled = false;
 | 
					            autoCutEnabled = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //--- manual mode ---
 | 
					        //--- manual mode ---
 | 
				
			||||||
        //switch to manual motor control (2 buttons + poti)
 | 
					        //switch to manual motor control (2 buttons + poti)
 | 
				
			||||||
        if ( SW_PRESET2.state && (SW_PRESET1.state || SW_PRESET3.state) && controlState != systemState_t::MANUAL ) {
 | 
					        if ( SW_PRESET2.state && (SW_PRESET1.state || SW_PRESET3.state) && controlState != systemState_t::MANUAL ) {
 | 
				
			||||||
@ -250,7 +244,6 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
            buzzer.beep(3, 100, 60);
 | 
					            buzzer.beep(3, 100, 60);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //--- set custom target length ---
 | 
					        //--- set custom target length ---
 | 
				
			||||||
        //set target length to poti position when SET switch is pressed
 | 
					        //set target length to poti position when SET switch is pressed
 | 
				
			||||||
        if (SW_SET.state == true) {
 | 
					        if (SW_SET.state == true) {
 | 
				
			||||||
@ -289,7 +282,7 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        //--- target length presets ---
 | 
					        //--- target length presets ---
 | 
				
			||||||
        if (controlState != systemState_t::MANUAL) { //dont apply preset length while controlling motor with preset buttons
 | 
					        if (controlState != systemState_t::MANUAL) { //dont apply preset length while controlling motor with preset buttons
 | 
				
			||||||
            if (SW_PRESET1.risingEdge){
 | 
					            if (SW_PRESET1.risingEdge) {
 | 
				
			||||||
                lengthTarget = 1000;
 | 
					                lengthTarget = 1000;
 | 
				
			||||||
                buzzer.beep(lengthTarget/1000, 25, 30);
 | 
					                buzzer.beep(lengthTarget/1000, 25, 30);
 | 
				
			||||||
                displayBot.blink(3, 100, 100, "S0LL    ");
 | 
					                displayBot.blink(3, 100, 100, "S0LL    ");
 | 
				
			||||||
@ -318,11 +311,10 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
        switch (controlState) {
 | 
					        switch (controlState) {
 | 
				
			||||||
            case systemState_t::COUNTING: //no motor action
 | 
					            case systemState_t::COUNTING: //no motor action
 | 
				
			||||||
                vfd_setState(false);
 | 
					                vfd_setState(false);
 | 
				
			||||||
                //TODO check stop condition before starting - prevents motor from starting 2 cycles when 
 | 
					                //TODO check stop condition before starting - prevents motor from starting 2 cycles when already at target
 | 
				
			||||||
                //--- start winding to length ---
 | 
					                //--- start winding to length ---
 | 
				
			||||||
                if (SW_START.risingEdge) {
 | 
					                if (SW_START.risingEdge) {
 | 
				
			||||||
                    changeState(systemState_t::WINDING_START);
 | 
					                    changeState(systemState_t::WINDING_START);
 | 
				
			||||||
                    //TODO apply dynamic speed here too (if started when already very close)
 | 
					 | 
				
			||||||
                    vfd_setSpeedLevel(1); //start at low speed 
 | 
					                    vfd_setSpeedLevel(1); //start at low speed 
 | 
				
			||||||
                    vfd_setState(true); //start motor
 | 
					                    vfd_setState(true); //start motor
 | 
				
			||||||
                    timestamp_motorStarted = esp_log_timestamp(); //save time started
 | 
					                    timestamp_motorStarted = esp_log_timestamp(); //save time started
 | 
				
			||||||
@ -341,10 +333,10 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case systemState_t::WINDING: //wind fast, slow down when close
 | 
					            case systemState_t::WINDING: //wind fast, slow down when close
 | 
				
			||||||
                                         //set vfd speed depending on remaining distance 
 | 
					                //set vfd speed depending on remaining distance 
 | 
				
			||||||
                setDynSpeedLvl(); //slow down when close to target
 | 
					                setDynSpeedLvl(); //slow down when close to target
 | 
				
			||||||
                handleStopCondition(&displayTop, &displayBot); //stops if button released or target reached
 | 
					                handleStopCondition(&displayTop, &displayBot); //stops if button released or target reached
 | 
				
			||||||
                                                               //TODO: cancel when there is no cable movement anymore e.g. empty / timeout?
 | 
					                //TODO: cancel when there is no cable movement anymore e.g. empty / timeout?
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case systemState_t::TARGET_REACHED:
 | 
					            case systemState_t::TARGET_REACHED:
 | 
				
			||||||
@ -355,14 +347,14 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                //switch initiate countdown to auto-cut
 | 
					                //switch initiate countdown to auto-cut
 | 
				
			||||||
                else if ( (autoCutEnabled)
 | 
					                else if ( (autoCutEnabled)
 | 
				
			||||||
                        && (esp_log_timestamp() - timestamp_changedState > 300) ){ //wait for dislay msg "reached" to finish
 | 
					                        && (esp_log_timestamp() - timestamp_changedState > 300) ) { //wait for dislay msg "reached" to finish
 | 
				
			||||||
                    changeState(systemState_t::AUTO_CUT_WAITING);
 | 
					                    changeState(systemState_t::AUTO_CUT_WAITING);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                //show msg when trying to start, but target is reached
 | 
					                //show msg when trying to start, but target is reached
 | 
				
			||||||
                if (SW_START.risingEdge){
 | 
					                if (SW_START.risingEdge) {
 | 
				
			||||||
                    buzzer.beep(3, 40, 30);
 | 
					                    buzzer.beep(2, 50, 30);
 | 
				
			||||||
                    displayTop.blink(2, 600, 800, "  S0LL  ");
 | 
					                    displayTop.blink(2, 600, 500, "  S0LL  ");
 | 
				
			||||||
                    displayBot.blink(2, 600, 800, "ERREICHT");
 | 
					                    displayBot.blink(2, 600, 500, "ERREICHT");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -370,18 +362,18 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
                //handle delayed start of cut
 | 
					                //handle delayed start of cut
 | 
				
			||||||
                cut_msRemaining = autoCut_delayMs - (esp_log_timestamp() - timestamp_changedState);
 | 
					                cut_msRemaining = autoCut_delayMs - (esp_log_timestamp() - timestamp_changedState);
 | 
				
			||||||
                //- countdown stop conditions -
 | 
					                //- countdown stop conditions -
 | 
				
			||||||
                if (!autoCutEnabled || !SW_AUTO_CUT.state || SW_RESET.state || SW_CUT.state){ //TODO: also stop when target not reached anymore?
 | 
					                if (!autoCutEnabled || !SW_AUTO_CUT.state || SW_RESET.state || SW_CUT.state) { //TODO: also stop when target not reached anymore?
 | 
				
			||||||
                    changeState(systemState_t::COUNTING);
 | 
					                    changeState(systemState_t::COUNTING);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                //- trigger cut if delay passed -
 | 
					                //- trigger cut if delay passed -
 | 
				
			||||||
                else if (cut_msRemaining <= 0){
 | 
					                else if (cut_msRemaining <= 0) {
 | 
				
			||||||
                    cutter_start();
 | 
					                    cutter_start();
 | 
				
			||||||
                    changeState(systemState_t::CUTTING);
 | 
					                    changeState(systemState_t::CUTTING);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                //- beep countdown -
 | 
					                //- beep countdown -
 | 
				
			||||||
                //time passed since last beep  >  time remaining / 6
 | 
					                //time passed since last beep  >  time remaining / 6
 | 
				
			||||||
                else if ( (esp_log_timestamp() - timestamp_cut_lastBeep)  > (cut_msRemaining / 6)
 | 
					                else if ( (esp_log_timestamp() - timestamp_cut_lastBeep)  > (cut_msRemaining / 6)
 | 
				
			||||||
                        && (esp_log_timestamp() - timestamp_cut_lastBeep) > 50 ){ //dont trigger beeps faster than beep time
 | 
					                        && (esp_log_timestamp() - timestamp_cut_lastBeep) > 50 ) { //dont trigger beeps faster than beep time
 | 
				
			||||||
                    buzzer.beep(1, 50, 0);
 | 
					                    buzzer.beep(1, 50, 0);
 | 
				
			||||||
                    timestamp_cut_lastBeep = esp_log_timestamp();
 | 
					                    timestamp_cut_lastBeep = esp_log_timestamp();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -389,7 +381,7 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            case systemState_t::CUTTING:
 | 
					            case systemState_t::CUTTING:
 | 
				
			||||||
                //exit when finished cutting
 | 
					                //exit when finished cutting
 | 
				
			||||||
                if (cutter_isRunning() == false){
 | 
					                if (cutter_isRunning() == false) {
 | 
				
			||||||
                    //TODO stop if start buttons released?
 | 
					                    //TODO stop if start buttons released?
 | 
				
			||||||
                    changeState(systemState_t::COUNTING);
 | 
					                    changeState(systemState_t::COUNTING);
 | 
				
			||||||
                    //TODO reset automatically or wait for manual reset?
 | 
					                    //TODO reset automatically or wait for manual reset?
 | 
				
			||||||
@ -411,14 +403,14 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                //P2 + P1 -> turn left
 | 
					                //P2 + P1 -> turn left
 | 
				
			||||||
                else if ( SW_PRESET1.state && !SW_PRESET3.state ) {
 | 
					                else if ( SW_PRESET1.state && !SW_PRESET3.state ) {
 | 
				
			||||||
                    vfd_setSpeedLevel(level); //TODO: use poti input for level
 | 
					                    vfd_setSpeedLevel(level);
 | 
				
			||||||
                    vfd_setState(true, REV);
 | 
					                    vfd_setState(true, REV);
 | 
				
			||||||
                    sprintf(buf_disp2, "[--%02i   ", level);
 | 
					                    sprintf(buf_disp2, "[--%02i   ", level);
 | 
				
			||||||
                    //                  123 45 678
 | 
					                    //                  123 45 678
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                //P2 + P3 -> turn right
 | 
					                //P2 + P3 -> turn right
 | 
				
			||||||
                else if ( SW_PRESET3.state && !SW_PRESET1.state ) {
 | 
					                else if ( SW_PRESET3.state && !SW_PRESET1.state ) {
 | 
				
			||||||
                    vfd_setSpeedLevel(level); //TODO: use poti input for level
 | 
					                    vfd_setSpeedLevel(level);
 | 
				
			||||||
                    vfd_setState(true, FWD);
 | 
					                    vfd_setState(true, FWD);
 | 
				
			||||||
                    sprintf(buf_disp2, "   %02i--]", level);
 | 
					                    sprintf(buf_disp2, "   %02i--]", level);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -461,7 +453,7 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
        //run handle function
 | 
					        //run handle function
 | 
				
			||||||
        displayTop.handle();
 | 
					        displayTop.handle();
 | 
				
			||||||
        //indicate upcoming cut when pending
 | 
					        //indicate upcoming cut when pending
 | 
				
			||||||
        if (controlState == systemState_t::AUTO_CUT_WAITING){
 | 
					        if (controlState == systemState_t::AUTO_CUT_WAITING) {
 | 
				
			||||||
            displayTop.blinkStrings(" CUT 1N ", "        ", 70, 30);
 | 
					            displayTop.blinkStrings(" CUT 1N ", "        ", 70, 30);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //otherwise show current position
 | 
					        //otherwise show current position
 | 
				
			||||||
@ -493,7 +485,7 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
            displayBot.blinkStrings("CUTTING]", "CUTTING[", 100, 100);
 | 
					            displayBot.blinkStrings("CUTTING]", "CUTTING[", 100, 100);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //show ms countdown to cut when pending
 | 
					        //show ms countdown to cut when pending
 | 
				
			||||||
        else if (controlState == systemState_t::AUTO_CUT_WAITING){
 | 
					        else if (controlState == systemState_t::AUTO_CUT_WAITING) {
 | 
				
			||||||
            sprintf(buf_disp2, "  %04d  ", cut_msRemaining);
 | 
					            sprintf(buf_disp2, "  %04d  ", cut_msRemaining);
 | 
				
			||||||
            //displayBot.showString(buf_disp2); //TODO:blink "erreicht" overrides this. for now using blink as workaround
 | 
					            //displayBot.showString(buf_disp2); //TODO:blink "erreicht" overrides this. for now using blink as workaround
 | 
				
			||||||
            displayBot.blinkStrings(buf_disp2, buf_disp2, 100, 100);
 | 
					            displayBot.blinkStrings(buf_disp2, buf_disp2, 100, 100);
 | 
				
			||||||
@ -507,13 +499,25 @@ void task_control(void *pvParameter)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //----------------------------
 | 
				
			||||||
 | 
					        //------- control lamp -------
 | 
				
			||||||
 | 
					        //----------------------------
 | 
				
			||||||
 | 
					        //basic functionality of lamp:
 | 
				
			||||||
 | 
					        //turn on when not idling
 | 
				
			||||||
 | 
					        //TODO: add switch-case for different sates
 | 
				
			||||||
 | 
					        //e.g. blink with different frequencies in different states
 | 
				
			||||||
 | 
					        if (controlState != systemState_t::COUNTING
 | 
				
			||||||
 | 
					                && controlState != systemState_t::TARGET_REACHED) {
 | 
				
			||||||
 | 
					            gpio_set_level(GPIO_LAMP, 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            gpio_set_level(GPIO_LAMP, 0);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        //TODO: blink disp2 when set button pressed
 | 
					 | 
				
			||||||
        //TODO: blink disp2 when preset button pressed (exept manual mode)
 | 
					 | 
				
			||||||
        //TODO: write "MAN CTL" to disp2 when in manual mode
 | 
					 | 
				
			||||||
        //TODO: display or blink "REACHED" when reached state and start pressed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -26,8 +26,10 @@ extern "C"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//enum describing the state of the system
 | 
				
			||||||
enum class systemState_t {COUNTING, WINDING_START, WINDING, TARGET_REACHED, AUTO_CUT_WAITING, CUTTING, MANUAL};
 | 
					enum class systemState_t {COUNTING, WINDING_START, WINDING, TARGET_REACHED, AUTO_CUT_WAITING, CUTTING, MANUAL};
 | 
				
			||||||
 | 
					//array with enum as strings for logging states
 | 
				
			||||||
extern const char* systemStateStr[7];
 | 
					extern const char* systemStateStr[7];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//task that controls the entire machine (has to be created as task in main function)
 | 
				
			||||||
void task_control(void *pvParameter);
 | 
					void task_control(void *pvParameter);
 | 
				
			||||||
 | 
				
			|||||||
@ -22,8 +22,6 @@ static const char *TAG = "cutter"; //tag for logging
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//=========================
 | 
					//=========================
 | 
				
			||||||
//========= start =========
 | 
					//========= start =========
 | 
				
			||||||
//=========================
 | 
					//=========================
 | 
				
			||||||
 | 
				
			|||||||
@ -13,19 +13,21 @@ extern "C"
 | 
				
			|||||||
#include "config.hpp"
 | 
					#include "config.hpp"
 | 
				
			||||||
#include "control.hpp"
 | 
					#include "control.hpp"
 | 
				
			||||||
#include "buzzer.hpp"
 | 
					#include "buzzer.hpp"
 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "switchesAnalog.hpp"
 | 
					#include "switchesAnalog.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//=================================
 | 
					//=================================
 | 
				
			||||||
//=========== functions ===========
 | 
					//=========== functions ===========
 | 
				
			||||||
//=================================
 | 
					//=================================
 | 
				
			||||||
 | 
					//--- configure output ---
 | 
				
			||||||
//function to configure gpio pin as output
 | 
					//function to configure gpio pin as output
 | 
				
			||||||
void gpio_configure_output(gpio_num_t gpio_pin){
 | 
					void gpio_configure_output(gpio_num_t gpio_pin){
 | 
				
			||||||
    gpio_pad_select_gpio(gpio_pin);
 | 
					    gpio_pad_select_gpio(gpio_pin);
 | 
				
			||||||
    gpio_set_direction(gpio_pin, GPIO_MODE_OUTPUT);
 | 
					    gpio_set_direction(gpio_pin, GPIO_MODE_OUTPUT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//--- init gpios ---
 | 
				
			||||||
void init_gpios(){
 | 
					void init_gpios(){
 | 
				
			||||||
    //--- outputs ---
 | 
					    //--- outputs ---
 | 
				
			||||||
    //4x stepper mosfets
 | 
					    //4x stepper mosfets
 | 
				
			||||||
@ -36,7 +38,7 @@ void init_gpios(){
 | 
				
			|||||||
    //gpio_configure_output(GPIO_VFD_D2); only used with 7.5kw vfd
 | 
					    //gpio_configure_output(GPIO_VFD_D2); only used with 7.5kw vfd
 | 
				
			||||||
    //2x power mosfets
 | 
					    //2x power mosfets
 | 
				
			||||||
    gpio_configure_output(GPIO_MOS1); //mos1
 | 
					    gpio_configure_output(GPIO_MOS1); //mos1
 | 
				
			||||||
    gpio_configure_output(GPIO_LAMP); //lamp
 | 
					    gpio_configure_output(GPIO_LAMP); //llamp (mos2)
 | 
				
			||||||
    //onboard relay and buzzer
 | 
					    //onboard relay and buzzer
 | 
				
			||||||
    gpio_configure_output(GPIO_RELAY);
 | 
					    gpio_configure_output(GPIO_RELAY);
 | 
				
			||||||
    gpio_configure_output(GPIO_BUZZER);
 | 
					    gpio_configure_output(GPIO_BUZZER);
 | 
				
			||||||
@ -47,12 +49,6 @@ void init_gpios(){
 | 
				
			|||||||
    //initialize and configure ADC
 | 
					    //initialize and configure ADC
 | 
				
			||||||
    adc1_config_width(ADC_WIDTH_BIT_12); //=> max resolution 4096
 | 
					    adc1_config_width(ADC_WIDTH_BIT_12); //=> max resolution 4096
 | 
				
			||||||
    adc1_config_channel_atten(ADC_CHANNEL_POTI, ADC_ATTEN_DB_11); //max voltage
 | 
					    adc1_config_channel_atten(ADC_CHANNEL_POTI, ADC_ATTEN_DB_11); //max voltage
 | 
				
			||||||
    ////initialize input for cutter position switch with pullup (now done via evaluatedSwitch construcor)
 | 
					 | 
				
			||||||
    //gpio_pad_select_gpio(GPIO_CUTTER_POS_SW);
 | 
					 | 
				
			||||||
    //gpio_set_direction(GPIO_CUTTER_POS_SW, GPIO_MODE_INPUT);
 | 
					 | 
				
			||||||
    //gpio_pad_select_gpio(GPIO_CUTTER_POS_SW);
 | 
					 | 
				
			||||||
    //gpio_set_pull_mode(GPIO_CUTTER_POS_SW, GPIO_PULLUP_ONLY);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -60,8 +56,6 @@ void init_gpios(){
 | 
				
			|||||||
//======================================
 | 
					//======================================
 | 
				
			||||||
//============ buzzer task =============
 | 
					//============ buzzer task =============
 | 
				
			||||||
//======================================
 | 
					//======================================
 | 
				
			||||||
//TODO: move the task creation to buzzer class (buzzer.cpp)
 | 
					 | 
				
			||||||
//e.g. only have function buzzer.createTask() in app_main
 | 
					 | 
				
			||||||
void task_buzzer( void * pvParameters ){
 | 
					void task_buzzer( void * pvParameters ){
 | 
				
			||||||
    ESP_LOGI("task_buzzer", "Start of buzzer task...");
 | 
					    ESP_LOGI("task_buzzer", "Start of buzzer task...");
 | 
				
			||||||
        //run function that waits for a beep events to arrive in the queue
 | 
					        //run function that waits for a beep events to arrive in the queue
 | 
				
			||||||
@ -71,8 +65,6 @@ void task_buzzer( void * pvParameters ){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//======================================
 | 
					//======================================
 | 
				
			||||||
//=========== main function ============
 | 
					//=========== main function ============
 | 
				
			||||||
//======================================
 | 
					//======================================
 | 
				
			||||||
@ -97,5 +89,4 @@ extern "C" void app_main()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    //beep at startup
 | 
					    //beep at startup
 | 
				
			||||||
    buzzer.beep(3, 70, 50);
 | 
					    buzzer.beep(3, 70, 50);
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user