Skip to content

Global/Individual Settings for LED, Button, Log configurable by Terminal Command #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions Firmware/Chameleon-Mini/Button.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Map.h"
#include "Terminal/CommandLine.h"
#include "Application/Application.h"
#include "UserInterface.h"

#define BUTTON_PORT PORTA
#define BUTTON_L PIN5_bm
Expand Down Expand Up @@ -215,8 +216,17 @@ void ButtonTick(void)
} else if (ButtonRPressTick == LONG_PRESS_TICK_COUNT) {
/* Long button press detected execute button action and advance PressTickCounter
* to an invalid state. */
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL){
ExecuteButtonAction(GLOBAL_UI_STORAGE.ButtonActions[BUTTON_R_PRESS_LONG]);
}
else {
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_LONG]);
}
#else
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_LONG]);
ButtonRPressTick++;
#endif
ButtonRPressTick++;
} else {
/* Button is still pressed, ignore */
}
Expand All @@ -225,7 +235,16 @@ void ButtonTick(void)
* a recent short button press. */
if ( (ButtonRPressTick > 0) && (ButtonRPressTick <= LONG_PRESS_TICK_COUNT) ) {
/* We have a short button press */
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL){
ExecuteButtonAction(GLOBAL_UI_STORAGE.ButtonActions[BUTTON_R_PRESS_SHORT]);
}
else {
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_SHORT]);
}
#else
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_R_PRESS_SHORT]);
#endif
}

ButtonRPressTick = 0;
Expand All @@ -239,8 +258,17 @@ void ButtonTick(void)
} else if (ButtonLPressTick == LONG_PRESS_TICK_COUNT) {
/* Long button press detected execute button action and advance PressTickCounter
* to an invalid state. */
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL){
ExecuteButtonAction(GLOBAL_UI_STORAGE.ButtonActions[BUTTON_L_PRESS_LONG]);
}
else {
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_LONG]);
}
#else
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_LONG]);
ButtonLPressTick++;
#endif
ButtonLPressTick++;
} else {
/* Button is still pressed, ignore */
}
Expand All @@ -249,7 +277,16 @@ void ButtonTick(void)
* a recent short button press. */
if ( (ButtonLPressTick > 0) && (ButtonLPressTick <= LONG_PRESS_TICK_COUNT) ) {
/* We have a short button press */
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL){
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_SHORT]);
}
else {
ExecuteButtonAction(GLOBAL_UI_STORAGE.ButtonActions[BUTTON_L_PRESS_SHORT]);
}
#else
ExecuteButtonAction(GlobalSettings.ActiveSettingPtr->ButtonActions[BUTTON_L_PRESS_SHORT]);
#endif
}

ButtonLPressTick = 0;
Expand All @@ -263,6 +300,16 @@ void ButtonGetActionList(char* List, uint16_t BufferSize)

void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action)
{
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL){
GlobalSettings.ActiveSettingPtr->ButtonActions[Type] = Action;
}
else
{
GLOBAL_UI_STORAGE.ButtonActions[Type] = Action;
}
#else

#ifndef BUTTON_SETTING_GLOBAL
GlobalSettings.ActiveSettingPtr->ButtonActions[Type] = Action;
#else
Expand All @@ -271,12 +318,24 @@ void ButtonSetActionById(ButtonTypeEnum Type, ButtonActionEnum Action)
GlobalSettings.Settings[i].ButtonActions[Type] = Action;
}
#endif
#endif
}

void ButtonGetActionByName(ButtonTypeEnum Type, char* Action, uint16_t BufferSize)
{
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL){
MapIdToText(ButtonActionMap, ARRAY_COUNT(ButtonActionMap),
GlobalSettings.ActiveSettingPtr->ButtonActions[Type], Action, BufferSize);
}
else {
MapIdToText(ButtonActionMap, ARRAY_COUNT(ButtonActionMap),
GLOBAL_UI_STORAGE.ButtonActions[Type], Action, BufferSize);
}
#else
MapIdToText(ButtonActionMap, ARRAY_COUNT(ButtonActionMap),
GlobalSettings.ActiveSettingPtr->ButtonActions[Type], Action, BufferSize);
#endif
}

bool ButtonSetActionByName(ButtonTypeEnum Type, const char* Action)
Expand Down
52 changes: 50 additions & 2 deletions Firmware/Chameleon-Mini/LED.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "Terminal/CommandLine.h"
#include "System.h"
#include "UserInterface.h"

#define BLINK_PRESCALER 1 /* x LEDTick(); */

Expand Down Expand Up @@ -109,6 +110,28 @@ void LEDGetFuncList(char* List, uint16_t BufferSize)

void LEDSetFuncById(uint8_t Mask, LEDHookEnum Function)
{
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL) {
if (Mask & LED_GREEN) {
GlobalSettings.ActiveSettingPtr->LEDGreenFunction = Function;
}

if (Mask & LED_RED) {
GlobalSettings.ActiveSettingPtr->LEDRedFunction = Function;
}
}
else
{
/* Always 1st setting is used */
if (Mask & LED_GREEN) {
GLOBAL_UI_STORAGE.LEDGreenFunction = Function;
}

if (Mask & LED_RED) {
GLOBAL_UI_STORAGE.LEDRedFunction = Function;
}
}
#else
#ifndef LED_SETTING_GLOBAL
if (Mask & LED_GREEN) {
GlobalSettings.ActiveSettingPtr->LEDGreenFunction = Function;
Expand All @@ -118,7 +141,7 @@ void LEDSetFuncById(uint8_t Mask, LEDHookEnum Function)
GlobalSettings.ActiveSettingPtr->LEDRedFunction = Function;
}
#else
/* Write LED func to all settings when using global settings */
/* Write LED func to all settings when using global settings */
for (uint8_t i=0; i<SETTINGS_COUNT; i++) {
if (Mask & LED_GREEN) {
GlobalSettings.Settings[i].LEDGreenFunction = Function;
Expand All @@ -128,6 +151,7 @@ void LEDSetFuncById(uint8_t Mask, LEDHookEnum Function)
GlobalSettings.Settings[i].LEDRedFunction = Function;
}
}
#endif
#endif

/* Clear modified LED and remove any pending actions */
Expand All @@ -145,13 +169,37 @@ void LEDSetFuncById(uint8_t Mask, LEDHookEnum Function)

void LEDGetFuncByName(uint8_t Mask, char* Function, uint16_t BufferSize)
{
if (Mask == LED_GREEN) {
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL) {
if (Mask == LED_GREEN) {
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
GlobalSettings.ActiveSettingPtr->LEDGreenFunction, Function, BufferSize);
} else if (Mask == LED_RED) {
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
GlobalSettings.ActiveSettingPtr->LEDRedFunction, Function, BufferSize);

}
}
else
{
if (Mask == LED_GREEN) {
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
GLOBAL_UI_STORAGE.LEDGreenFunction, Function, BufferSize);
} else if (Mask == LED_RED) {
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
GLOBAL_UI_STORAGE.LEDRedFunction, Function, BufferSize);

}
}
#else
if (Mask == LED_GREEN) {
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
GlobalSettings.ActiveSettingPtr->LEDGreenFunction, Function, BufferSize);
} else if (Mask == LED_RED) {
MapIdToText(LEDFunctionMap, ARRAY_COUNT(LEDFunctionMap),
GlobalSettings.ActiveSettingPtr->LEDRedFunction, Function, BufferSize);
}
#endif
}

bool LEDSetFuncByName(uint8_t Mask, const char* Function)
Expand Down
20 changes: 20 additions & 0 deletions Firmware/Chameleon-Mini/LEDHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,34 @@
INLINE void LEDHook(LEDHookEnum Func, LEDActionEnum Action) {
extern LEDActionEnum LEDGreenAction;
extern LEDActionEnum LEDRedAction;
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL) {
if (GlobalSettings.ActiveSettingPtr->LEDGreenFunction == Func) {
LEDGreenAction = Action;
}

if (GlobalSettings.ActiveSettingPtr->LEDRedFunction == Func) {
LEDRedAction = Action;
}
}
else {
if (GLOBAL_UI_STORAGE.LEDGreenFunction == Func) {
LEDGreenAction = Action;
}

if (GLOBAL_UI_STORAGE.LEDRedFunction == Func) {
LEDRedAction = Action;
}
}
#else
if (GlobalSettings.ActiveSettingPtr->LEDGreenFunction == Func) {
LEDGreenAction = Action;
}

if (GlobalSettings.ActiveSettingPtr->LEDRedFunction == Func) {
LEDRedAction = Action;
}
#endif
}

#endif /* LEDHOOK_H_ */
39 changes: 36 additions & 3 deletions Firmware/Chameleon-Mini/Log.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "System.h"
#include "Map.h"
#include "LEDHook.h"
#include "UserInterface.h"

static uint8_t LogMem[LOG_SIZE];
static uint8_t *LogMemPtr;
Expand Down Expand Up @@ -63,8 +64,18 @@ static void LogFuncLive(LogEntryEnum Entry, const void* Data, uint8_t Length)

void LogInit(void)
{
#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL) {
LogSetModeById(GlobalSettings.ActiveSettingPtr->LogMode);
}
else
{
LogSetModeById(GLOBAL_UI_STORAGE.LogMode);
}
#else
LogSetModeById(GlobalSettings.ActiveSettingPtr->LogMode);
LogMemPtr = LogMem;
#endif
LogMemPtr = LogMem;
LogMemLeft = sizeof(LogMem);

uint8_t result;
Expand Down Expand Up @@ -166,6 +177,16 @@ uint16_t LogMemFree(void)

void LogSetModeById(LogModeEnum Mode)
{

#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL) {
GlobalSettings.ActiveSettingPtr->LogMode = Mode;
}
else
{
GLOBAL_UI_STORAGE.LogMode = Mode;
}
#else
#ifndef LOG_SETTING_GLOBAL
GlobalSettings.ActiveSettingPtr->LogMode = Mode;
#else
Expand All @@ -174,7 +195,7 @@ void LogSetModeById(LogModeEnum Mode)
GlobalSettings.Settings[i].LogMode = Mode;
}
#endif

#endif
switch(Mode) {
case LOG_MODE_OFF:
EnableLogSRAMtoFRAM = false;
Expand Down Expand Up @@ -211,8 +232,20 @@ bool LogSetModeByName(const char* Mode)

void LogGetModeByName(char* Mode, uint16_t BufferSize)
{
MapIdToText(LogModeMap, ARRAY_COUNT(LogModeMap),

#ifdef USER_INTERFACE_MODE_CONFIGURABLE
if ( GlobalSettings.UserInterfaceMode == USER_INTERFACE_INDIVIDUAL) {
MapIdToText(LogModeMap, ARRAY_COUNT(LogModeMap),
GlobalSettings.ActiveSettingPtr->LogMode, Mode, BufferSize);
}
else {
MapIdToText(LogModeMap, ARRAY_COUNT(LogModeMap),
GLOBAL_UI_STORAGE.LogMode, Mode, BufferSize);
}
#else
MapIdToText(LogModeMap, ARRAY_COUNT(LogModeMap),
GlobalSettings.ActiveSettingPtr->LogMode, Mode, BufferSize);
#endif
}

void LogGetModeList(char* List, uint16_t BufferSize)
Expand Down
12 changes: 9 additions & 3 deletions Firmware/Chameleon-Mini/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,25 @@ SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_CYCLE_SETTINGS
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_STORE_MEM
SETTINGS += -DDEFAULT_LBUTTON_ACTION=BUTTON_ACTION_RECALL_MEM

SETTINGS += -DUSER_INTERFACE_MODE_CONFIGURABLE

#Define if button action setting should be independent of active setting
SETTINGS += -DBUTTON_SETTING_GLOBAL
#SETTINGS += -DBUTTON_SETTING_GLOBAL

#Default LED functions
SETTINGS += -DDEFAULT_RED_LED_ACTION=LED_SETTING_CHANGE
SETTINGS += -DDEFAULT_GREEN_LED_ACTION=LED_POWERED

#Define if LED function setting should be independent of active setting
SETTINGS += -DLED_SETTING_GLOBAL
#SETTINGS += -DLED_SETTING_GLOBAL

#Default logging mode
SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_OFF
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_MEMORY
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_TERMINAL

#Define if log settings should be global
SETTINGS += -DLOG_SETTING_GLOBAL
#SETTINGS += -DLOG_SETTING_GLOBAL

#Default setting
SETTINGS += -DDEFAULT_SETTING=SETTINGS_FIRST
Expand All @@ -69,6 +71,9 @@ SETTINGS += -DDEFAULT_READER_THRESHOLD=400
#Use EEPROM to store settings
SETTINGS += -DENABLE_EEPROM_SETTINGS

#Default user interface mode
SETTINGS += -DDEFAULT_USERINTERFACE_MODE=USER_INTERFACE_GLOBAL

#Memory definitions and objcopy flags to include sections in binaries
FLASH_DATA_ADDR = 0x10000 #Start of data section in flash
FLASH_DATA_SIZE = 0x10000 #Size of data section in flash
Expand All @@ -94,6 +99,7 @@ SRC += $(TARGET).c LUFADescriptors.c System.c Configuration.c Random.c C
SRC += Terminal/Terminal.c Terminal/Commands.c Terminal/XModem.c Terminal/CommandLine.c
SRC += Codec/Codec.c Codec/ISO14443-2A.c Codec/Reader14443-2A.c Codec/SniffISO14443-2A.c Codec/Reader14443-ISR.S
SRC += Application/MifareUltralight.c Application/MifareClassic.c Application/ISO14443-3A.c Application/Crypto1.c Application/Reader14443A.c Application/Sniff14443A.c
SRC += UserInterface.c
SRC += $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
LUFA_PATH = ../LUFA
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -DFLASH_DATA_ADDR=$(FLASH_DATA_ADDR) -DFLASH_DATA_SIZE=$(FLASH_DATA_SIZE) -DSPM_HELPER_ADDR=$(SPM_HELPER_ADDR) -DBUILD_DATE=$(BUILD_DATE) -DCOMMIT_ID=\"$(COMMIT_ID)\" $(SETTINGS)
Expand Down
Loading