First working prototype

This commit is contained in:
Charlez Kwan 2020-02-06 13:29:37 +01:00
parent 4d3ea331f2
commit 2060cd1233
3 changed files with 104 additions and 30 deletions

View file

@ -86,6 +86,8 @@ void Error_Handler(void);
#define BUSY_GPIO_Port GPIOA
#define SPI_CS_Pin GPIO_PIN_4
#define SPI_CS_GPIO_Port GPIOA
#define TimerControl_Pin GPIO_PIN_10
#define TimerControl_GPIO_Port GPIOB
#define ButtonLeft_Pin GPIO_PIN_12
#define ButtonLeft_GPIO_Port GPIOB
#define ButtonPress_Pin GPIO_PIN_13

View file

@ -47,6 +47,7 @@
#include "DEV_Config.h"
#include "GUI_Paint.h"
#include "ImageData.h"
#include "eeprom.h"
#include <stdlib.h>
#include <stdbool.h>
/* USER CODE END Includes */
@ -95,7 +96,7 @@ const uint8_t WeekLetter[7][2]={
enum Mode{Running, Choose, Set, Offscreen};
uint8_t system_mode = Running;
uint8_t setWeekday,weekday,hour,minsec;
uint8_t selector_pos;
uint8_t selector_pos = 0;
//Create a new image cache
UBYTE *BlackImage;
UWORD Imagesize = ((EPD_WIDTH % 8 == 0) ? (EPD_WIDTH / 8) : (EPD_WIDTH / 8 + 1)) * EPD_HEIGHT;
@ -113,6 +114,8 @@ void Paint_DrawArray(void);
void Paint_DrawCurrent(void);
void Paint_Drawonoff(bool);
void Paint_Selector(bool, uint8_t,uint8_t);
void System_bjt_output(bool);
void System_screenfullupdate(bool);
bool System_fire(void);
bool System_CustomHeartbeat(uint8_t);
void ButtonLeft_Pressed(void);
@ -124,6 +127,8 @@ void Change_selectorpos(bool);
void Change_time(uint8_t,bool);
void Read_intosettime(void);
void Write_intostime(void);
void Eeprom_loadsettings(void);
void Eeprom_savesettings(void);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
@ -186,33 +191,35 @@ int main(void)
printf("e-Paper init failed\r\n");
}
Paint_SelectImage(BlackImage);
Eeprom_loadsettings();
selector_pos = 0;
for (;;){
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); // Get Time
HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN); // Get Date
sPaint_time.Hour = sTime.Hours;
sPaint_time.Min = sTime.Minutes;
sPaint_time.Sec = sTime.Seconds;
// printf("hour %i :",sPaint_time.Hour);
// printf("min %i :",sPaint_time.Min);
if(system_mode!=Offscreen){
// System_screenfullupdate(System_CustomHeartbeat(1));
Paint_SelectImage(BlackImage);
Paint_Clear(WHITE);
Paint_DrawArray();
Paint_DrawCurrent();
Paint_Selector(System_CustomHeartbeat(2),selector_pos, system_mode);
}else{
Paint_Clear(WHITE);
Paint_DrawString_EN(0,0,"You can remove the monitor",&Font16,WHITE,BLACK);
Paint_Drawonoff(System_fire());
EPD_Display(BlackImage);
DEV_Delay_ms(50); //Analog clock 1s
}
Paint_Drawonoff(System_fire());
// printf("sTime hour:", sTime.Hours);
// printf(" : sTime min :", sTime.Minutes);
// printf("\r\n");
EPD_Display(BlackImage);
DEV_Delay_ms(50); //Analog clock 1s
System_bjt_output(System_fire());
// else{
// Paint_Clear(WHITE);
// Paint_DrawString_EN(0,0,"You can remove the monitor",&Font16,WHITE,BLACK);
// EPD_Display(BlackImage);
// DEV_Delay_ms(50); //Analog clock 1s
// EPD_Sleep();
// }
// printf("500ms..\r\n");
if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_12)){
ButtonLeft_Pressed();
@ -224,11 +231,31 @@ int main(void)
ButtonRight_Pressed();
}
if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_15)){
if(system_mode == Running){
system_mode = Offscreen;
}else{
system_mode = Running;
}
HAL_Delay(100);
if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_15)){
if(system_mode == Running){
for(uint8_t i = 0 ; i<3 ;i++){
system_mode = Offscreen;
Paint_Clear(WHITE);
Paint_DrawString_EN(0,0,"You can remove the monitor",&Font16,WHITE,BLACK);
EPD_Display(BlackImage);
DEV_Delay_ms(200); //Analog clock 1s
}
EPD_Sleep();
}else{
// for(uint8_t i = 0 ; i<2 ;i++){
//Partial refresh, example shows time
if (EPD_Init(lut_partial_update) != 0){
printf("e-Paper init failed\r\n");
}
Paint_SelectImage(BlackImage);
EPD_Display(BlackImage);
DEV_Delay_ms(200);
// }
system_mode = Running;
}
}
}
}
@ -437,7 +464,7 @@ static void MX_GPIO_Init(void)
HAL_GPIO_WritePin(GPIOA, RST_Pin|DC_Pin|BUSY_Pin|SPI_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, TimerControl_Pin|LED_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : RST_Pin DC_Pin BUSY_Pin SPI_CS_Pin */
GPIO_InitStruct.Pin = RST_Pin|DC_Pin|BUSY_Pin|SPI_CS_Pin;
@ -446,19 +473,19 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : TimerControl_Pin LED_Pin */
GPIO_InitStruct.Pin = TimerControl_Pin|LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : ButtonLeft_Pin ButtonPress_Pin ButtonRight_Pin system_mode_Pin */
GPIO_InitStruct.Pin = ButtonLeft_Pin|ButtonPress_Pin|ButtonRight_Pin|system_mode_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : LED_Pin */
GPIO_InitStruct.Pin = LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
@ -514,6 +541,11 @@ void Paint_DrawCurrent(){
// Paint_DrawTime(50,175, &sPaint_time, &Font24, WHITE, BLACK);
Paint_DrawChar(140,175,WeekLetter[weekday][0],&Font20,WHITE,BLACK);
Paint_DrawChar(152,175,WeekLetter[weekday][1],&Font20,WHITE,BLACK);
//debug
Paint_DrawChar(0 , 175, value[sPaint_time.Sec / 10] , &Font24, WHITE, BLACK);
Paint_DrawChar(15 , 175, value[sPaint_time.Sec % 10] , &Font24, WHITE, BLACK);
}
void Paint_Drawonoff(bool draw_yes){
@ -548,7 +580,27 @@ void Paint_Selector(bool heartbeat,uint8_t pos, uint8_t runningmode){
}
bool System_fire(){ // TODO the comparison is still wrong( same start hour but different end hour doesnt work)
void System_bjt_output(bool on){
if(on){
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_SET);
}else{
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_RESET);
}
}
void System_screenfullupdate(bool heartbeat){
if(heartbeat){
if (EPD_Init(lut_full_update) != 0){
printf("e-Paper init failed\r\n");
}
}else{
if (EPD_Init(lut_partial_update) != 0){
printf("e-Paper init failed\r\n");
}
}
}
bool System_fire(){
uint16_t Activetime_length_min=0, Currenttime_length_min=0;
@ -645,7 +697,9 @@ void ButtonPress_Pressed(void){
}
}
}
if(system_mode == Set){
Eeprom_savesettings();
}
Change_systemmode();
};
//keep it short, executed in ISR
@ -758,6 +812,24 @@ void Write_intostime(){
sDate.Date = setWeekday + 2; //date hack because the RTC auto detect the weekday from the date
}
void Eeprom_loadsettings(){
for(uint8_t i=0 ; i < 7 ; i++){
sSetStart[i].Hours = (uint8_t) (readEEPROMHalfWord(2*i) >> 8);
sSetStart[i].Minutes = (uint8_t) readEEPROMHalfWord(2*i);
sSetEnd[i].Hours = (uint8_t) (readEEPROMHalfWord(2*i + 14) >> 8);
sSetEnd[i].Minutes = (uint8_t) readEEPROMHalfWord(2*i + 14);
}
}
void Eeprom_savesettings(){
enableEEPROMWriting();
for(uint8_t i = 0; i < 7; i++){
writeEEPROMHalfWord(2*i,sSetStart[i].Hours << 8 | sSetStart[i].Minutes);
writeEEPROMHalfWord(2*i + 14,sSetEnd[i].Hours << 8 | sSetEnd[i].Minutes);
}
disableEEPROMWriting();
}
int __io_putchar(int ch){
uint8_t c[1];
c[0] = ch & 0x00FF;

View file

@ -236,5 +236,5 @@ void EPD_Sleep(void)
{
EPD_SendCommand(DEEP_SLEEP_MODE);
EPD_SendData(0x01);
// EPD_WaitUntilIdle();
EPD_WaitUntilIdle();
}