Scheduler.cpp
)
+set_target_properties(
+ workmeter-${AVR_MCU}.elf PROPERTIES
+ COMPILE_DEFINITIONS WORKMETER_PARAMETERS
+ )
+
target_link_libraries(
workmeter-${AVR_MCU}.elf
avrHAL-${AVR_MCU}
//#include <avr/io.h>
#include <Utils/StdTypes.h>
#include <Platform/IParameterHandler.h>
-#include <Metadata/PowerswitchParamIds.h>
+#include <Metadata/WorkMeterParamIds.h>
#include "Led0.h"
/**
WorkMeterHandler::WorkMeterHandler(IRtc *argRtc,ILCD *argLCD,IParameterHandler *argPH,PN532 *argPN532)
- : m_Rtc(argRtc), m_LCD(argLCD),m_NFC(argPN532),m_Params(argPH),m_Ticks(0),m_State(ST_IDLE)
+ : m_Rtc(argRtc), m_LCD(argLCD),m_NFC(argPN532),m_Params(argPH),m_Ticks(0),m_State(ST_INIT)
{
Uint8_t i = 0;
m_Params->writeValue(PID_Seconde,i);
m_Params->registerListener(PID_Hour,this); /* State on or off */
m_Params->registerListener(PID_Minute,this); /* State on or off */
+ m_Params->registerListener(PID_Anne,this); /* Write Date to RTC */
+ m_Params->registerListener(PID_Mois,this); /* Write Date to RTC */
+ m_Params->registerListener(PID_Jour,this); /* Write Date to RTC */
}
+void WorkMeterHandler::onWriteValue(const Uint8_t paramID,const Uint16_t _val)
+{
+ switch (paramID)
+ {
+ case PID_Anne:
+ m_Date.year = _val;
+ m_State = ST_SET_DATE;
+ break;
+ }
+}
void WorkMeterHandler::onWriteValue(const Uint8_t paramID,const Uint8_t _val)
{
switch (paramID)
m_Time.hour = _val;
m_State = ST_SET_TIME;
break;
+ case PID_Jour:
+ m_Date.day = _val;
+ m_State = ST_SET_DATE;
+ break;
+ case PID_Mois:
+ m_Date.month = _val;
+ m_State = ST_SET_DATE;
+ break;
case PID_BackLight:
m_LCD->setDisplay(_val);
break;
m_StrTime[2] = ':';
m_StrTime[3] = (m_Time.min / 10 ) + 0x30;
m_StrTime[4] = (m_Time.min - (( m_Time.min / 10) * 10 )) +0x30;
+#if 0
m_StrTime[5] = ':';
m_StrTime[6] = (m_Time.seconds / 10) + 0x30;
m_StrTime[7] = ((m_Time.seconds) -( (m_Time.seconds / 10) *10 )) + 0x30;
m_StrTime[8] = 0;
+#else
+ m_StrTime[5] = 0;
+#endif
}
void WorkMeterHandler::getTime()
{
}
+void WorkMeterHandler::getDate()
+{
+ m_Rtc->getDate(m_Date);
+ m_Params->writeValue(PID_Jour,m_Date.day);
+ m_Params->writeValue(PID_Mois,m_Date.month);
+ m_Params->writeValue(PID_Anne,m_Date.year);
+}
+
/**
* Cycle of scheduler is 10ms. So the cycle below is 1s
*
}
switch (m_State)
{
+ case ST_INIT:
+ m_State = ST_GET_DATE;
+ break;
case ST_IDLE:
m_State = ST_GET_TIME;
break;
getTime();
m_State = ST_DISP_UPDATE_CURSOR;
break;
+ case ST_SET_DATE:
+ m_Rtc->setDate(m_Date);
+ m_State = ST_WAIT;
+ case ST_GET_DATE:
+ getDate();
+ m_State = ST_GET_TIME;
case ST_DISP_UPDATE_CURSOR_TAG:
m_LCD->setCursor(11,0);
m_State = ST_DISP_UPDATE_TAG;
class WorkMeterHandler : public ITask, public IParameterListener
{
enum eStates {
- ST_IDLE
+ ST_INIT
+ ,ST_IDLE
,ST_GET_TIME
,ST_SET_TIME
+ ,ST_GET_DATE
+ ,ST_SET_DATE
,ST_WAIT_BADGE
,ST_WAIT
,ST_DISP_UPDATE_TIME
void onWriteValue(const Uint8_t paramID,const Uint8_t _val) ;
+ void onWriteValue(const Uint8_t paramID,const Uint16_t _val) ;
+
void onWriteValue(const Uint8_t paramID,const Float32_t _val) ;
private:
void timeToString();
/**/
void getTime();
/**/
+ void getDate();
+ /**/
void setTime();
Bool_t tagPresenceChanged();
PN532 *m_NFC;
IParameterHandler *m_Params;
RtcTime_t m_Time;
+ RtcDate_t m_Date;
Uint32_t m_Ticks;
Uint8_t m_State;
Bool_t m_TagChange;
} RtcTime_t;
typedef struct {
+ Uint16_t year;
Uint8_t weekDay;
Uint8_t day;
Uint8_t month;
- Uint16_t year;
} RtcDate_t;
/**
* \brief Abstract interface of services an Rtc must Provide
{
Uint8_t cmd[5] ;
// Day of the week
- cmd[0] = 0;
- itsII2C->write(DS3231_ADDRESS,cmd,1);
+ cmd[0] = 0x04;
+ cmd[1] = (argDate.day / 10) << 4;
+ cmd[1] |= argDate.day - ((argDate.day / 10) *10);
+ cmd[2] = 0x00; // Set Century to true
+ cmd[2] |= (argDate.month / 10) << 4;
+ cmd[2] |= argDate.month - ((argDate.month / 10) * 10);
+ Uint8_t shiftYear = static_cast<Uint8_t>((argDate.year - 2000));
+ cmd[3] = (shiftYear / 10) <<4;
+ cmd[3] |= (shiftYear - ( (shiftYear / 10) * 10 ));
+ itsII2C->write(DS3231_ADDRESS,cmd,4);
}
void DS3231::getDate(RtcDate_t &argDate)
{
+ Uint8_t cmd[5] ;
+ // Day of the week
+ cmd[0] = 0x04;
+ itsII2C->write(DS3231_ADDRESS,cmd,1);
+ itsII2C->read(DS3231_ADDRESS,cmd,3);
+ argDate.day = cmd[0] & 0x0F;
+ argDate.day += ((cmd[0] & 0xF0)>>4) * 10;
+ argDate.month = ((cmd[1] &0x70)>>4 ) * 10 + (cmd[1] &0x0F) ;
+ argDate.year = ( (cmd[1] & 0x80)>>7 ) * 100 + 2000 ;
+ argDate.year += ( ((cmd[2] & 0xF0)>>4 ) * 10 ) + (cmd[2] & 0x0F);
}
void DS3231::toString(Uint8_t *argOutTime)
, PID_Seconde = 1 /* On / Off Socket 1 */
, PID_Minute = 2 /* On / Off Socket 2 */
, PID_Hour = 3 /* On / Off Socket 3 */
- , PID_BackLight = 4 /* On / Off Socket 4 */
- , PID_LedCycle = 5 /* Ye Blinking led cycle. 0 is off */
- , PID_LedState = 6 /* Set let state ... */
- , PID_Display = 7 /* Set On/Off Display */
- , PID_RFFirmwareVersion = 8
- , PID_FirmwareVersion = 9 /* Cycle Per rotation used in closed loop */
- , PID_BadgePresent = 10 /* Set PID constant factor */
- , PID_BadgeCount = 11 /* Set PID integral factor */
- , PID_BadgeLength = 12 /* Badge ID length */
- , PID_BadgeLow = 13 /* Write 4 bytes low badge ID */
- , PID_BadgeHigh = 14 /* When 7 bytes Length add the 3 high bytes here */
- , PID_LowLevelError1 = 15 /* Low Level Error1 up to 32 errors */
- , PID_LowLevelError2 = 16 /* Low Level Error2 up to 32 errors */
- , PID_MAX = 17
+ , PID_Jour = 4 /* On / Off Socket 3 */
+ , PID_Mois = 5 /* On / Off Socket 3 */
+ , PID_Anne = 6 /* On / Off Socket 3 */
+ , PID_BackLight = 7 /* On / Off Socket 4 */
+ , PID_LedCycle = 8 /* Ye Blinking led cycle. 0 is off */
+ , PID_LedState = 9 /* Set let state ... */
+ , PID_Display = 10 /* Set On/Off Display */
+ , PID_RFFirmwareVersion = 11
+ , PID_FirmwareVersion = 12 /* Cycle Per rotation used in closed loop */
+ , PID_BadgePresent = 13 /* Set PID constant factor */
+ , PID_BadgeCount = 14 /* Set PID integral factor */
+ , PID_BadgeLength = 14 /* Badge ID length */
+ , PID_BadgeLow = 16 /* Write 4 bytes low badge ID */
+ , PID_BadgeHigh = 17 /* When 7 bytes Length add the 3 high bytes here */
+ , PID_LowLevelError1 = 18 /* Low Level Error1 up to 32 errors */
+ , PID_LowLevelError2 = 19 /* Low Level Error2 up to 32 errors */
+ , PID_MAX = 20
};
#endif
,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_I32<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
+ ,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
,{0,NULL , (TYPE_U8<<4) | (NONE<<2) | (RW)}
IParameterListener() {};
virtual void onWriteValue(const uint8_t paramID,const uint8_t _val) = 0;
+ virtual void onWriteValue(const uint8_t paramID,const uint16_t _val) = 0;
virtual void onWriteValue(const uint8_t paramID,const Float32_t _val) = 0;
};
m_Values[paramID].u.m_U16 = _val;
if (m_Values[paramID].m_Listener != 0 )
{
- m_Values[paramID].m_Listener->onWriteValue(paramID,m_Values[paramID].u.m_U8);
+ m_Values[paramID].m_Listener->onWriteValue(paramID,m_Values[paramID].u.m_U16);
}
}
}
m_Values[paramID].u.m_U32 = _val;
if (m_Values[paramID].m_Listener != 0 )
{
- m_Values[paramID].m_Listener->onWriteValue(paramID,m_Values[paramID].u.m_U8);
+ m_Values[paramID].m_Listener->onWriteValue(paramID,m_Values[paramID].u.m_U16);
}
}
}