forked from rverstappen/AMX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ron Verstappen
committed
Sep 27, 2011
0 parents
commit 5608104
Showing
86 changed files
with
15,650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
MODULE_NAME='Automation' (char configFile[]) | ||
|
||
#include 'Debug.axi' | ||
#include 'AutomationConfig.axi' | ||
|
||
|
||
DEFINE_VARIABLE | ||
|
||
char DBG_MODULE[] = 'Automation' | ||
|
||
AutomationInput gInput | ||
|
||
|
||
DEFINE_FUNCTION double calcGmtOffset () | ||
{ | ||
double result | ||
char gmtOffset[10] | ||
gmtOffset = clkmgr_get_timezone() | ||
debug (DBG_MODULE, 9, "'GMT timezone offset: ',gmtOffset") | ||
select | ||
{ | ||
active (find_string (gmtOffset,'-',1)): | ||
{ | ||
remove_string (gmtOffset,'-',1) | ||
result = -(time_to_hour(gmtOffset) + time_to_minute(gmtOffset)/60.0) | ||
} | ||
active (find_string (gmtOffset,'+',1)): | ||
{ | ||
remove_string (gmtOffset,'+',1) | ||
result = time_to_hour(gmtOffset) + time_to_minute(gmtOffset)/60.0 | ||
} | ||
active (1): | ||
{ | ||
debug (DBG_MODULE, 1, "'Error determining GMT timezone offset: ',gmtOffset") | ||
return 0.0 | ||
} | ||
} // select | ||
if (clkmgr_is_daylightsavings_on()) | ||
{ | ||
result = result + 1.0 | ||
} | ||
return result | ||
} | ||
|
||
DEFINE_FUNCTION recalcAstro() | ||
{ | ||
local_var sinteger astroResult | ||
astroResult = astro_clock (gMainConfig.mLongitude, gMainConfig.mLatitude, calcGmtOffset(), date, | ||
gInput.mSunrise, gInput.mSunset) | ||
debug (DBG_MODULE, 1, "'astro_clock(',itoa(astroResult), | ||
') Sunrise: ',gInput.mSunrise,'; Sunset: ',gInput.mSunset") | ||
} | ||
|
||
DEFINE_START | ||
|
||
{ | ||
readConfigFile (DBG_MODULE, configFile) | ||
rebuild_event() | ||
} | ||
wait 571 // 57.1 seconds | ||
{ | ||
recalcAstro() | ||
} | ||
|
||
|
||
DEFINE_PROGRAM | ||
|
||
wait 35673 // approx once an hour | ||
{ | ||
recalcAstro() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
PROGRAM_NAME='AutomationConfig' | ||
|
||
// Configuration support for the Automation module | ||
|
||
#if_not_defined __AUTOMATION_CONFIG__ | ||
#define __AUTOMATION_CONFIG__ | ||
|
||
#include 'ConfigUtils' | ||
#include 'ConfigServerUtils' | ||
|
||
|
||
DEFINE_CONSTANT | ||
|
||
AUTOCFG_ITEM_TYPE_UNKNOWN = 0 | ||
AUTOCFG_ITEM_TYPE_TIME_OF_DAY = 1 | ||
|
||
AUTOCFG_MAX_AUTOMATIONS = 100 | ||
AUTOCFG_MAX_TIME_LINE_EVENTS = 32 | ||
|
||
AUTOCFG_READING_UNKNOWN = 0 | ||
AUTOCFG_READING_MAIN = 1 | ||
AUTOCFG_READING_AUTOMATION = 2 | ||
|
||
|
||
DEFINE_TYPE | ||
|
||
structure AutomationConfig | ||
{ | ||
double mLatitude | ||
double mLongitude | ||
} | ||
|
||
structure AutomationInput | ||
{ | ||
char mSunrise[8] | ||
char mSunset[8] | ||
} | ||
|
||
structure AutomationItem | ||
{ | ||
// Common attributes for automation items | ||
integer mId | ||
char mName[32] | ||
dev mDev | ||
char mCommand[256] | ||
integer mType | ||
// Attributes specific to time-of-day automations | ||
|
||
// Implementation members: | ||
long mTlArray[AUTOCFG_MAX_TIME_LINE_EVENTS] | ||
} | ||
|
||
|
||
DEFINE_VARIABLE | ||
|
||
volatile AutomationConfig gMainConfig | ||
volatile AutomationItem gItems[AUTOCFG_MAX_AUTOMATIONS] | ||
volatile integer gReadMode | ||
volatile integer gThisItem | ||
|
||
DEFINE_FUNCTION handleHeading (char moduleName[], char heading[]) | ||
{ | ||
debug (moduleName, 8, "'read config heading: <',heading,'>'") | ||
switch (heading) | ||
{ | ||
case 'general': | ||
{ | ||
gReadMode = AUTOCFG_READING_MAIN | ||
break | ||
} | ||
case 'automation': | ||
{ | ||
gReadMode = AUTOCFG_READING_AUTOMATION | ||
gThisItem = 0 | ||
break | ||
} | ||
default: | ||
{ | ||
debug (moduleName, 0, "'unknown config heading: ',heading") | ||
} | ||
} | ||
} | ||
|
||
DEFINE_FUNCTION handleProperty (char moduleName[], char propName[], char propValue[]) | ||
{ | ||
debug (moduleName, 8, "'read config property (',propName,'): <',propValue,'>'") | ||
switch (gReadMode) | ||
{ | ||
|
||
case AUTOCFG_READING_MAIN: | ||
{ | ||
switch (propName) | ||
{ | ||
case 'latitude': | ||
{ | ||
gMainConfig.mLatitude = atof(propValue) | ||
break | ||
} | ||
case 'longitude': | ||
{ | ||
gMainConfig.mLongitude = atof(propValue) | ||
break | ||
} | ||
} // switch | ||
} // case AUTOCFG_READING_MAIN | ||
|
||
case AUTOCFG_READING_AUTOMATION: | ||
{ | ||
switch (propName) | ||
{ | ||
case 'id': | ||
{ | ||
gThisItem = atoi(propValue) | ||
if (length_array(gItems) < gThisItem) | ||
{ | ||
set_length_array(gItems, gThisItem) | ||
} | ||
gItems[gThisItem].mId = gThisItem | ||
break | ||
} | ||
case 'name': | ||
{ | ||
gItems[gThisItem].mName = propValue | ||
break | ||
} | ||
case 'dev': | ||
{ | ||
parseDev (gItems[gThisItem].mDev, propValue) | ||
break | ||
} | ||
case 'command': | ||
{ | ||
gItems[gThisItem].mCommand = propValue | ||
break | ||
} | ||
case 'type': | ||
{ | ||
gItems[gThisItem].mType = automationType(propValue) | ||
break | ||
} | ||
default: | ||
{ | ||
debug (moduleName, 0, "'Unhandled property: ',propName") | ||
break | ||
} | ||
break | ||
} // inner switch | ||
} // case AUTOCFG_READING_AUTOMATION | ||
default: | ||
{ | ||
debug (moduleName, 1, "'error: property with no heading (',propName,'): <',propValue,'>'") | ||
} | ||
} | ||
} | ||
|
||
DEFINE_FUNCTION integer automationType (char typeStr[]) | ||
{ | ||
lower_string (typeStr) | ||
switch (typeStr) | ||
{ | ||
case 'time-of-day': return AUTOCFG_ITEM_TYPE_TIME_OF_DAY | ||
default: return AUTOCFG_ITEM_TYPE_UNKNOWN | ||
} | ||
} | ||
|
||
#end_if // __AUTOMATION_CONFIG__ |
Oops, something went wrong.