Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board

Dependencies:   BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src

main.cpp

Committer:
the_sz
Date:
2015-11-12
Revision:
8:51e0f01d5c74
Parent:
7:dc29f6647486
Child:
9:fe2c9b3a312b

File content as of revision 8:51e0f01d5c74:

#include "WakeupLight.h"

int                             lastCheckedMinute=-1;

void checkForAlarmSpecified(struct tm *tmStruct,CONFIG_TYPE_ENUM typeTime,CONFIG_TYPE_ENUM typeFlags)
{
    uint32_t                    value;
    bool                        checkTime;

    value=Config_Get(typeFlags);
    if (value!=0)
    {
        checkTime=false;

        DPrintf("checkForAlarmSpecified: %u.\r\n",tmStruct->tm_wday);

        if (((value & CONFIG_ALARM_MASK_MONDAY)!=0) && (tmStruct->tm_wday==1))
            checkTime=true;
        if (((value & CONFIG_ALARM_MASK_TUESDAY)!=0) && (tmStruct->tm_wday==2))
            checkTime=true;
        if (((value & CONFIG_ALARM_MASK_WEDNESDAY)!=0) && (tmStruct->tm_wday==3))
            checkTime=true;
        if (((value & CONFIG_ALARM_MASK_THURSDAY)!=0) && (tmStruct->tm_wday==4))
            checkTime=true;
        if (((value & CONFIG_ALARM_MASK_FRIDAY)!=0) && (tmStruct->tm_wday==5))
            checkTime=true;
        if (((value & CONFIG_ALARM_MASK_SATURDAY)!=0) && (tmStruct->tm_wday==6))
            checkTime=true;
        if (((value & CONFIG_ALARM_MASK_SUNDAY)!=0) && (tmStruct->tm_wday==0))
            checkTime=true;
            
        if (checkTime==true)
        {
            value=Config_Get(typeTime);
            if (value==((tmStruct->tm_hour << 8) | (tmStruct->tm_min)))
            {
                DPrintf("checkForAlarmSpecified: Alarm detecetd.\r\n");
                LED_StartAnimation(LAE_WAKEUP);
            }
        }
    }
}
    
void checkForAlarm(void)
{
    struct tm                   *tmStruct;
    time_t                      timeValue;

    timeValue=time(NULL);
    tmStruct=localtime(&timeValue);
    
    if (tmStruct->tm_min!=lastCheckedMinute)
    {
        lastCheckedMinute=tmStruct->tm_min;
        
        // check all alarm against current time
        checkForAlarmSpecified(tmStruct,CT_ALARM_1_TIME,CT_ALARM_1_MASK);
        checkForAlarmSpecified(tmStruct,CT_ALARM_2_TIME,CT_ALARM_2_MASK);
        checkForAlarmSpecified(tmStruct,CT_ALARM_3_TIME,CT_ALARM_3_MASK);
        checkForAlarmSpecified(tmStruct,CT_ALARM_4_TIME,CT_ALARM_4_MASK);
        checkForAlarmSpecified(tmStruct,CT_ALARM_5_TIME,CT_ALARM_5_MASK);
        checkForAlarmSpecified(tmStruct,CT_ALARM_6_TIME,CT_ALARM_6_MASK);
    }
}

#include "stm32746g_discovery_audio.h"

uint16_t buffer[2000];
void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
{
    DPrintf("***1");
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
}
void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
{
    DPrintf("***2");
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
}
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
{
    DPrintf("***3");
}
    
int main()
{
    debug_Init();

    DPrintf("WakeupLight - Hardware v%08X.\r\n",BSP_GetVersion());

    OnBoardLED_Init();

    LED_Init();

    UI_Init();

    Config_Init();


// OUTPUT_DEVICE_SPEAKER OUTPUT_DEVICE_BOTH
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE,100,8000);
uint32_t index;
for (index=0;index<100;index++)
{
    if ((index % 2)==0)
        buffer[index]=0x0000;
    else
        buffer[index]=0x7000;
}
    
BSP_AUDIO_OUT_Play(buffer, sizeof(buffer)*sizeof(uint16_t));
/*
#include "SDFileSystem.h"
SDFileSystem sd(PD_2, PC_8, PC_12, PC_11, "sd"); // MOSI, MISO, SCLK, SSEL
DigitalOut sdsd(PC_9);
mkdir("/sd/foo",0777);
FILE *fp = fopen("/sd/mbed.txt", "w");
fprintf(fp, "Hello World!\n");
fclose(fp);
*/

    for (;;)
    {
        checkForAlarm();

        UI_Poll();
    }
}