Skip to content

Commit

Permalink
modified: code.c
Browse files Browse the repository at this point in the history
	modified:   conf.oil
	modified:   inc/WidgetConfig.h
	modified:   inc/app.h
	modified:   src/app.c
	modified:   src/ui.c
  • Loading branch information
chris committed Jun 2, 2024
1 parent f0760f4 commit b6ae3a3
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 67 deletions.
Binary file modified c_mX.bin
Binary file not shown.
34 changes: 7 additions & 27 deletions code.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ TASK(LCD_IN) {

burst <<= 1;
}
/**
* This search for specific words in the message received, but it looks
* for them, starting in the begging of the buffer until where there's
* no more chars, and everytime this task is executed, the RX_READ starts
*.where the last search ended in the buffer.
*/
TASK(ESP8266_POLL) {
if (esp8_status.cmd == ESP8_UNKNOWN) {
esp8266_response();
Expand All @@ -115,15 +109,16 @@ TASK(ESP8266_POLL) {

}

/**
* Task used for FSM.
*/
TASK(NETWORK) {
network();
}

TASK(WEATHER_UPDATE) {
app_fsm_restart();
weather_update();
}

TASK(SPOTIFY_UPDATE) {
spotify_update_player();
}

/*
Expand Down Expand Up @@ -180,29 +175,14 @@ int main(void)
EE_systick_enable_int();
EE_systick_start();

// ui_init();
STM_EVAL_LEDInit(LED4);
UI_init();
esp8266_init();

/* Init Touchscreen */
IOE_Config();
/*Init the LCD*/
STM32f4_Discovery_LCD_Init();
// LCD_LOG_Init();

/**** LCD Calibration Data got with : lcd_touch project ***/
InitTouch(-0.1247, 0.0650, -349, 5);

LCD_Clear(APP_BACKGROUND_COLOR);
LCD_SetColors(APP_BACKGROUND_COLOR, APP_BACKGROUND_COLOR);
DrawInit(weather_ui);
DrawFixWidgets();
LCD_SetFont(&Font8x12);

EXEC(LCD_IN);
EXEC(ESP8266_POLL);
EXEC(NETWORK);
EXEC(WEATHER_UPDATE);
EXEC(SPOTIFY_UPDATE);

for (;;) {
}
Expand Down
20 changes: 19 additions & 1 deletion conf.oil
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ CPU mySystem {

COUNTER myCounter;

/******* NETWORK FSM *******/
ALARM NETWORK_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = NETWORK;};
Expand All @@ -118,6 +119,7 @@ CPU mySystem {
SCHEDULE = FULL;
};

/******* Interface for the ESP8266 *******/
ALARM ESP8266_POLL_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = ESP8266_POLL; };
Expand All @@ -131,6 +133,7 @@ CPU mySystem {
SCHEDULE = FULL;
};

/******* Touch *******/
ALARM LCD_IN_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = LCD_IN; };
Expand All @@ -143,7 +146,8 @@ CPU mySystem {
ACTIVATION = 1; /* only one pending activation */
SCHEDULE = FULL;
};


/******* Weather *******/
ALARM WEATHER_UPDATE_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = WEATHER_UPDATE; };
Expand All @@ -156,6 +160,20 @@ CPU mySystem {
ACTIVATION = 1;
SCHEDULE = FULL;
};

/******* Spotify *******/
ALARM SPOTIFY_UPDATE_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = SPOTIFY_UPDATE; };
};

TASK SPOTIFY_UPDATE {
PRIORITY = 0x02;
AUTOSTART = FALSE;
STACK = SHARED;
ACTIVATION = 1;
SCHEDULE = FULL;
};

ISR systick_handler {
CATEGORY = 2;
Expand Down
3 changes: 1 addition & 2 deletions inc/WidgetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ extern Widget weather_ui[NUMWIDGETS];

void DrawFixWidgets();

// void set_ImageWidget(Image *Img_w, unsigned char *img_ptr);

void UI_init(void);
void UI_clear_progress(void);
void UI_set_progress(short state, short max_state);
void UI_set_err_progress(short state, short max_state);
Expand Down
3 changes: 3 additions & 0 deletions inc/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
#ifndef APP_H
#define APP_H

void spotify_update_player(void);
void weather_update(void);

#endif
68 changes: 33 additions & 35 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

#include "WidgetConfig.h"

#define MATCH(str, res) if(memcmp(str, res, res##_LEN) == 0)
#define MATCH(str, res) if(memcmp(str, res, res##_LEN) == 0)

#define SPOTIFY_UPDATE 0b01
#define WEATHER_UPDATE 0b10
#define SPOTIFY_UPDATE_EVENT 0b01
#define WEATHER_UPDATE_EVENT 0b10

WebAppBuilder_t webAppOptions;
static char spotify_auth_content[SPOTIFY_AUTH_CONTENT_SIZE];
static int16_t spotify_code;
static uint8_t internal_events = 0;


static void app_spotify_conf(uint8_t *success, char *http, void *arg) {

struct Socket *sock = (struct Socket *) arg;
Expand Down Expand Up @@ -472,10 +471,6 @@ void client_function(struct StateS *state) {
}
break;

/*case SPOTIFY:
if (*spotify_token > ' ')
client_id = SPOTIFY_PLAYER;
*/
case SPOTIFY_AUTH:
switch(client_state) {
case CLIENT_CONF:
Expand Down Expand Up @@ -578,28 +573,26 @@ void client_function(struct StateS *state) {

fsm_client(state, &sock);

//if (SUPERSTATE(*state->nx_state) == ESP8SS_READY) {
if (esp8_status.http == HTTP_401) {
client_state = CLIENT_CONF;
// When the Token is expired a renewal is asked
// using the refreshing token.
spotify_code = snprintf(spotify_auth_content,\
SPOTIFY_AUTH_CONTENT_SIZE,\
SPOTIFY_REFRESH_CONTENT, spotify_rtoken);
if (esp8_status.http == HTTP_401) {
client_state = CLIENT_CONF;
// When the Token is expired a renewal is asked
// using the refreshing token.
spotify_code = snprintf(spotify_auth_content,\
SPOTIFY_AUTH_CONTENT_SIZE,\
SPOTIFY_REFRESH_CONTENT, spotify_rtoken);

if (spotify_code < 0 ||\
spotify_code > SPOTIFY_AUTH_CONTENT_SIZE)
{
memset(spotify_auth_content, 0,\
SPOTIFY_AUTH_CONTENT_SIZE);
client_id = LOCATION;
break;
}

client_id = SPOTIFY_AUTH;
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_SSL);
if (spotify_code < 0 ||\
spotify_code > SPOTIFY_AUTH_CONTENT_SIZE)
{
memset(spotify_auth_content, 0,\
SPOTIFY_AUTH_CONTENT_SIZE);
client_id = LOCATION;
break;
}
//}

client_id = SPOTIFY_AUTH;
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_SSL);
}
}
// break;
}
Expand Down Expand Up @@ -632,13 +625,13 @@ void NetEventHandler(struct StateS *s,\
(SUPERSTATE(*s->nx_state) == ESP8SS_READY))
{

if(internal_events & SPOTIFY_UPDATE) {
internal_events &= ~SPOTIFY_UPDATE;
if(internal_events & SPOTIFY_UPDATE_EVENT) {
internal_events &= ~SPOTIFY_UPDATE_EVENT;
*s->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_SSL);
// *client_id = SPOTIFY;
*client_id = SPOTIFY;

} else if (internal_events & WEATHER_UPDATE) {
internal_events &= ~WEATHER_UPDATE;
} else if (internal_events & WEATHER_UPDATE_EVENT) {
internal_events &= ~WEATHER_UPDATE_EVENT;
*s->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_TCP);
*client_id = LOCATION;
}
Expand All @@ -651,6 +644,11 @@ void NetEventHandler(struct StateS *s,\
* This is called by a another Tasks that will restart the APP FSM to
* update the weather info.
*/
void app_fsm_restart(void) {
internal_events |= SPOTIFY_UPDATE;
void spotify_update_player(void) {
internal_events |= SPOTIFY_UPDATE_EVENT;
}

void weather_update(void) {
internal_events |= WEATHER_UPDATE_EVENT;
}

24 changes: 22 additions & 2 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#include <time.h>
#include <stdlib.h>

#include "stm32f4_discovery.h"
#include "WidgetConfig.h"

#include "Widget.h"
#include "fonts.h"
#include "STMPE811QTR.h"

#include "OW01d.h"
#include "OW02d.h"
Expand Down Expand Up @@ -149,7 +151,7 @@ void DrawFixWidgets() {
WPrint(&weather_ui[TEMP_DEGREE2_STR], "C");
WPrintLog(&weather_ui[SPOTIFY_STATUS], "Spotify Non Connected");

/* Buton Bar */
/* Button Bar */
LCD_SetColors(0x3b2d, 0x3b2d);
LCD_DrawFullRect(19, 172, 288, 51);
LCD_SetColors(0x03dd, 0x03d2d);
Expand All @@ -159,10 +161,28 @@ void DrawFixWidgets() {
LCD_SetColors(APP_BACKGROUND_COLOR, APP_BACKGROUND_COLOR);
/*************/


DrawOff(&weather_ui[WiFi_AP_SET]);
DrawOff(&weather_ui[SPOTIFY]);
}
void UI_init(void) {
STM_EVAL_LEDInit(LED4);

/* Init Touchscreen */
IOE_Config();
InitTouch(-0.1247, 0.0650, -349, 5);

STM32f4_Discovery_LCD_Init();
// LCD_LOG_Init();

LCD_Clear(APP_BACKGROUND_COLOR);
LCD_SetColors(APP_BACKGROUND_COLOR, APP_BACKGROUND_COLOR);

DrawInit(weather_ui);

DrawFixWidgets();

LCD_SetFont(&Font8x12);
}

/**************** PROGRESS BAR FUNCTIONS ***************/
#define PROGRESS_BAR_Y 237
Expand Down

0 comments on commit b6ae3a3

Please sign in to comment.