Skip to content

Commit

Permalink
new register access
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Oct 22, 2017
1 parent f319e15 commit d5d17cf
Show file tree
Hide file tree
Showing 24 changed files with 1,342 additions and 1,124 deletions.
2 changes: 1 addition & 1 deletion AlarmClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SysClock : public AlarmClock {

if (cycles < TIMER1_RESOLUTION) {
clockSelectBits = _BV(CS10);
pwmPeriod = cycles;
pwmPeriod = (unsigned short)cycles;
}
else if (cycles < TIMER1_RESOLUTION * 8) {
clockSelectBits = _BV(CS11);
Expand Down
2 changes: 2 additions & 0 deletions AskSinPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class AskSin : public AskSinBase {
sysclock.init();
// signal start to user
led.set(LedStates::welcome);
// delay next send by random time
waitTimeout((rand() % 3500)+1000);
}

bool runready () {
Expand Down
22 changes: 11 additions & 11 deletions Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace as {

template <class HalType> class Device;
template <class HalType,class List0Type> class Device;
class ActionSetMsg;
class RemoteEventMsg;
class SensorEventMsg;

template<class HalType,class List1Type,class List3Type,class List4Type,int PeerCount>
template<class HalType,class List1Type,class List3Type,class List4Type,int PeerCount,class List0Type=List0>
class Channel {
Device<HalType>* dev;
Device<HalType,List0Type>* dev;
bool change; // the status is changed, we may need to send a status
bool inhi;
uint8_t num ; // channels per device
Expand All @@ -28,7 +28,7 @@ class Channel {
typedef List1Type List1;
typedef List3Type List3;
typedef List4Type List4;
typedef Device<HalType> DeviceType;
typedef Device<HalType,List0Type> DeviceType;

public:
Channel () : dev(0), change(false), inhi(false), num(0), addr(0) {}
Expand All @@ -53,7 +53,7 @@ class Channel {

bool aesActive () const { return getList1().aesActive(); }

void setup(Device<HalType>* dev,uint8_t number,uint16_t addr) {
void setup(Device<HalType,List0Type>* dev,uint8_t number,uint16_t addr) {
this->dev = dev;
this->num = number;
this->addr = addr;
Expand Down Expand Up @@ -238,13 +238,13 @@ class Channel {



template <class HalType>
template <class HalType,class List0Type=List0>
class VirtBaseChannel {
public:
VirtBaseChannel () {}
virtual ~VirtBaseChannel () {}

virtual void setup(Device<HalType>* dev,uint8_t number,uint16_t addr) = 0;
virtual void setup(Device<HalType,List0Type>* dev,uint8_t number,uint16_t addr) = 0;
virtual uint16_t size () const = 0;
virtual uint8_t number () const = 0;
virtual uint16_t address () const = 0;
Expand Down Expand Up @@ -278,16 +278,16 @@ class VirtBaseChannel {

};

template <class HalType,class ChannelType>
class VirtChannel : public VirtBaseChannel<HalType> {
template <class HalType,class ChannelType,class List0Type=List0>
class VirtChannel : public VirtBaseChannel<HalType,List0Type> {
ChannelType ch;
public:
VirtChannel () {}
virtual ~VirtChannel () {}

operator ChannelType& () { return ch; }

virtual void setup(Device<HalType>* dev,uint8_t number,uint16_t addr) { ch.setup(dev,number,addr); }
virtual void setup(Device<HalType,List0Type>* dev,uint8_t number,uint16_t addr) { ch.setup(dev,number,addr); }
virtual uint16_t size () const { return ch.size(); }
virtual uint8_t number () const { return ch.number(); }
virtual uint16_t address () const { return ch.address(); }
Expand All @@ -297,7 +297,7 @@ class VirtChannel : public VirtBaseChannel<HalType> {
virtual void inhibit (bool value) { ch.inhibit(value); }
virtual bool inhibit () const { return ch.inhibit(); }
virtual bool aesActive () const { return ch.aesActive(); }
virtual bool has (const Peer& p) { return ch.has(p); };
virtual bool has (const Peer& p) const { return ch.has(p); };
virtual Peer peer (uint8_t idx) const { return ch.peer(idx); }
virtual bool peer (const Peer& p) { return ch.peer(p); }
virtual bool peer (const Peer& p1,const Peer& p2) { return ch.peer(p1,p2); }
Expand Down
10 changes: 10 additions & 0 deletions ChannelList.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class BaseList {
bool getData (uint8_t offset,uint8_t* buf,uint16_t size) const {
return storage.getData(addr + offset,buf,size);
}

void clear (uint8_t offset,uint16_t size) {
storage.clearData(addr + offset,size);
}

void init (const uint8_t* data,uint16_t size) {
for(uint16_t idx=0; idx<size; ++idx) {
storage.setByte(addr + idx,pgm_read_byte(data + idx));
}
}
};

class GenericList : public BaseList {
Expand Down
9 changes: 4 additions & 5 deletions Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ struct DeviceInfo {
uint8_t DeviceInfo[2];
};


template <class HalType>
template <class HalType,class List0Type=List0>
class Device {

public:
Expand All @@ -68,7 +67,7 @@ class Device {

private:
HalType* hal;
List0& list0;
List0Type& list0;
uint8_t msgcount;

HMID lastdev;
Expand All @@ -82,7 +81,7 @@ class Device {
uint8_t numChannels;

public:
Device (const DeviceInfo& i,uint16_t addr,List0& l,uint8_t ch) : hal(0), list0(l), msgcount(0), lastmsg(0), kstore(addr), info(i), numChannels(ch) {
Device (const DeviceInfo& i,uint16_t addr,List0Type& l,uint8_t ch) : hal(0), list0(l), msgcount(0), lastmsg(0), kstore(addr), info(i), numChannels(ch) {
// TODO init seed
}
virtual ~Device () {}
Expand Down Expand Up @@ -186,7 +185,7 @@ class Device {
return list0.masterid();
}

const List0& getList0 () {
const List0Type& getList0 () {
return list0;
}

Expand Down
Loading

0 comments on commit d5d17cf

Please sign in to comment.