A good standard prefix may be time_ so you will have things like
time_second, time_hour, time_year etc. But the libraries that
increment these should have different prefixes which relate to the
library. The is the solution I use for other things is alias.
For example, a RTC lib should have prefixes like devicename_
Then in the sample, you can do the include as follows with some
aliases:
include devicelibname
alias time_second is devicename_second
alias time_hour is devicename_hour
And the include for whatever is using time_second, time_hour, etc.
include myclock
The advantage is that you can now easily choose any RTC lib for your
library. At the same time, we won't have any duplicate prefixes in
libs or anything too generic.
I currently do something similar for many libs we already have such as
SPI, serial, fat32 (for choosing storage device). Note the aliases at
the bottom of each include statement below that allows me to use
either SPI hardware or software without modifying the lib that uses
SPI.
-- SPI HARDWARE
include spi_master_hw -- includes the spi library
-- define spi inputs/outputs
pin_sdi_direction = input -- spi input
pin_sdo_direction = output -- spi output
pin_sck_direction = output -- spi clock
--
spi_init(SPI_MODE_11,SPI_RATE_FOSC_4) -- init spi, choose mode and
speed
--
alias spi_master is spi_master_hw
alias spi_master_exchange is spi_master_hw_exchange
OR
-- SPI SOFTWARE
alias spi_master_sw_sdi is pin_sdi
alias spi_master_sw_sdi_direction is pin_sdi_direction
alias spi_master_sw_sdo is pin_sdo
alias spi_master_sw_sdo_direction is pin_sdo_direction
alias spi_master_sw_sck is pin_sck
alias spi_master_sw_sck_direction is pin_sck_direction
-- define spi inputs/outputs
spi_master_sw_sdi_direction = input -- spi input
spi_master_sw_sdo_direction = output -- spi output
spi_master_sw_sck_direction = output -- spi clock
--
include spi_master_sw
spi_master_sw_init(SPI_MODE_11,0) -- init spi, choose mode
--
alias spi_master is spi_master_sw
alias spi_master_exchange is spi_master_sw_exchange
Seb also did something similar in pintools because "led" was way to
generic for a library, but "led" was needed in the sample. I see this
as similar since someone might want to use a variable named "seconds"
in a sample. See the last line:
const byte pintools_map[4] = {"A",0, "C",2}
include pintools
alias pin is pintools_level
alias pin_direction is pintools_direction
--
-- set your pins to outputs
pin_direction[0] = output
pin_direction[1] = output -- this pin direction will change in main
program
-- rename pins to led
alias led is pintools_level
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.