aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2019-01-27 14:41:51 +0200
committerAvi Levkovich <avi@twine-s.com>2019-01-27 14:41:51 +0200
commitc64b07d93d944a294df08cee553800a09757d6ec (patch)
tree71ab5b00aa977d5848058d2ed65cfd5f0782062f /Software/Embedded_SW/Embedded/Modules
parent9f678962afca4568589680a897f9f358a2b163d2 (diff)
parent2fb4421e0d771ea84e744856dc56ebc7b713cd86 (diff)
downloadTango-c64b07d93d944a294df08cee553800a09757d6ec.tar.gz
Tango-c64b07d93d944a294df08cee553800a09757d6ec.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules')
-rw-r--r--Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c18
-rw-r--r--Software/Embedded_SW/Embedded/Modules/General/buttons.c537
-rw-r--r--Software/Embedded_SW/Embedded/Modules/General/buttons.h8
3 files changed, 546 insertions, 17 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c
index 7600e6547..475a623f0 100644
--- a/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c
+++ b/Software/Embedded_SW/Embedded/Modules/AlarmHandling/AlarmHandling.c
@@ -219,6 +219,7 @@ const AlarmHandlingItemStruc AlarmItem[MAX_SYSTEM_ALARMS]={
{eOneSecond,DoNotPollAlarm,0,0,0,0,DEBUG_LOG_CATEGORY__Warning,0xFF,0,EVENT_TYPE__THREAD_TENSION_CONTROL_FAILURE,"Thread Tension Control Failure"},
{eOneSecond,DoNotPollAlarm,0,0,0,0,DEBUG_LOG_CATEGORY__Warning,0xFF,0,EVENT_TYPE__WINDER_CONE_DOES_NOT_EXIST,"No cone in winder"}
};
+
char TestMessage[5]="Test";
bool DispenserInUse[MAX_SYSTEM_DISPENSERS] = {false,false,false,false,false,false,false,false};
bool EventsNotificationRequestAccepted = false;
@@ -477,23 +478,6 @@ JobEndReasonEnum AlarmHandlingPrepareJob(void *CurrentJob)
return JobEndReason;
}
-/*
-uint32_t AlarmHandling_CalculateTemperatures(uint32_t SensorId, uint32_t Data)
-{
- AlarmHandlingMessageStruc Message;
-
- //send message to the Millisec task
- Message.messageId = AlarmHandlingCalculateTemperature;
- Message.msglen = sizeof(AlarmHandlingMessageStruc);
- Message.SensorId = SensorId;
- Message.Data = Data;
- if (AlarmHandlingMsgQ != NULL)
- Mailbox_post(AlarmHandlingMsgQ , &Message, BIOS_NO_WAIT);
-
-
- return OK;
-}
-*/
uint32_t AlarmHandling_ControlTrigger(uint32_t IfIndex, uint32_t ReadValue)
{
AlarmHandlingMessageStruc Message;
diff --git a/Software/Embedded_SW/Embedded/Modules/General/buttons.c b/Software/Embedded_SW/Embedded/Modules/General/buttons.c
new file mode 100644
index 000000000..075e0f009
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/General/buttons.c
@@ -0,0 +1,537 @@
+/************************************************************************************************************************
+ * buttons.c
+ * buttons behaver
+ *
+************************************************************************************************************************/
+#include <Container.h>
+#include <DataDef.h>
+#include "include.h"
+
+#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"//#include "FPGA_GPIO.h" // use for FPGA IO
+#include "DataDef.h" // use for FPGA IO
+#include "Modules/Control/control.h" // use for FPGA IO
+
+#include "StateMachines/Printing/PrintingSTM.h"
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <driverlib/gpio.h>
+#include "Common/report/report.h"
+
+#include "Modules/General/buttons.h"
+
+int MachineOnOff();
+int ch_to_power_down();
+int ch_to_power_up();
+int thredJog();
+
+typedef enum
+{
+ colorOFF = 0,
+ BLUE,
+ BLINK,
+ fastBILNK,
+ BREATHING
+} PBcolor;
+
+typedef enum
+{
+ OFFPB = 0,
+ COUNTPB ,
+ SHORTPB ,
+ LONGPB ,
+ REPLONGPB //repeat long PB
+}PBstat;
+
+typedef enum
+{
+ MSEC = 0,
+ lESS200 ,
+ LESS500 ,
+ LESS5000 ,
+ MORE5000
+}timems;
+
+typedef enum
+{
+ sttOFF = 0,
+ sttON,
+ sttDISABLE,
+ sttENABLE,
+ sttIDLE,
+ sttJOGGING,
+ sttRDY,
+ sttPRELOAD,
+ sttLOADING,
+ sttLOADSUCSESS,
+ sttLOADFAIL
+} PBmachinState;
+
+//enum PBstat OnOffPBstate = OFFPB;
+//enum PBstat ret
+//enum PBstat threadPB = OFFPB;
+
+struct button
+{
+ char bttn_name[10]; //option
+ int bttn_status; // 0=release 1=press
+ /* enum */ PBstat Action; //offPB,shortPB,longPB,countPB,replongPB
+ /* enum */ PBcolor color; //off, blue, blink, bithing
+ /* enum */ PBmachinState state; //sttOFF, sttON, sttDISABLE, sttENABLE, sttIDLE, sttJOGGING
+ uint32_t count;
+};
+
+struct button power , jog, load;
+uint32_t ButtonsCallBackFunction(uint32_t IfIndex, uint32_t ReadValue);
+uint32_t ButtonsCBFunction(uint32_t IfIndex, uint32_t ReadValue);
+uint32_t ShortLongOffPB(uint8_t OnOffPB, struct button *pBtn);
+uint32_t StateMachine(struct button *pBtn);
+
+
+uint32_t ButtonJogCallBackFunction(uint32_t IfIndex, uint32_t ReadValue);
+uint32_t ButtonJogCBFunction(uint32_t IfIndex, uint32_t ReadValue);
+uint8_t thraedJogging(uint8_t off);
+uint32_t setJoggingEnableCondition(struct button *pBtn);
+uint32_t joggingMachine(uint8_t OnOffPB, struct button *pBtn);
+
+
+uint32_t ButtonLoadCallBackFunction(uint32_t IfIndex, uint32_t ReadValue);
+uint32_t ButtonLoadCBFunction(uint32_t IfIndex, uint32_t ReadValue);
+
+/*
+void Power_Reset();
+uint8_t Buttons_LEDS(BUTTON Button, OPERATION_MODE LED_Mode);
+uint8_t Buzzer(OPERATION_MODE Buzzer_Mode);
+bool Read_PWR_Button();//TODO move to GPIO folder
+*/
+
+
+
+/*
+ * read GPIO status
+ * port: GPIO_PORTN_BASE
+ * pin : GPIO_PIN_7
+ *
+ * return !GPIOstatus
+ */
+uint32_t ButtonsCallBackFunction(uint32_t IfIndex, uint32_t ReadValue)
+{
+ if(ROM_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_7))
+ return 0x00;
+ else
+ return 0x01;
+}
+uint32_t ButtonJogCallBackFunction(uint32_t IfIndex, uint32_t ReadValue)
+{
+ if(ROM_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_7))
+ return 0x00;
+ else
+ return 0x01;
+}
+
+uint32_t ButtonLoadCallBackFunction(uint32_t IfIndex, uint32_t ReadValue)
+{
+ if(ROM_GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_7))
+ return 0x00;
+ else
+ return 0x01;
+}
+
+//uint32_t AddControlCallback( ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint16_t IfIndex, uint32_t Parameter1, uint32_t Parameter2 );
+//Power_Reset()// Resets the MCU
+
+#define BUTTOMS_SAMPLE_TIME 50
+
+uint32_t Buttons_Init(void)
+{
+
+ power.bttn_status = 0 ;
+// power.bttn_name = "power"; //option
+ power.bttn_status = 0; // 0=release 1=press
+ power.Action = OFFPB ; //off,short,long,count,replong
+ power.color = colorOFF; //off, blue, blink, bithing
+ power.state = sttOFF; //sttOFF, sttON, sttDISABLE, sttENABLE, sttIDLE, sttJOGGING
+ power.count = 0;
+
+ AddControlCallback( ButtonsCBFunction, BUTTOMS_SAMPLE_TIME, ButtonsCallBackFunction, 0,0,0 ); // eFiftyMillisecond
+
+ jog.bttn_status = 0 ;
+// power.bttn_name = "power"; //option
+ jog.bttn_status = 0; // 0=release 1=press
+ jog.Action = OFFPB ; //OFFPB,short,long,count,replong
+ jog.color = colorOFF; //colorOFF, BLUE, BLINK,
+ jog.state = sttOFF; // sttDISABLE, sttENABLE, sttJOGGING
+ jog.count = 0;
+ AddControlCallback( ButtonJogCBFunction, BUTTOMS_SAMPLE_TIME, ButtonJogCallBackFunction, 0,0,0 ); //
+
+ load.bttn_status = 0 ;
+// power.bttn_name = "power"; //option
+ load.bttn_status = 0; // 0=release 1=press
+ load.Action = OFFPB ; //OFFPB,short,long,count,replong
+ load.color = colorOFF; //colorOFF, BLUE, BLINK,
+ load.state = sttOFF; // sttDISABLE, sttENABLE, sttJOGGING
+ load.count = 0;
+
+ AddControlCallback( ButtonLoadCBFunction, BUTTOMS_SAMPLE_TIME, ButtonLoadCallBackFunction, 0,0,0 ); //
+}
+
+
+//read the buttons data here and handle
+uint32_t ButtonsCBFunction(uint32_t IfIndex, uint32_t ReadValue)
+{
+ ShortLongOffPB(ReadValue,&power);
+ return 0;
+}
+
+uint32_t ButtonJogCBFunction(uint32_t IfIndex, uint32_t ReadValue)
+{
+ setJoggingEnableCondition(&jog);
+ joggingMachine(ReadValue, &jog);
+ return 0;
+}
+
+
+uint32_t ButtonLoadCBFunction(uint32_t IfIndex, uint32_t ReadValue)
+{
+ // ShortLongOffPB(ReadValue,&load);
+ return 0;
+}
+
+/*---------------------------------------------------------------------------------*/
+
+
+
+//OnOffPB = getPBstatus(POWER_PB);
+
+
+
+/*
+ *
+ *
+ */
+int Get_timer()
+{
+ // to go timer
+ return 0;
+}
+
+int ClearTimer()
+{
+ //to do clear timer
+ return 0;
+}
+int StartTimer()
+{
+ // to do start timer
+ return 0;
+}
+int StopTimer()
+{
+ // to do start timer
+ return 0;
+}
+
+/* ---------------------------------------------------------
+ * --- ShortLongOffPB(int OnOffPB, enum PBstat *ret) ----
+ * input: OnOffPB status(0(pressed) or 1(relesed)
+ *
+ * output: offPB, countPB, shortPB, longPB, replongPB
+ *
+ * that func get :
+ * OnOffPB status (
+ * 0=release,
+ * 1=pressed
+ * )
+ *
+ ------------------------------------------------------------*/
+
+
+//ShortLongOffPB( OnOffPB, &ret)
+
+
+uint32_t ShortLongOffPB(uint8_t OnOffPB, struct button *pBtn)
+{
+ uint8_t parameter = 0 ; // why we need it!!!!
+
+
+ pBtn->count += OnOffPB;
+ switch( pBtn->Action )
+ {
+ case OFFPB: // last OnOffPBstate was OFF
+ if( OnOffPB )
+ {
+ pBtn->Action = COUNTPB ;
+ }
+ break;
+ case COUNTPB: // last OnOffPBstate was COUNTPB
+ if (OnOffPB)
+ {
+ if( pBtn->count > 5 ) //250ms
+ {
+ pBtn->Action = SHORTPB ;
+ }
+ }
+ else
+ {
+ pBtn->Action = OFFPB ;
+ pBtn->count = 0;
+ }
+ break;
+ case SHORTPB: // last OnOffPBstate was SHORTPB
+ if (OnOffPB)
+ {
+ if (pBtn->count > 100) //5000ms
+ {
+ pBtn->Action = LONGPB ;
+ REPORT_MSG(parameter,"Long PB ");
+ StateMachine(pBtn);
+ pBtn->count = 0;
+ }
+ }
+ else
+ {
+ REPORT_MSG(parameter,"Short PB ");
+ StateMachine(pBtn);
+ pBtn->count = 0;
+ pBtn->Action = OFFPB ;
+ };
+ break;
+ case LONGPB:
+ if (OnOffPB)
+ {
+ REPORT_MSG(parameter," ------------ Please release the PB ----------------- ");
+ }
+ else
+ {
+ pBtn->Action = OFFPB ;
+ pBtn->count = 0;
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+/* --- StateMachine(enum PBstat PBAction) ----
+ * input:
+ *
+ * output: offPB, countPB, shortPB, longPB, replong
+ *
+ *
+ */
+
+
+
+uint32_t StateMachine(struct button *pBtn) //short press(=0)/long press(=1)
+{
+ uint8_t parameter = 1;
+
+ switch (pBtn->state)// sttON/sttOFF/sttIDLE
+ {
+ case sttON:
+ switch (pBtn->Action)
+ {
+ case LONGPB: //Power Down
+ pBtn->state = sttOFF; // todo
+ REPORT_MSG(parameter,"Power state is OFF ");
+ break;
+// case SHORTPB: //idle ?????
+// setMachineStatus = IDLE; // ????/
+// break;
+ default:
+ break;
+ }
+ break;
+ case sttOFF:
+ switch (pBtn->Action)
+ {
+// case LONGPB: //Idle?
+// // todo
+// break;
+ case SHORTPB: //powerup?
+ // to do ?
+ pBtn->state = sttON; //todo
+ REPORT_MSG(parameter,"Power state is ON ");
+ break;
+ default:
+ break;
+ }
+ break;
+ case sttIDLE:
+ switch (pBtn->Action)
+ {
+ case LONGPB: //Power off from idle
+ pBtn->state = sttOFF; // todo
+ REPORT_MSG(parameter,"Power state is OFF ");
+ break;
+ case SHORTPB: //Wake up from idle
+ pBtn->state = sttON;// to do ?
+ REPORT_MSG(parameter,"Power state is ON ");
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+return 0;
+}
+
+
+
+
+
+ /*-----------------------------------------------------------------------------------*/
+
+
+ /* int rdJoggingEnableCondition()
+ * read if we can enabl the thraed jogging
+ *
+ * return 0 or 1
+ * disable OFF(0) - the machine is working now you cannot jogging the thread.
+ * enable ON(1) - joggin thread is enable
+ */
+
+
+
+uint32_t setJoggingEnableCondition(struct button *pBtn)
+{
+ if (0
+// 1.
+// 2.
+// 3.
+// ...
+ )
+ {
+ pBtn->state = sttDISABLE;
+ REPORT_MSG(pBtn->state,"Jogging : sttDISABLE ");
+ ThreadAbortJoggingFunc();
+ }
+
+ else
+ {
+ pBtn->state = sttENABLE;
+ REPORT_MSG(pBtn->state,"Jogging : sttENABLE ");
+ ThreadJoggingFunc(40);
+ }
+
+return 0;
+}
+
+
+
+
+
+/*int joggingMachine()
+ * state machine for thread jogging button:
+ * 1. OFF - when the machine is working
+ * 2. blue - when the machin is not workig so we can jog thread
+ * 3. blink - when pushing the jog thread button and jogigthread
+ *
+ */
+
+
+uint32_t joggingMachine(uint8_t OnOffPB, struct button *pBtn)
+{
+ if (sttDISABLE == pBtn->state)
+ {
+ // jogging is disable
+ pBtn->color = colorOFF;
+ }
+ else
+ {
+ if (!OnOffPB)
+ {
+ ThreadAbortJoggingFunc(); // to do!!!!
+ pBtn->color = BLUE;
+ }
+ else
+ {
+ pBtn->color = BLINK;
+ ThreadJoggingFunc(40);
+ }
+ }
+return 0;
+}
+
+
+/*------------------------------------------------------------------------------*/
+
+/*------ THREAD LOAD/UNLOAD ----------*/
+
+/*
+int LoadStatMachine(enum PBstat PBAction, struct button *pBtn)
+{
+
+ switch (pBtn->PBstate)
+ {
+ case sttRDY :
+ switch (pBtn->PBAction)
+ {
+ case (SHORTPB):
+ case (LONGPB):
+ case (REPLONGPB):
+ pBtn->PBstate = sttPRELOAD;
+ pBtn->PBcolor = BLINK;
+ if (doPreloading())
+ {
+ pBtn->PBstate = sttPRELOAD ; // to do
+ pBtn->PBcolor = BLUE;
+ }
+ else pBtn->PBstate = sttDISABLE ;
+ break;
+ default :
+ break;
+ }
+ break;
+ case sttPRELOAD:
+ switch (pBtn->PBAction)
+ {
+ case (SHORTPB):
+ case (LONGPB):
+ case (REPLONGPB):
+ if (doLoading())
+ {
+ pBtn->PBstate = sttLOADSUCSESS ; // to do
+ pBtn->PBcolor = BLUE;
+ }
+ else
+ {
+ pBtn->PBstate = sttLOADFAIL ;
+ pBtn->PBcolor = fastBILNK ; // to do
+ }
+ break;
+ default :
+ break;
+ }
+ break;
+ case sttLOADING:
+ break;
+// case sttLOADSUCSESS ?????
+// break;
+// case sttLOADFAIL: ?????
+// break;
+
+ default: //sttDISABLE
+ pBtn->PBcolor = colorOFF;
+ break;
+ }
+ShortLongOffPB( threadPB, ret,struct button *pBtn);
+
+
+}
+*/
+
+
+
diff --git a/Software/Embedded_SW/Embedded/Modules/General/buttons.h b/Software/Embedded_SW/Embedded/Modules/General/buttons.h
new file mode 100644
index 000000000..897fb6031
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/General/buttons.h
@@ -0,0 +1,8 @@
+#ifndef BUTTONS_H
+#define BUTTONS_H
+
+uint32_t Buttons_Init(void);
+uint32_t Button_load_Init(void);
+uint32_t Button_JOG_Init(void);
+
+#endif