Topic: tech dcc pc src prev next
tech dcc pc src > cfg.h
#ifndef HERMES_CFG_H
#define HERMES_CFG_H
#include <inttypes.h>
#include <stdbool.h>
#define CFG_LOCO_LIST_LENGTH 20
#define CFG_ACCESSORY_LIST_LENGTH 20
typedef uint16_t cfg_address_type;
typedef unsigned char cfg_loco_index_type;
typedef uint32_t functions_type;
#define CFG_NULL_ADDR (0xffff)
#define CFG_NULL_INDEX 255
#define CFG_NULL_FN 255
#define SPEED_STEPS_128 255
#define SPEED_STEPS_28 1
#define STOP_MODE_ON_ENTERING_STATION 255
#define STOP_MODE_ON_LEAVING_MAIN 1
#define HERMES_SERVO_STATE_CV 112
//
// CONTROLLER CONFIGURATION STORAGE
//
typedef struct
{
cfg_address_type address;
unsigned char speed_steps;
unsigned char stop_mode;
functions_type f_default;
functions_type f_enable;
functions_type f_momentary;
// List of functions attached to buttons 1-8 on the panel.
unsigned char f_list[8];
} cfg_loco;
/*
* Reset the controller's EEPROM to the default values.
*/
void Cfg_Reset();
// Check whether a locomotive address is valid (0, or 'all locomotives', is
// valid).
bool Cfg_LocoAddressValid(cfg_address_type address);
// Count the functions which are enabled for a locomotive.
unsigned char Cfg_LocoFunctions(const cfg_loco *loco);
// Check whether an accessory address is valid.
bool Cfg_AccessoryAddressValid(cfg_address_type address);
cfg_loco_index_type Cfg_AddressCount(
const cfg_address_type *list
);
// Get the index of an address in a list.
cfg_loco_index_type Cfg_IndexInList(
cfg_address_type addr,
const cfg_address_type *list
);
// Add an address to a sorted list, moving every higher address back.
void Cfg_AddToList(
cfg_address_type addr,
cfg_address_type *list
);
// Remove an address from a list.
void Cfg_RemoveFromList(
cfg_address_type addr,
cfg_address_type *list
);
/*
* Get the next address in a list, appearing after a given address.
*
* The list must be ordered, continuous (no gaps) and null-terminated. Lists
* generated by Cfg_Accessories and Cfg_Addresses are suitable.
*
* Wraps if the end of the list is reached.
*/
cfg_address_type Cfg_NextInList(
cfg_address_type *list,
cfg_address_type current
);
/*
* Get the previous address in a list, appearing before a certain value.
*
* The list must be ordered, continuous (no gaps) and null-terminated. Lists
* generated by Cfg_Accessories and Cfg_Addresses are suitable.
*
* Wraps if the start of the list is reached.
*/
cfg_address_type Cfg_PrevInList(
cfg_address_type *list,
cfg_address_type current
);
cfg_loco Cfg_DefaultLoco();
cfg_loco Cfg_ReadLoco(cfg_address_type address);
cfg_loco Cfg_ReadLocoFromIndex(cfg_loco_index_type index);
bool Cfg_WriteLoco(cfg_loco loco);
void Cfg_WriteLocoToIndex(
cfg_loco_index_type index,
cfg_loco loco
);
void Cfg_Addresses(cfg_address_type *list);
cfg_loco_index_type Cfg_NextFreeLoco();
cfg_loco_index_type Cfg_AddrToIndex(
cfg_address_type address
);
// Fetch the list of programmed accessories.
void Cfg_Accessories(cfg_address_type *list);
// Add an accessory to the accessory list if it is not already present.
void Cfg_SaveAccessory(cfg_address_type accessory_address);
// Delete an accessory from the accessory list.
void Cfg_DeleteAccessory(cfg_address_type accessory_address);
// Read the list of 'on' accessories. 'accessories' will be an ordered,
// contiguous, null-terminated list.
void Cfg_ReadAccessoryOn(cfg_address_type *accessories);
// Save the list of 'on' accessories. 'accessories' must be an ordered,
// contiguous, null-terminated list.
void Cfg_SaveAccessoryOn(cfg_address_type *accessories);
void Cfg_ReadAccessoryHotlist(cfg_address_type *accessories);
void Cfg_SaveAccessoryHotlist(cfg_address_type *accessories);
#endif