extern encodertest * encodertestNew(pin * pPinA, pin * pPinB, int Max) { oosmos_Allocate(pEncoderTest, encodertest, MAX_ENCODERTESTS, NULL); // StateName Parent Default // ====================================================== oosmos_StateMachineInit(pEncoderTest, StateMachine, NULL, Idle_State); oosmos_LeafInit (pEncoderTest, Idle_State, StateMachine ); encoder * pEncoder = encoderNew(pPinA, pPinB, Max); encoderSubscribeChangeEvent(pEncoder, &pEncoderTest->EventQueue, ChangeEvent, NULL); pEncoderTest->m_pEncoder = pEncoder; return pEncoderTest; }
extern switchtest * switchtestNew(pin * pPin) { oosmos_Allocate(pSwitchTest, switchtest, MAX_SWITCHTESTS, NULL); /* StateName Parent Default */ /* ===================================================== */ oosmos_StateMachineInit(pSwitchTest, StateMachine, NULL, Idle_State); oosmos_LeafInit (pSwitchTest, Idle_State, StateMachine ); sw * pSwitch = swNew(pPin); swSubscribeOpenEvent(pSwitch, &pSwitchTest->EventQueue, OpenEvent, NULL); swSubscribeCloseEvent(pSwitch, &pSwitchTest->EventQueue, ClosedEvent, NULL); return pSwitchTest; }
extern matrix * matrixNew(int Rows, int Columns, ...) { oosmos_Allocate(pMatrix, matrix, matrixMAX, NULL); pMatrix->m_Rows = 0; pMatrix->m_Columns = 0; int RowIndex; for (RowIndex = 0; RowIndex < matrixMAX_ROWS; RowIndex++) { pMatrix->m_pRowPins[RowIndex] = NULL; int ColumnIndex; for (ColumnIndex = 0; ColumnIndex < matrixMAX_COLS; ColumnIndex++) { pMatrix->m_pColumnPins[ColumnIndex] = NULL; pMatrix->m_pSwitch[RowIndex][ColumnIndex] = NULL; } } // StateName Parent Default // ===================================================== oosmos_StateMachineInitNoQueue(pMatrix, StateMachine, NULL, Running_State); oosmos_LeafInit (pMatrix, Running_State, StateMachine ); va_list ArgList; va_start(ArgList, Columns); int Row; for (Row = 1; Row <= Rows; Row += 1) AddRow(pMatrix, Row, va_arg(ArgList, pin *)); int Column; for (Column = 1; Column <= Columns; Column += 1) AddColumn(pMatrix, Column, va_arg(ArgList, pin *)); va_end(ArgList); return pMatrix; }
extern key * keyNew(char Char) { static bool Initialized = false; oosmos_Allocate(pKey, key, keyMAX, NULL); if (!Initialized) { hStdin = GetStdHandle(STD_INPUT_HANDLE); Initialized = true; } oosmos_RegisterActiveObject(pKey, StateMachine, &pKey->m_ActiveObject); pKey->m_Char = Char; pKey->m_State = Up_State; oosmos_SubscriberListInit(pKey->m_PressedEvent); oosmos_SubscriberListInit(pKey->m_ReleasedEvent); return pKey; }
static test * testNew(void) { oosmos_Allocate(pTest, test, 1, NULL); // StateName Parent Default // ================================================================================================= oosmos_StateMachineInit (pTest, StateMachine, NULL, Active_State ); oosmos_OrthoInitNoCode (pTest, Active_State, StateMachine ); oosmos_OrthoRegionInitNoCode(pTest, Active_Top_State, Active_State, Active_Top_Moving_State ); oosmos_LeafInitNoCode (pTest, Active_Top_Moving_State, Active_Top_State ); oosmos_OrthoRegionInit (pTest, Active_Middle_State, Active_State, Active_Middle_Idle_State ); oosmos_CompositeInitNoCode(pTest, Active_Middle_Idle_State, Active_Middle_State, Active_Middle_Idle_Inner_State); oosmos_LeafInitNoCode (pTest, Active_Middle_Idle_Inner_State, Active_Middle_Idle_State ); oosmos_OrthoRegionInitNoCode(pTest, Active_Base_State, Active_State, Active_Base_Leaf_State ); oosmos_LeafInit (pTest, Active_Base_Leaf_State, Active_Base_State ); oosmos_LeafInitNoCode (pTest, Active_Base_Running_State, Active_Base_State ); oosmos_Debug(&pTest->StateMachine, true, NULL); return pTest; }
extern lcd * lcdNew(pin * pRS, pin * pRW, pin * pE, pin * pData4, pin * pData5, pin * pData6, pin * pData7) { oosmos_Allocate(pLCD, lcd, lcdMAX, NULL); pLCD->m_pRS = pRS; pLCD->m_pRW = pRW; pLCD->m_pE = pE; pLCD->m_pData4 = pData4; pLCD->m_pData5 = pData5; pLCD->m_pData6 = pData6; pLCD->m_pData7 = pData7; oosmos_DelayMS(50); CommandFunctionSetInit(pLCD, bits8); oosmos_DelayUS(4100); // // The data sheet does not say one needs to do this twice. However, // the Arduino does it twice, and it definitely makes the display // more stable when reloading new code without a cold reset. // CommandFunctionSetInit(pLCD, bits8); oosmos_DelayUS(4100); CommandFunctionSetInit(pLCD, bits8); oosmos_DelayUS(100); CommandFunctionSetInit(pLCD, bits4); CommandFunctionSet(pLCD, bits4, lines2, font5x8); CommandDisplaySet(pLCD, displayOn, cursorOff, blinkingOff); CommandClearDisplay(pLCD); CommandEntryModeSet(pLCD, entryIncrement, shiftOff); return pLCD; }
extern keypad * keypadNew(matrix * pMatrix) { oosmos_Allocate(pKeypad, keypad, 1, NULL); // StateName Parent Default // ================================================ oosmos_StateMachineInit(pKeypad, StateMachine, NULL, Idle_State); oosmos_LeafInit (pKeypad, Idle_State, StateMachine ); NewSwitchWithContext(pKeypad, pMatrix, 1, 1, "1"); NewSwitchWithContext(pKeypad, pMatrix, 1, 2, "2"); NewSwitchWithContext(pKeypad, pMatrix, 1, 3, "3"); NewSwitchWithCodes (pKeypad, pMatrix, 2, 1, FourPressedEvent, FourReleasedEvent); NewSwitchWithContext(pKeypad, pMatrix, 2, 2, "5"); NewSwitchWithContext(pKeypad, pMatrix, 2, 3, "6"); NewSwitchWithContext(pKeypad, pMatrix, 3, 1, "7"); NewSwitchWithContext(pKeypad, pMatrix, 3, 2, "8"); NewSwitchWithContext(pKeypad, pMatrix, 3, 3, "9"); return pKeypad; }