Skip to content

Commit

Permalink
clean buadrate settings
Browse files Browse the repository at this point in the history
  • Loading branch information
guruathwal committed Dec 26, 2020
1 parent 984d0b6 commit e104886
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 31 deletions.
2 changes: 0 additions & 2 deletions TFT/src/User/API/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ enum
#define LANGUAGE_CHECK_SIGN (LANGUAGE_FLASH_SIGN + LANGUAGE_ADDR)
#define ICON_CHECK_SIGN (ICON_FLASH_SIGN + ICON_ADDR(0))

#define ITEM_BAUDRATE_NUM 9

#define MAX_EXT_COUNT 6
#define MAX_HOTEND_COUNT 6
#define MAX_HEATER_COUNT (2 + MAX_HOTEND_COUNT) // chamber + bed + hotend
Expand Down
2 changes: 1 addition & 1 deletion TFT/src/User/API/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void parseConfigKey(u16 index)
break;

case C_INDEX_UART_BAUDRATE:
SET_VALID_INT_VALUE(infoSettings.baudrate, 0, ITEM_BAUDRATE_NUM - 1);
SET_VALID_INT_VALUE(infoSettings.baudrate, 0, ITEM_BAUDRATE_COUNT - 1);
break;

case C_INDEX_LANGUAGE:
Expand Down
22 changes: 22 additions & 0 deletions TFT/src/User/API/serialConnection.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "serialConnection.h"
#include "includes.h"

bool serialHasBeenInitialized = false;
const u32 baudrateList[ITEM_BAUDRATE_COUNT] = {2400, 9600, 19200, 38400, 57600, 115200, 250000, 500000, 1000000};

void Serial_ReSourceDeInit(void)
{
if (!serialHasBeenInitialized) return;
serialHasBeenInitialized = false;
Serial_DeInit();
}

void Serial_ReSourceInit(void)
{
if (serialHasBeenInitialized) return;
serialHasBeenInitialized = true;

memset(&infoHost, 0, sizeof(infoHost));
reminderSetUnConnected(); // reset connect status
Serial_Init(infoSettings.baudrate);
}
21 changes: 21 additions & 0 deletions TFT/src/User/API/serialConnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _SERIAL_CONNECTION_H_
#define _SERIAL_CONNECTION_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ITEM_BAUDRATE_COUNT 9

extern const uint32_t baudrateList[ITEM_BAUDRATE_COUNT];

void Serial_ReSourceDeInit(void);
void Serial_ReSourceInit(void);

#ifdef __cplusplus
}
#endif

#endif
11 changes: 5 additions & 6 deletions TFT/src/User/Menu/ConnectionSettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,21 @@ void menuDisconnect(void)
infoMenu.cur--;
}

const char * const item_baudrate_str[ITEM_BAUDRATE_NUM] = {"2400", "9600", "19200", "38400", "57600",
"115200", "250000", "500000", "1000000"};
const u32 item_baudrate[ITEM_BAUDRATE_NUM] = {2400, 9600, 19200, 38400, 57600, 115200, 250000, 500000, 1000000};
const char * const item_baudrate_str[ITEM_BAUDRATE_COUNT] = {"2400", "9600", "19200", "38400", "57600",
"115200", "250000", "500000", "1000000"};

void menuBaudrate(void)
{
LABEL title = {LABEL_BAUDRATE};
LISTITEM totalItems[ITEM_BAUDRATE_NUM];
LISTITEM totalItems[ITEM_BAUDRATE_COUNT];
KEY_VALUES key_num = KEY_IDLE;
SETTINGS now = infoSettings;
uint8_t cur_item = 0;

// fill baudrate items
for(uint8_t i = 0; i < COUNT(totalItems); i++)
{
if (infoSettings.baudrate == item_baudrate[i])
if (infoSettings.baudrate == i)
{
totalItems[i].icon = ICONCHAR_CHECKED;
cur_item = i;
Expand Down Expand Up @@ -97,7 +96,7 @@ void menuBaudrate(void)
totalItems[cur_item].icon = ICONCHAR_CHECKED;
listWidgetRefreshItem(cur_item); // refresh checked status

infoSettings.baudrate = item_baudrate[cur_item];
infoSettings.baudrate = cur_item;
Serial_ReSourceDeInit(); // Serial_Init() will malloc a dynamic memory, so Serial_DeInit() first to free, then malloc again.
Serial_ReSourceInit();
reminderMessage(LABEL_UNCONNECTED, STATUS_UNCONNECT);
Expand Down
18 changes: 0 additions & 18 deletions TFT/src/User/Menu/Mode.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
#include "Mode.h"
#include "includes.h"

bool serialHasBeenInitialized = false;
bool freshboot = true;

void Serial_ReSourceDeInit(void)
{
if (!serialHasBeenInitialized) return;
serialHasBeenInitialized = false;
Serial_DeInit();
}

void Serial_ReSourceInit(void)
{
if (serialHasBeenInitialized) return;
serialHasBeenInitialized = true;

memset(&infoHost, 0, sizeof(infoHost));
reminderSetUnConnected(); // reset connect status
Serial_Init(infoSettings.baudrate);
}

void infoMenuSelect(void)
{
infoMenu.cur = 0;
Expand Down
3 changes: 0 additions & 3 deletions TFT/src/User/Menu/Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ extern "C" {

void infoMenuSelect(void);

void Serial_ReSourceDeInit(void);
void Serial_ReSourceInit(void);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 0 additions & 1 deletion TFT/src/User/Menu/SettingsMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern "C" {
#include <stdint.h>
#include "Settings.h"

extern const u32 item_baudrate[ITEM_BAUDRATE_NUM];
extern uint8_t machine_type[64];

void menuInfo(void);
Expand Down
1 change: 1 addition & 0 deletions TFT/src/User/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "HD44780_Simulator.h"
#include "ui_draw.h"
#include "touch_process.h"
#include "serialConnection.h"
#include "interfaceCmd.h"
#include "coordinate.h"
#include "ff.h"
Expand Down

0 comments on commit e104886

Please sign in to comment.