-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCCServiceModeScheduler.h
95 lines (72 loc) · 2.32 KB
/
DCCServiceModeScheduler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef __DCCSERVICEMODESCHEDULER_H__
#define __DCCSERVICEMODESCHEDULER_H__
#include "DCCServiceModePacket.h"
#include "DCCServiceModeQueue.h"
#include "WProgram.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#ifndef CURRENT_SENSE_PIN
#define CURRENT_SENSE_PIN 3
#endif
#ifndef OVER_CURRENT_VALUE
#define OVER_CURRENT_VALUE 200
#endif
#ifndef ACK_THRESHOLD
#define ACK_THRESHOLD 100
#endif
enum physical_register_t
{
address_register,
start_voltage_register,
acceleration_register,
deceleration_register,
basic_configuration_register,
reserved_register,
version_number_register,
manufacturer_ID_register
};
enum programmer_mode_t
{
idle_mode,
power_on_initial_mode,
power_on_mode,
recovery_mode
};
class DCCServiceModeScheduler
{
public:
DCCServiceModeScheduler(void);
// bool writeByte(uint16_t CV, uint8_t value);
// uint8_t readByte(uint16_t CV);
// bool writeAddress(uint_16t address);
// uint_16t readAddress();
// bool hardReset(void); //reset decoder to factory state.
void setup(void); //for any post-constructor initialization
//to be called periodically within loop()
void update(void);
//reset software
void reset(void);
bool checkACK(void) {return _wasACKd;}
// bool checkSupportDirectMode(void);
bool directModeWriteByte(uint16_t CV, uint8_t value);
// bool directModeVerifyByte(uint16_t CV, uint8_t value);
// bool directModeWriteBit(uint16_t CV, uint8_t bit, uint8_t value);
// bool directModeVerifyBit(uint16_t CV, uint8_t bit, uint8_t value);
// bool addressOnlyModeWriteAddress(uint8_t address);
// bool addressOnlyModeVerifyAddress(uint8_t address);
// bool physicalRegsiterModeWriteByte(physical_register_t register, uint8_t value);
// bool physicalRegsiterModeVerifyByte(physical_register_t register, uint8_t value);
// bool pagedRegisterModeWriteByte(uint16_t CV, uint8_t value);
// bool pagedRegisterModeVerifyByte(uint16_t CV, uint8_t value);
private:
bool _accepts_direct_mode;
bool _tested_direct_mode;
bool _wasACKd;
programmer_mode_t _mode;
uint16_t _over_current_timer;
uint16_t _ack_timer;
DCCServiceModeQueue _power_on_queue;
DCCServiceModeQueue _instruction_queue;
DCCServiceModeQueue _conditional_queue;
};
#endif //__DCCSERVICEMODESCHEDULER_H__