Last-Modified: Mon, 03 Aug 2026 00:30:28 GMT Expires: Thu, 31 Jul 2036 00:30:28 GMT AssemblyInfo.cs « Properties « TestApp « Tango.Scripting « TEMP « Visual_Studio « Software - Tango - Twine softwares
aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TEMP/Tango.Scripting/TestApp/Properties/AssemblyInfo.cs
blob: d2b37f2f37416c77cabc42c02116ba0198b9296c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * PowerOffSequence.c
 *
 *  Created on: Apr 2, 2019
 *      Author: shlomo
 */


#include "modules/General/GeneralHardware.h"
#include "modules/General/Safety.h"
#include "modules/thread/thread.h"
#include "modules/waste/waste.h"
#include "modules/ids/ids.h"
#include "modules/control/control.h"
#include "modules/AlarmHandling/AlarmHandling.h"
#include "modules/heaters/heaters_ex.h"
#include "modules/Diagnostics/Diagnostics.h"
#include "Modules/General/process.h"

#include "Modules/Thread/Thread_ex.h"
#include "Common/SWUpdate/FirmwareUpgrade.h"

#include "StateMachines/Printing/PrintingSTM.h"
#include "PowerIdle.h"
#include "InitSequence.h"

#include "drivers/I2C_Communication/DAC/Blower.h"
#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h"
#include "drivers/Heater/TemperatureSensor.h"
#include "drivers/Valves/Valve.h"

#include "heaters/heaters_ex.h"

#include "PowerOffSequence.h"
/*
    typedef enum
    {
        POWER_OFF_INIT,
        POWER_OFF_STOP_RUNNING_JOB,
        POWER_OFF_HEAD_CLEAN,
        POWER_OFF_MIXER_FLUSH,
        POWER_OFF_HEATERS_OFF,
        POWER_OFF_STORE_DATA,
        POWER_OFF_SET_VALVE_POSITION,
        POWER_OFF_WAIT_FOR_TEMPERATURE,
        POWER_OFF_WAIT_FOR_PROCESSES,//wait for waste emptying, ink filling, thread loading
        POWER_OFF_TURN_OFF_DRYER_FAN,
        POWER_OFF_TURN_OFF_COOLER,
        POWER_OFF_TURN_OFF_BLOWER,
        POWER_OFF_POWER_OFF,
        POWER_OFF_MAX,
    }POWER_OFF_STAGES_ENUM;
*/
POWER_OFF_STAGES_ENUM PowerOffMachineState = POWER_OFF_INIT,StoredMachineState = POWER_OFF_INIT;
uint32_t PowerOffControlId = 0xFF;
uint32_t WaitForProcessControlId = 0xFF;
uint32_t PowerOffSequenceStateMachine( POWER_OFF_STAGES_ENUM ReadValue);
bool PowerOffInProcess = false;
#define POWER_OFF_TEMP_THRESHOLD 5000  //50 celsious
int32_t PowerOffTemperatureThreshold = POWER_OFF_TEMP_THRESHOLD;

bool PowerOffInProcessGetState(void)
{
    return PowerOffInProcess;
}
void PowerOffSetTemperatureThreshold (int32_t temperature)
{
    if (temperature)
    {
        PowerOffTemperatureThreshold =  temperature*100;
    }
}
/*******************************************************************************************************/
uint32_t PowerOffScheduler(uint32_t IfIndex, uint32_t BusyFlag)
{
    if (PowerOffMachineState > StoredMachineState)
    {
        StoredMachineState = PowerOffMachineState;
        PowerOffSequenceStateMachine (PowerOffMachineState);
    }
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffInit(void)
{
    LOG_ERROR(0,"Power Off Init");
    PowerOffMachineState++;
    StopInitSequence();
    setmachineActive(true);
    PowerOffInProcess = true;
    PowerOffControlId = AddControlCallback( PowerOffScheduler, eOneSecond, TemplateDataReadCBFunction,0,0, 0 );
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffCancel(void)
{
    if (PowerOffMachineState >= POWER_OFF_HEAD_CLEAN)
        PowerOffMachineState = POWER_OFF_CANCELLED;
    PowerOffInProcess = false;
    return OK;
}
/************************************************************************shlomo

 */
uint32_t PowerOffHeadCleanControlId = 0xff;
uint32_t PowerOffHeadCleanCallback(uint32_t DispenserId, uint32_t ReadValue)
{
    if ( JobIsActive()== false)
       {
           //stop this control loop
           SafeRemoveControlCallback(PowerOffHeadCleanControlId, PowerOffHeadCleanCallback );
           PowerOffHeadCleanControlId = 0xFF;
           PowerOffMachineState++;

       }
    return OK;
}

/*******************************************************************************************************/
uint32_t PowerOffHeadClean(void)
{
    //TBD
    if (AutoHoming_Config >= AutoHoming_PowerOff )
        AutoHoming_Config = AutoHoming_JobEnd_PowerOn_off;
    ThreadCleaningJobFunc(50);
    if (PowerOffHeadCleanControlId != 0xFF)
    {
        RemoveControlCallback(PowerOffHeadCleanControlId, PowerOffHeadCleanCallback );
        PowerOffHeadCleanControlId = 0xFF;
        //return ERROR;
    }
    PowerOffHeadCleanControlId = AddControlCallback( PowerOffHeadCleanCallback,eOneSecond , TemplateDataReadCBFunction,0,0, 0 );
//    if ( PowerOffHeadCleanControlId == 0xFF)
//        return ERROR;

    return OK;
}
/*******************************************************************************************************/
bool DispenserHomingActive[MAX_SYSTEM_DISPENSERS] = {false,false,false,false,false,false,false,false};
uint32_t PowerOffDispenserHomingCallback(uint32_t DispenserId, uint32_t ReadValue)
{
    DispenserHomingActive[DispenserId] = false;
    REPORT_MSG (DispenserId, "PowerOffDispenserHomingCallback");

    return OK;
}
#define TI_DISPENSER_ID 4
#define DEFAULT_MIXER_CLEANING_SPEED 1000
#define DEFAULT_MIXER_CLEANING_TIMEOUT 10000

uint32_t PowerOffMixerFlushCallback(void)
{
    //TBD
    int i;
    REPORT_MSG (PowerOffMachineState, "PowerOffMixerFlushCallback");
    SafeRemoveControlCallback(PowerOffHeadCleanControlId, PowerOffMixerFlushCallback );

    Control3WayValvesWithCallback ((Valves_t)TI_DISPENSER_ID, MidTank_Dispenser, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer
    TimerMotors_t  HW_Motor_Id = DispenserIdToMotorId[TI_DISPENSER_ID];
    MotorStop(HW_Motor_Id,Hard_Hiz);

    Task_sleep (20);
    for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
    {
        if(IDS_HomeDispenser(i,1000,PowerOffDispenserHomingCallback) == OK)
        {
            DispenserHomingActive[i] = true;
            REPORT_MSG (i, "PowerOffDispenserHomingCallback");
        }
    }
    PowerOffMachineState++;
    return OK;
}
uint32_t PowerOffMixerFlushDispenserStopCallback(void)
{
    REPORT_MSG (PowerOffMachineState, "PowerOffMixerFlushDispenserStopCallback");
    IDS_Dispenser_Start_Motor_and_Open_Valve(TI_DISPENSER_ID,DEFAULT_MIXER_CLEANING_SPEED,NULL);
    PowerOffHeadCleanControlId = AddControlCallback( PowerOffMixerFlushCallback,DEFAULT_MIXER_CLEANING_TIMEOUT , TemplateDataReadCBFunction,0,0, 0 );
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffMixerFlush(void)
{
    int i;
    REPORT_MSG (PowerOffMachineState, "PowerOffMixerFlush");
    Valve_Set(VALVE_MIXCHIP_WASTECH, Mixer_Waste); //if intersegment is defined throw the ink away
    for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
    {
        if (i!=TI_DISPENSER_ID)
            IDS_Dispenser_Close_Valve_And_Stop_Motor(i, NULL);
        else
            IDS_Dispenser_Close_Valve_And_Stop_Motor(i, PowerOffMixerFlushDispenserStopCallback);
    }

    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffHeatersOff(void)
{
    ProcessParameters ProcessParametersClear;
    ProcessParametersClear.dryerzone1temp = 0;
    ProcessParametersClear.dryerzone2temp = 0;
    ProcessParametersClear.dryerzone3temp = 0;
    ProcessParametersClear.mixertemp      = 0;
    ProcessParametersClear.headzone1temp  = 0;
    ProcessParametersClear.headzone2temp  = 0;
    ProcessParametersClear.headzone3temp  = 0;
    ProcessParametersClear.headzone4temp  = 0;
    ProcessParametersClear.headzone5temp  = 0;
    ProcessParametersClear.headzone6temp  = 0;
    ProcessParametersClear.dyeingspeed = 40;
    if (HandleProcessParameters(&ProcessParametersClear)!= OK)
    {
        LOG_ERROR (PowerOffMachineState, "Turn Off Heaters  failed");
        return ERROR;
    }

    PowerOffMachineState++;

    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffStoreData(void)
{
    //TBD
    REPORT_MSG (PowerOffMachineState, "Store Data");
    IDS_Dispenser_Store_Data();
    PowerOffMachineState++;
    return OK;
}
/*******************************************************************************************************/
int WaitForProcessCounter = 0;
uint32_t PowerOffWaitForProcessesCallback(uint32_t IfIndex, uint32_t BusyFlag)
{
    int i;
    bool HomingActive = false;
    for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
    {
        if (DispenserHomingActive[i] ==true)
        {
            HomingActive = true;
        }
    }
    if ((WHS_IsEmptying()||
        //MidTankFillingActive()||
        ThreadLoadingActive()||
        SwUpgradeActive()||
        (HomingActive == true))&&
        (WaitForProcessCounter++<900))
    {
        REPORT_MSG (PowerOffMachineState, "Ongoing processes calback, wait for end of process");
        resetIdleCounter();
    }
    else
    {
        PowerOffMachineState++;
        SafeRemoveControlCallback(WaitForProcessControlId, PowerOffWaitForProcessesCallback);
        WaitForProcessControlId = 0xFF;
    }
 return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffWaitForProcesses(void)
{
    int i;
    REPORT_MSG (PowerOffMachineState, "Stop dispensers homing");
    bool HomingActive = false;
    for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
    {
        if (DispenserHomingActive[i] ==true)
        {
            HomingActive = true;
            IDS_StopHomeDispenser(i);
            REPORT_MSG (i, "IDS_StopHomeDispenser");
            IDS_HomeDispenserWaitForHomingEnd(i,  2*eOneMinute /*2 minutes*/ , PowerOffDispenserHomingCallback);
        }
    }

    if (WHS_IsEmptying()||
        //MidTankFillingActive()||
        ThreadLoadingActive()||
        SwUpgradeActive()||
        (HomingActive == true))
    {
        WaitForProcessCounter = 0; //15 minutes wait
        REPORT_MSG (PowerOffMachineState, "Ongoing processes, wait for end of process");
        WaitForProcessControlId = AddControlCallback( PowerOffWaitForProcessesCallback, eOneSecond, TemplateDataReadCBFunction,0,0, 0 );
    }
    else
    {
        PowerOffMachineState++;
    }
    //TBD
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffStopRunningJob(void)
{
    if (JobIsActive())
    {
        REPORT_MSG (PowerOffMachineState, "Stop running job");
        AbortJob("Power off pressed");
    }
    PowerOffMachineState++;
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffSetValvePosition(void)
{
    //TBD
    PowerOffMachineState++;
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffWaitForTemperatureCallback(uint32_t IfIndex, uint32_t BusyFlag)
{
    uint32_t MaxTemp = 0,readTemp;
    readTemp = TemperatureSensorRead( MIXER_PT100);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP1);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP2);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP3);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP4);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DYEINGH_TEMP5);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( HEAD6_PT100);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;
    readTemp = TemperatureSensorRead( TEMP_SENSE_ANALOG_DRYER_TEMP1);
    if ((readTemp>= MaxTemp)&&(readTemp < 28000))
        MaxTemp = readTemp;


    if ((MaxTemp>PowerOffTemperatureThreshold)&&(WaitForProcessCounter++<3600))
    {
        Report("On going cooling down, wait for end of cooling",__FILE__,__LINE__,(int)MaxTemp,RpWarning,(int)WaitForProcessCounter,0);
        resetIdleCounter();
    }
    else
    {
        Report("ended cooling down, wait for end of cooling",__FILE__,__LINE__,(int)MaxTemp,RpWarning,(int)WaitForProcessCounter,0);
        PowerOffMachineState = POWER_OFF_TURN_OFF_DRYER_FAN;
        SafeRemoveControlCallback(WaitForProcessControlId, PowerOffWaitForTemperatureCallback);
        WaitForProcessControlId = 0xFF;
    }
 return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffWaitForTemperature(void)
{
    if (WaitForProcessControlId == 0xFF)
    {
        WaitForProcessCounter = 0;
        WaitForProcessControlId = AddControlCallback( PowerOffWaitForTemperatureCallback, eOneSecond, TemplateDataReadCBFunction,0,0, 0 );
    }
    //TBD
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffTurnOffDryerFan(void)
{
    Control_Dryer_Fan(STOP,75);//use START or STOP,  0 - 100%
    PowerOffMachineState++;

    //TBD
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffTurnOffCooler(void)
{
    uint32_t DeActivateChiller();
    PowerOffMachineState++;
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffTurnOffBlower(void)
{
    Turn_the_Blower_Off();//Turn off
    PowerOffMachineState++;
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffPowerOff(void)
{
    int i;
    for (i = 0;i<10;i++)
    {
        REPORT_MSG (10-i, "Power off in x seconds");
        Task_sleep (1000);
    }
    Power_Off();
    return OK;
}
/*******************************************************************************************************/
uint32_t PowerOffSequenceStateMachine( POWER_OFF_STAGES_ENUM ReadValue)
{
    uint32_t status = OK;

    REPORT_MSG(ReadValue,"PowerOffSequenceStateMachine");
    switch (ReadValue)
    {
    case POWER_OFF_INIT:
        break;
    case POWER_OFF_HEAD_CLEAN:
        status = PowerOffHeadClean();
        break;
    case POWER_OFF_MIXER_FLUSH:
        status = PowerOffMixerFlush();
        break;
    case POWER_OFF_HEATERS_OFF:
        status = PowerOffHeatersOff();
        break;
    case POWER_OFF_STORE_DATA:
        status = PowerOffStoreData();
        break;
    case POWER_OFF_WAIT_FOR_PROCESSES: //wait for waste emptying: ink filling: thread loading
        status = PowerOffWaitForProcesses();
        break;
    case POWER_OFF_STOP_RUNNING_JOB:
        status = PowerOffStopRunningJob();
        break;
    case POWER_OFF_SET_VALVE_POSITION:
        status = PowerOffSetValvePosition();
        break;
    case POWER_OFF_WAIT_FOR_TEMPERATURE:
        status = PowerOffWaitForTemperature();
        break;
    case POWER_OFF_TURN_OFF_DRYER_FAN:
        status = PowerOffTurnOffDryerFan();
        break;
    case POWER_OFF_TURN_OFF_COOLER:
        status = PowerOffTurnOffCooler();
        break;
    case POWER_OFF_TURN_OFF_BLOWER:
        status = PowerOffTurnOffBlower();
        break;
    case POWER_OFF_POWER_OFF:
        status = PowerOffPowerOff();
        break;
    case POWER_OFF_ERROR:
    case POWER_OFF_CANCELLED:
        RemoveControlCallback( PowerOffControlId,PowerOffScheduler);
        PowerOffControlId = 0xFF;
        RemoveControlCallback(WaitForProcessControlId, PowerOffWaitForProcessesCallback);
        RemoveControlCallback(WaitForProcessControlId, PowerOffWaitForTemperatureCallback);
        WaitForProcessControlId = 0xFF;
        LOG_ERROR(ReadValue,"POWER OFF Cancelled");
        break;
    default:
        LOG_ERROR(ReadValue,"ERROR IN POWER OFF STATE MACHINE");
        break;
    }
return status;
}