aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.EmbroideryUI/Properties/AssemblyInfo.cs
blob: d3af848f33ee1478dac6aff0d5e5cdda94916920 (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
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Tango.EmbroideryUI")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>.  For example, if you are using US english
//in your source files, set the <UICulture> to en-US.  Then uncomment
//the NeutralResourceLanguage attribute below.  Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly:ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                             //(used if a resource is not found in the page,
                             // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
                                      //(used if a resource is not found in the page,
                                      // app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.8.1737")]
[assembly: AssemblyFileVersion("1.0.0.0")]
/*
 * PowerIdle.c
 *
 *  Created on: Apr 3, 2019
 *      Author: shlomo
 */
#include "modules/General/GeneralHardware.h"
#include "modules/General/Safety.h"
#include "modules/thread/thread.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/General/MachineStatus.h"
#include "Modules/General/buttons.h"

#include "PMR/Power/StandByRequest.pb-c.h"
#include "PMR/Power/StandByResponse.pb-c.h"
#include "PMR/Power/StartPowerUpRequest.pb-c.h"
#include "PMR/Power/AbortPowerUpRequest.pb-c.h"
#include "PMR/Power/StartPowerUpResponse.pb-c.h"
#include "PMR/Power/AbortPowerUpResponse.pb-c.h"
#include "PMR/Power/PowerUpState.pb-c.h"
#include "PMR/MachineStatus/MachineStatus.pb-c.h"

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

#include "drivers/I2C_Communication/DAC/Blower.h"
#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h"
#include "drivers/Valves/Valve.h"
#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC_Blower/WHS_Blower.h>
#include "drivers/Heater/TemperatureSensor.h"

#include "heaters/heaters_ex.h"

#define DEFAULT_IDLE_TIME_LIMIT 3600
int powerIdleSecondsCounter = 0;
int powerIdleSecondsLimit = DEFAULT_IDLE_TIME_LIMIT;
uint32_t IdleDrierTemperature  = 8000;
uint32_t IdleHeadTemperature = 8000;
uint32_t IdleMixerTemperature = 0;

bool powerIdleState = false;
bool machineActive = false;
uint32_t IdleControlId = 0xFF;
uint32_t IdleHeatingControlId = 0xFF;
uint32_t IdleToPowerDownControlId = 0xFF;
ProcessParameters ActiveProcessParameters,ProcessParametersClear;
bool Auto_Shutdown_Bypass = false;
bool Set_Auto_Shutdown_Bypass (int value)
{
    if (value == 0)
        Auto_Shutdown_Bypass = false;
    else
        Auto_Shutdown_Bypass = true;
    return Auto_Shutdown_Bypass;
}
bool Auto_Idle_Bypass = false;
bool Set_Auto_Idle_Bypass (int value)
{
    if (value == 0)
        Auto_Idle_Bypass = false;
    else
        Auto_Idle_Bypass = true;
    return Auto_Idle_Bypass;
}

uint32_t PowerIdleToPowerDownCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag)
{
    if (SafeRemoveControlCallback(IdleToPowerDownControlId, PowerIdleToPowerDownCallBackFunction )==OK)
        IdleToPowerDownControlId = 0xFF;
    if (Auto_Shutdown_Bypass == false)
    {
#ifndef DISPESER_TEST
        Report("PowerIdle calling power off ",__FILE__,__LINE__,(int)eOneHour*2,RpWarning,(int)0,0);
        PowerOffInit();
#endif
    }
    return OK;
}
void PowerIdleSetIdle(void)
{
	int i;
    Report("PowerIdle Set ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)powerIdleSecondsCounter,0);
    memcpy (&ActiveProcessParameters,&ProcessParametersKeep,sizeof(ProcessParameters));
    ProcessParameters ProcessParametersClear;
    ProcessParametersClear.dryerzone1temp = (ActiveProcessParameters.dryerzone1temp<80)? ActiveProcessParameters.dryerzone1temp:IdleDrierTemperature;
    ProcessParametersClear.dryerzone2temp = (ActiveProcessParameters.dryerzone2temp<80)? ActiveProcessParameters.dryerzone2temp:IdleDrierTemperature;
    ProcessParametersClear.dryerzone3temp = (ActiveProcessParameters.dryerzone3temp<80)? ActiveProcessParameters.dryerzone3temp:IdleDrierTemperature;
    ProcessParametersClear.mixertemp      = (ActiveProcessParameters.mixertemp     <60)? ActiveProcessParameters.mixertemp     :IdleMixerTemperature;
    ProcessParametersClear.headzone1temp  = (ActiveProcessParameters.headzone1temp <60)? ActiveProcessParameters.headzone1temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone2temp  = (ActiveProcessParameters.headzone2temp <60)? ActiveProcessParameters.headzone2temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone3temp  = (ActiveProcessParameters.headzone3temp <60)? ActiveProcessParameters.headzone3temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone4temp  = (ActiveProcessParameters.headzone4temp <80)? ActiveProcessParameters.headzone4temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone5temp  = (ActiveProcessParameters.headzone5temp <80)? ActiveProcessParameters.headzone5temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone6temp  = (ActiveProcessParameters.headzone6temp <80)? ActiveProcessParameters.headzone6temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone7temp  = (ActiveProcessParameters.headzone7temp <80)? ActiveProcessParameters.headzone7temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone8temp  = (ActiveProcessParameters.headzone6temp <80)? ActiveProcessParameters.headzone6temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone9temp  = (ActiveProcessParameters.headzone9temp <80)? ActiveProcessParameters.headzone9temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone10temp  = (ActiveProcessParameters.headzone10temp <80)? ActiveProcessParameters.headzone10temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone11temp  = (ActiveProcessParameters.headzone11temp <80)? ActiveProcessParameters.headzone11temp  :IdleHeadTemperature;
    ProcessParametersClear.headzone12temp  = (ActiveProcessParameters.headzone12temp <80)? ActiveProcessParameters.headzone12temp  :IdleHeadTemperature;
    ProcessParametersClear.dyeingspeed    = (ActiveProcessParameters.dyeingspeed   <40)? ActiveProcessParameters.dyeingspeed    :IdleHeadTemperature;
    ProcessParametersClear.dryerbufferlength    = (ActiveProcessParameters.dryerbufferlength   <30)? ActiveProcessParameters.dryerbufferlength    :30;
    ProcessParametersClear.rblowertemp  = (ActiveProcessParameters.rblowertemp <80)? ActiveProcessParameters.rblowertemp  :IdleHeadTemperature;
    ProcessParametersClear.lblowertemp  = (ActiveProcessParameters.lblowertemp <80)? ActiveProcessParameters.lblowertemp  :IdleHeadTemperature;
    ProcessParametersClear.rblowerflow  = (ActiveProcessParameters.rblowerflow <1.2)? ActiveProcessParameters.rblowerflow  :1.2;
    ProcessParametersClear.lblowerflow  = (ActiveProcessParameters.lblowerflow <1.2)? ActiveProcessParameters.lblowerflow  :1.2;
    ProcessParametersClear.headairflow  = (ActiveProcessParameters.headairflow <3)? ActiveProcessParameters.headairflow  :3;
    if (HandleProcessParameters(&ProcessParametersClear,false)!= OK)
    {
        LOG_ERROR (1, "Turn Heaters idle failed");
        //return;
    }
    if (BlowerCfg.enabled == true)
    {
        Turn_the_Blower_On();//Turn on with the Default_Voltage
        if (BlowerCfg.heatingvoltage)
            Control_Voltage_To_Blower(BlowerCfg.heatingvoltage);
        else
            Control_Voltage_To_Blower(BlowerCfg.voltage-500);
        WHS_Set_SetPoint_Q_value(headairflow*2/3);
    }
    SetMachineStatus(MACHINE_STATE__Sleep);
    if (Auto_Shutdown_Bypass == false)
    {
        IdleToPowerDownControlId = AddControlCallback("IdleToPowerDown",PowerIdleToPowerDownCallBackFunction, eOneHour*2, TemplateDataReadCBFunction,0,0, 0 );
    }
    short_cycle = false;
    if (AutoHoming_Config >= AutoHoming_PowerOn_off )
    {
        for (i=0;i<MAX_SYSTEM_DISPENSERS;i++)
        {
            IDS_HomeDispenser(i,1000,NULL);
        }
    }

}

uint32_t PowerIdleCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag)
{
    if (machineActive == true)
        return OK;
    if ((powerIdleSecondsCounter%100 == 0)&&(powerIdleSecondsCounter))
        Report("PowerIdle Idle counter ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)powerIdleSecondsCounter,0);

    if (++powerIdleSecondsCounter>=powerIdleSecondsLimit)
    {
        if ((powerIdleState == false)&&(Auto_Idle_Bypass == false))
        {
            Report("PowerIdle Idle activated ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)powerIdleSecondsCounter,0);
            powerIdleState = true;
            SetPowerMachineState(sttIDLE);
            //move to idle state
            PowerIdleSetIdle();
            if (SafeRemoveControlCallback(IdleControlId, PowerIdleCallBackFunction )==OK)
                IdleControlId = 0xFF;

        }
    }
    return OK;
}
void PowerIdleInit(void)
{
    IdleControlId = AddControlCallback("IdleCounter", PowerIdleCallBackFunction, eOneSecond, TemplateDataReadCBFunction,0,0, 0 );
    if (IdleControlId == 0xFF)
        Report("AddControlCallback failed",__FILE__,__LINE__,(int)IdleControlId,RpWarning,(int)0,0);
    Report("PowerIdleInit ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)0,0);

}
void  PowerIdleSetParameters(uint32_t switchtoidletimeinseconds,uint32_t idledriertemperature,uint32_t idleheadtemperature,uint32_t idlemixertemperature)
{
    if (switchtoidletimeinseconds >= DEFAULT_IDLE_TIME_LIMIT)
        powerIdleSecondsLimit = switchtoidletimeinseconds;
    IdleDrierTemperature = idledriertemperature;
    IdleHeadTemperature = idleheadtemperature;
    IdleMixerTemperature = idlemixertemperature;
    Report("Power Idle Set Parameters",__FILE__,powerIdleSecondsLimit,(int)idledriertemperature,RpWarning,(int)idleheadtemperature,0);

}
int getIdleCounter (void) {return powerIdleSecondsCounter;}
void setIdleLimit (int Limit) {powerIdleSecondsLimit = Limit;}
void setmachineActive(bool Active){machineActive = Active;}
void resetIdleCounter (void) {powerIdleSecondsCounter = 0;}
bool getIdleState (void) {return powerIdleState;}
void StandByRequestFunc(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;

    //StandByRequest* request = stand_by_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    StandByResponse response =   STAND_BY_RESPONSE__INIT;

    PowerIdleActivateIdleState();
    responseContainer = createContainer(MESSAGE_TYPE__StandByResponse, requestContainer->token, true, &response, &stand_by_response__pack, &stand_by_response__get_packed_size);
    //-------------------------------------------------------------------------------------------
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    //stand_by_request__free_unpacked(request,NULL);
}
uint32_t OutOfIdleUpdate(bool last)
{
    uint32_t status = NOT_SUPPORTED;
/*
    double calculate;
    int result = 0;
    MessageContainer responseContainer;
    ErrorCode Error = ERROR_CODE__NONE;

    StartPowerUpResponse response = START_POWER_UP_RESPONSE__INIT;

    if (PowerUpToken[0] == 0)
        return OK;
    response.has_state = true;
    response.has_progresspercentage = true;

    if (last == false)
    {
        response.state = POWER_UP_STATE__HeatingStarted;
        if (dryerzone1temp < 1)
            response.progresspercentage = 30.0;
        else
        {
            calculate = (double)((MillisecGetTemperatures(TEMP_SENSE_ANALOG_DRYER_TEMP1)/100)/(dryerzone1temp))*70.0;
            if (calculate > 0)
                result = (int)calculate;
            response.progresspercentage = 30.0 + result;
        }
        //Report("Heating calculation",__FILE__,(int)dryerzone1temp,(int)response.progresspercentage,RpWarning,(int)result,0);
        response.message = "Heating up";
    }
    else
    {
        response.state = POWER_UP_STATE__MachineReadyToDye;
        response.progresspercentage = 100.0;
        response.message = "Ready to dye";
    }
    //Report("PowerUpUpdate",__FILE__,last,(int)response.progresspercentage,RpWarning,(int)stage,0);
    Report("OutOfIdleUpdate",__FILE__,last,response.state,RpWarning,(int)response.progresspercentage,0);
    responseContainer = createContainer(MESSAGE_TYPE__StartPowerUpResponse, PowerUpToken, last, &response, &start_power_up_response__pack, &start_power_up_response__get_packed_size);
    responseContainer.has_continuous = true;
    responseContainer.continuous = true;
    if (Error != ERROR_CODE__NONE)
    {
        responseContainer.has_error = true;
        responseContainer.error = Error;
        responseContainer.errormessage = response.message;
    }
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);

    SendChars((char*)container_buffer, container_size);
    //MessageContainer responseContainer;
*/
    return status;
}

uint32_t PowerIdleStartHeatingCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag)
{
    OutOfIdleUpdate(false);
    if (HeaterCheckReady()==true)
    {
        //MachineStateDetail = MACHINE_STATE_MACHINE_READY_TO_DYE;
        if (SafeRemoveControlCallback(IdleHeatingControlId, PowerIdleStartHeatingCallBackFunction )==OK)
            IdleHeatingControlId = 0xFF;
        else
            Report("Remove control callback failed",__FILE__,__LINE__,(int)IdleHeatingControlId,RpWarning,(int)PowerIdleStartHeatingCallBackFunction,0);
        //InitSequenceStateMachine(InitStages);
	    SetMachineStatus(MACHINE_STATE__Ready);
	    OutOfIdleUpdate(true);
    }

    return OK;
}

void PowerIdleOutOfIdleState(void)
{
    Report("PowerIdle Out of Idle  ",__FILE__,__LINE__,(int)powerIdleSecondsLimit,RpWarning,(int)powerIdleSecondsCounter,0);
    powerIdleSecondsCounter = 0;
    if (powerIdleState == true)
    {
        powerIdleState = false;
        RemoveControlCallback(IdleToPowerDownControlId, PowerIdleToPowerDownCallBackFunction );
        IdleToPowerDownControlId = 0xFF;
        SetPowerMachineState(sttON);
        if (HandleProcessParameters(&ActiveProcessParameters,false)!= OK)
        {
            LOG_ERROR (1, "Turn Heaters active failed");
            return ;
        }
        if (IdleControlId == 0xFF)
            IdleControlId = AddControlCallback( "NULL",PowerIdleCallBackFunction, eOneSecond, TemplateDataReadCBFunction,0,0, 0 );
        if (IdleControlId == 0xFF)
            Report("AddControlCallback failed",__FILE__,__LINE__,(int)IdleControlId,RpWarning,(int)0,0);
        SetMachineStatus(MACHINE_STATE__PowerUp);
        IdleHeatingControlId = AddControlCallback("Heating Out of Idle", PowerIdleStartHeatingCallBackFunction, 2*eOneSecond, TemplateDataReadCBFunction,0,0, 0 );


    }

}
void PowerIdleActivateIdleState(void)
{
    Report("PowerIdle Activate Idle  ",__FILE__,__LINE__,(int)machineActive,RpWarning,(int)powerIdleSecondsCounter,0);
    if (machineActive == true)
    {
        LOG_ERROR(machineActive, "machine is active, cannot switch on idle state");
        return;
    }
    powerIdleSecondsCounter = 0;
    if (powerIdleState == false)
    {
        powerIdleState = true;
        PowerIdleSetIdle();
    }

}