Peter Smith
Published © MIT

Hiker Companion

Hold the the Hiker's Companion phone extension in your hand while hiking, and leave your expensive and delicate phone in your knapsack.

AdvancedFull instructions provided2 days250
Hiker Companion

Things used in this project

Hardware components

Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1

Software apps and online services

NXP Rapid IOT Studio

Story

Read more

Schematics

Code Flow

The hardware used is the self-contained Rapid IOT prototyping kit; this image is the overall Rapid IOT Studio diagram of the code

Code

Hiiker's Companion

C/C++
#include "callbacks.h"

//HEADER START

//HEADER END

void ATMO_Setup() {

}


ATMO_Status_t EmbeddedStaticTextDisplay_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t EmbeddedStaticTextDisplay_displayPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(EmbeddedStaticTextDisplay, x), ATMO_PROPERTY(EmbeddedStaticTextDisplay, y), false);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedStaticTextDisplay_topRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedStaticTextDisplay_bottomRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedStaticTextDisplay_topLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedStaticTextDisplay_bottomLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedStaticTextDisplay_onDisplayed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedStaticTextDisplay_setText(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_Value_t strVal;
    ATMO_InitValue(&strVal);
    ATMO_CreateValueConverted(&strVal, ATMO_DATATYPE_STRING, in);
    ATMO_UI_STATICTEXT_SetText(ATMO_VARIABLE(EmbeddedStaticTextDisplay,pageHandle), strVal.data);
    ATMO_FreeValue(&strVal);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedStaticTextDisplay_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_UI_PAGE_Config_t config;
	config.hidden = ATMO_PROPERTY(EmbeddedStaticTextDisplay, pageHidden);
	config.textColor = ATMO_PROPERTY(EmbeddedStaticTextDisplay, textColor);
	config.activeButtons = ATMO_UI_Page_GetButtonMask(ATMO_PROPERTY(EmbeddedStaticTextDisplay, topRightButtonEnabled),
		ATMO_PROPERTY(EmbeddedStaticTextDisplay,bottomRightButtonEnabled), ATMO_PROPERTY(EmbeddedStaticTextDisplay, topLeftButtonEnabled), ATMO_PROPERTY(EmbeddedStaticTextDisplay, bottomLeftButtonEnabled));
    config.x = ATMO_PROPERTY(EmbeddedStaticTextDisplay, x);
	config.y = ATMO_PROPERTY(EmbeddedStaticTextDisplay, y);
	strncpy(config.topLeftButtonLabel, ATMO_PROPERTY(EmbeddedStaticTextDisplay, topLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.topRightButtonLabel, ATMO_PROPERTY(EmbeddedStaticTextDisplay, topRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomLeftButtonLabel, ATMO_PROPERTY(EmbeddedStaticTextDisplay, bottomLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomRightButtonLabel, ATMO_PROPERTY(EmbeddedStaticTextDisplay, bottomRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
    config.spanX = ATMO_PROPERTY(EmbeddedStaticTextDisplay, spanX);
	config.spanY = ATMO_PROPERTY(EmbeddedStaticTextDisplay, spanY);
    config.title = ATMO_PROPERTY(EmbeddedStaticTextDisplay, pageTitle);
    config.titleHidden = ATMO_PROPERTY(EmbeddedStaticTextDisplay, titleHidden);
	ATMO_UI_STATICTEXT_Init(&config);
	ATMO_VARIABLE(EmbeddedStaticTextDisplay, pageHandle) = config.templateInstance;
    ATMO_UI_STATICTEXT_SetText(config.templateInstance, ATMO_PROPERTY(EmbeddedStaticTextDisplay, text));
	ATMO_UI_STATICTEXT_SetTextSize(config.templateInstance, ATMO_PROPERTY(EmbeddedStaticTextDisplay, fontSize));
	ATMO_UI_STATICTEXT_SetAlignment(config.templateInstance, ATMO_PROPERTY(EmbeddedStaticTextDisplay, horizontalAlignment));
	ATMO_UI_STATICTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(EmbeddedStaticTextDisplay,pageHandle), 1, ATMO_ABILITY(EmbeddedStaticTextDisplay, topRightButtonPressed));
	ATMO_UI_STATICTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(EmbeddedStaticTextDisplay,pageHandle), 2, ATMO_ABILITY(EmbeddedStaticTextDisplay, bottomRightButtonPressed));
	ATMO_UI_STATICTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(EmbeddedStaticTextDisplay,pageHandle), 3, ATMO_ABILITY(EmbeddedStaticTextDisplay, topLeftButtonPressed));
    ATMO_UI_STATICTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(EmbeddedStaticTextDisplay,pageHandle), 4, ATMO_ABILITY(EmbeddedStaticTextDisplay, bottomLeftButtonPressed));
    
	if(!config.hidden)
	{
		ATMO_UI_STATICTEXT_RegisterOnDisplayedAbilityHandle(ATMO_VARIABLE(EmbeddedStaticTextDisplay,pageHandle), ATMO_ABILITY(EmbeddedStaticTextDisplay, onDisplayed));
	}
    return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedPageController_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t EmbeddedPageController_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_PAGE_CONTROLLER_Config_t config;
	config.enableUpDownNavLabels = ATMO_PROPERTY(EmbeddedPageController, upDownNavigationLabelsEnabled);
	config.enableLeftRightNavLabels = ATMO_PROPERTY(EmbeddedPageController, leftRightNavigationLabelsEnabled);
	ATMO_UI_Page_SetConfiguration(&config);
    return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_displayRootPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	
	ATMO_UI_Page_DisplayRootPage();
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_navigateUp(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessNavButton(ATMO_UI_PAGE_NAV_UP);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_navigateDown(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessNavButton(ATMO_UI_PAGE_NAV_DOWN);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_navigateLeft(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessNavButton(ATMO_UI_PAGE_NAV_LEFT);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_navigateRight(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessNavButton(ATMO_UI_PAGE_NAV_RIGHT);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_processTopRightButton(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessUserButton(1);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_processBottomRightButton(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessUserButton(2);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_processTopLeftButton(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessUserButton(3);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedPageController_processBottomLeftButton(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_ProcessUserButton(4);
	return ATMO_Status_Success;
	
}


ATMO_Status_t Interval_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t Interval_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_INTERVAL_Handle_t intervalHandle;
    ATMO_INTERVAL_AddAbilityInterval(
		ATMO_PROPERTY(Interval, instance), 
		ATMO_ABILITY(Interval, interval), 
		ATMO_PROPERTY(Interval, time), 
		&intervalHandle
	);
	
	return ATMO_Status_Success;
	
}


ATMO_Status_t Interval_interval(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t SX9500Touch_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t SX9500Touch_setup(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_SX9500_Config_t config;
	config.address = ATMO_PROPERTY(SX9500Touch, i2cAddress);
	config.i2cDriverInstance = ATMO_PROPERTY(SX9500Touch, i2cInstance);
	config.gpioDriverInstance = ATMO_PROPERTY(SX9500Touch, gpioInstance);
	config.interruptEnabled = ATMO_PROPERTY(SX9500Touch, interruptEnabled);
	config.interruptPin = ATMO_PROPERTY(SX9500Touch, interruptGpio);
	ATMO_SX9500_Init(&config);
	ATMO_SX9500_RegisterTouchedAbilityHandle(SX9500_Touched_Up, ATMO_ABILITY(SX9500Touch, pressUp));
	ATMO_SX9500_RegisterTouchedAbilityHandle(SX9500_Touched_Down, ATMO_ABILITY(SX9500Touch, pressDown));
	ATMO_SX9500_RegisterTouchedAbilityHandle(SX9500_Touched_Left, ATMO_ABILITY(SX9500Touch, pressLeft));
	ATMO_SX9500_RegisterTouchedAbilityHandle(SX9500_Touched_Right, ATMO_ABILITY(SX9500Touch, pressRight));
	return ATMO_Status_Success;
}


ATMO_Status_t SX9500Touch_getTouchData(ATMO_Value_t *in, ATMO_Value_t *out) {
	return;
}


ATMO_Status_t SX9500Touch_pressUp(ATMO_Value_t *in, ATMO_Value_t *out) {
SX9500_TouchState_t touchState;
ATMO_GetBinary(in, &touchState, sizeof(touchState));
ATMO_CreateValueBinary(out, &touchState, sizeof(touchState));
return ATMO_Status_Success;
}


ATMO_Status_t SX9500Touch_pressDown(ATMO_Value_t *in, ATMO_Value_t *out) {
SX9500_TouchState_t touchState;
ATMO_GetBinary(in, &touchState, sizeof(touchState));
ATMO_CreateValueBinary(out, &touchState, sizeof(touchState));
return ATMO_Status_Success;
}


ATMO_Status_t SX9500Touch_pressLeft(ATMO_Value_t *in, ATMO_Value_t *out) {
SX9500_TouchState_t touchState;
ATMO_GetBinary(in, &touchState, sizeof(touchState));
ATMO_CreateValueBinary(out, &touchState, sizeof(touchState));
return ATMO_Status_Success;
}


ATMO_Status_t SX9500Touch_pressRight(ATMO_Value_t *in, ATMO_Value_t *out) {
SX9500_TouchState_t touchState;
ATMO_GetBinary(in, &touchState, sizeof(touchState));
ATMO_CreateValueBinary(out, &touchState, sizeof(touchState));
return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_setup(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_FXOS8700_Config_t config;
	config.address = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, i2cAddress);
	config.i2cDriverInstance = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, i2cInstance);
	config.gpioDriverInstance = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, gpioInstance);
	config.int1En = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt1Enabled);
    config.int2En = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt2Enabled);
    config.int1Pin = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt1Gpio);
    config.int2Pin = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt2Gpio);

    switch(ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, motionDetectType))
    {
        case FXOS8700_NoDetect:
        {
            config.freefallEnabled = false;
            config.motionEnabled = false;
            config.tapDetectionEnabled = false;
            break;
        }
        case FXOS8700_FreefallDetect:
        {
            config.freefallEnabled = true;
            config.motionEnabled = false;
            config.tapDetectionEnabled = false;
            break;
        }
        case FXOS8700_MotionDetect:
        {
            config.freefallEnabled = false;
            config.motionEnabled = true;
            config.tapDetectionEnabled = false;
            break;
        }
        case FXOS8700_TapDetect:
        {
            config.freefallEnabled = false;
            config.motionEnabled = false;
            config.tapDetectionEnabled = true;
            break; 
        }
        default:
        {
            config.freefallEnabled = false;
            config.motionEnabled = false;  
            config.tapDetectionEnabled = false;
            break;
        }
    }

    ATMO_FXOS8700_SetMotionDetectedAbilityHandle(ATMO_ABILITY(FXOS8700AccelerometerMagnetometer, detectMotion));
    ATMO_FXOS8700_SetFreefallDetectedAbilityHandle(ATMO_ABILITY(FXOS8700AccelerometerMagnetometer, detectFreefall));
    ATMO_FXOS8700_SetTapDetectedAbilityHandle(ATMO_ABILITY(FXOS8700AccelerometerMagnetometer, detectTap));
	ATMO_FXOS8700_Init(&config);

    return ATMO_Status_Success;
	
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_setEnabled(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_FXOS8700_SetEnabled(true);
return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_setDisabled(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_FXOS8700_SetEnabled(false);
return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_setEnabledDisabled(ATMO_Value_t *in, ATMO_Value_t *out) {
bool enabled = false;
ATMO_GetBool(in, &enabled);
ATMO_FXOS8700_SetEnabled(enabled);
return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getAccelData(ATMO_Value_t *in, ATMO_Value_t *out) {
    ATMO_3dFloatVector_t data;

    if( ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success )
    {
        ATMO_CreateValueVoid(out);
        return ATMO_Status_Fail;
    }

    ATMO_CreateValue3dVectorFloat(out, &data);

    return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getAccelX(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_3dFloatVector_t data;

	if(ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success)
	{
		ATMO_CreateValueVoid(out);
		return ATMO_Status_Fail;
	}

	ATMO_CreateValueFloat(out, data.x);
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getAccelY(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_3dFloatVector_t data;

	if(ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success)
	{
		ATMO_CreateValueVoid(out);
		return ATMO_Status_Fail;
	}

	ATMO_CreateValueFloat(out, data.y);
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getAccelZ(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_3dFloatVector_t data;

	if(ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success)
	{
		ATMO_CreateValueVoid(out);
		return ATMO_Status_Fail;
	}

	ATMO_CreateValueFloat(out, data.z);
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getMagData(ATMO_Value_t *in, ATMO_Value_t *out) {
    ATMO_3dFloatVector_t data;

    if( ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success )
    {
        ATMO_CreateValueVoid(out);
        return ATMO_Status_Fail;
    }

    ATMO_CreateValue3dVectorFloat(out, &data);

    return ATMO_Status_Success;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getMagX(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_3dFloatVector_t data;

	if(ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success)
	{
		ATMO_CreateValueVoid(out);
		return ATMO_Status_Fail;
	}

	ATMO_CreateValueFloat(out, data.x);
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getMagY(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_3dFloatVector_t data;

	if(ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success)
	{
		ATMO_CreateValueVoid(out);
		return ATMO_Status_Fail;
	}

	ATMO_CreateValueFloat(out, data.y);
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_getMagZ(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_3dFloatVector_t data;

	if(ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success)
	{
		ATMO_CreateValueVoid(out);
		return ATMO_Status_Fail;
	}

	ATMO_CreateValueFloat(out, data.z);
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_detectTap(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_detectMotion(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_detectFreefall(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;

}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_enableFreefallDetection(ATMO_Value_t *in, ATMO_Value_t *out) {
if(ATMO_FXOS8700_EnableFreefallDetection() == ATMO_FXOS8700_Status_Success)
{
    return ATMO_Status_Success;
}

return ATMO_Status_Fail;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_enableMotionDetection(ATMO_Value_t *in, ATMO_Value_t *out) {
if(ATMO_FXOS8700_EnableMotionDetection() == ATMO_FXOS8700_Status_Success)
{
    return ATMO_Status_Success;
}

return ATMO_Status_Fail;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_enableTapDetection(ATMO_Value_t *in, ATMO_Value_t *out) {
if(ATMO_FXOS8700_EnableTapDetection() == ATMO_FXOS8700_Status_Success)
{
    return ATMO_Status_Success;
}

return ATMO_Status_Fail;
}


ATMO_Status_t FXOS8700AccelerometerMagnetometer_disableDetection(ATMO_Value_t *in, ATMO_Value_t *out) {
if(ATMO_FXOS8700_DisableAllDetection() == ATMO_FXOS8700_Status_Success)
{
    return ATMO_Status_Success;
}

return ATMO_Status_Fail;
}


ATMO_Status_t CompassHeading_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
    	ATMO_3dFloatVector_t values;
ATMO_Get3dVectorFloat(in, &values);
//char testStr[64];
double x = values.x + 61.875;

double y = values.y + 89.75;
double z = values.z - 77;
double angle = atan2 (x, y) * 180.0 / 3.141592;
char direction[100];
if (angle > 168.75)       sprintf (direction, "N    ", angle);
else if (angle >  146.25) sprintf (direction, "NNW  ", angle);
else if (angle >  123.75) sprintf (direction, "NW   ", angle);
else if (angle >  101.25) sprintf (direction, "WNW  ", angle);
else if (angle >   78.75) sprintf (direction, "W    ", angle);
else if (angle >   56.25) sprintf (direction, "WSW  ", angle);
else if (angle >   33.75) sprintf (direction, "SW   ", angle);
else if (angle >   11.25) sprintf (direction, "SSW  ", angle);
else if (angle >  -11.25) sprintf (direction, "S    ", angle);
else if (angle >  -33.75) sprintf (direction, "SSE  ", angle);
else if (angle >  -56.25) sprintf (direction, "SE   ", angle);
else if (angle >  -78.75) sprintf (direction, "ESE  ", angle);
else if (angle > -101.25) sprintf (direction, "E    ", angle);
else if (angle > -123.75) sprintf (direction, "ENE  ", angle);
else if (angle > -146.25) sprintf (direction, "NE   ", angle);
else if (angle > -168.75) sprintf (direction, "NNE  ", angle);
else                      sprintf (direction, "N    ", angle);



//sprintf(testStr, "X: %.2f\r\nY:%.2f\nZ:%.2f\nang:%.2f", x, y, z, angle);
ATMO_CreateValueString(out, direction);
    	return ATMO_Status_Success;
}


ATMO_Status_t StatusDisplay_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t StatusDisplay_displayPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(StatusDisplay, x), ATMO_PROPERTY(StatusDisplay, y), false);
	return ATMO_Status_Success;
	
}


ATMO_Status_t StatusDisplay_onDisplayed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t StatusDisplay_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_UI_PAGE_Config_t config;
    config.hidden = ATMO_PROPERTY(StatusDisplay, pageHidden);
    config.activeButtons = ATMO_UI_Page_GetButtonMask(ATMO_PROPERTY(StatusDisplay, topRightButtonEnabled),
    ATMO_PROPERTY(StatusDisplay,bottomRightButtonEnabled), ATMO_PROPERTY(StatusDisplay, topLeftButtonEnabled), ATMO_PROPERTY(StatusDisplay, bottomLeftButtonEnabled));
    config.x = ATMO_PROPERTY(StatusDisplay, x);
    config.y = ATMO_PROPERTY(StatusDisplay, y);
	strncpy(config.topLeftButtonLabel, ATMO_PROPERTY(StatusDisplay, topLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.topRightButtonLabel, ATMO_PROPERTY(StatusDisplay, topRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomLeftButtonLabel, ATMO_PROPERTY(StatusDisplay, bottomLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomRightButtonLabel, ATMO_PROPERTY(StatusDisplay, bottomRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
    config.spanX = ATMO_PROPERTY(StatusDisplay, spanX);
	config.spanY = ATMO_PROPERTY(StatusDisplay, spanY);
    config.title = ATMO_PROPERTY(StatusDisplay, pageTitle);
    config.titleHidden = ATMO_PROPERTY(StatusDisplay, titleHidden);
    ATMO_UI_SYSTEMSTATUS_Init(&config);
    
}


ATMO_Status_t CompasDisplay_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t CompasDisplay_displayPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(CompasDisplay, x), ATMO_PROPERTY(CompasDisplay, y), false);
	return ATMO_Status_Success;
	
}


ATMO_Status_t CompasDisplay_onDisplayed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_onLeave(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t CompasDisplay_setIconLabelAndColor(ATMO_Value_t *in, ATMO_Value_t *out) {

    struct {
        char str[32];
        GUI_COLOR color;
    } icon_data;
 
    ATMO_GetBinary(in, &icon_data, sizeof(icon_data));
    ATMO_UI_ICONLINES_SetIconLabelColor(ATMO_VARIABLE(CompasDisplay, pageHandle), icon_data.str, icon_data.color);
    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_setIconLabel(ATMO_Value_t *in, ATMO_Value_t *out) {

    char str[32];
    ATMO_GetString(in, str, 32);
    ATMO_UI_ICONLINES_SetIconLabel(ATMO_VARIABLE(CompasDisplay, pageHandle), str);
    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_UI_PAGE_Config_t config;
    config.hidden = ATMO_PROPERTY(CompasDisplay, pageHidden);
    config.textColor = ATMO_PROPERTY(CompasDisplay, textColor);
    config.activeButtons = ATMO_UI_Page_GetButtonMask(ATMO_PROPERTY(CompasDisplay, topRightButtonEnabled),
    ATMO_PROPERTY(CompasDisplay,bottomRightButtonEnabled), ATMO_PROPERTY(CompasDisplay, topLeftButtonEnabled), ATMO_PROPERTY(CompasDisplay, bottomLeftButtonEnabled));
	config.x = ATMO_PROPERTY(CompasDisplay, x);
    config.y = ATMO_PROPERTY(CompasDisplay, y);
	strncpy(config.topLeftButtonLabel, ATMO_PROPERTY(CompasDisplay, topLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.topRightButtonLabel, ATMO_PROPERTY(CompasDisplay, topRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomLeftButtonLabel, ATMO_PROPERTY(CompasDisplay, bottomLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomRightButtonLabel, ATMO_PROPERTY(CompasDisplay, bottomRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
    config.spanX = ATMO_PROPERTY(CompasDisplay, spanX);
	config.spanY = ATMO_PROPERTY(CompasDisplay, spanY);
    config.title = ATMO_PROPERTY(CompasDisplay, pageTitle);
    config.titleHidden = ATMO_PROPERTY(CompasDisplay, titleHidden);
	ATMO_UI_ICONLINES_Init(&config, ATMO_PROPERTY(CompasDisplay, numLines), false);
	ATMO_VARIABLE(CompasDisplay, pageHandle) = config.templateInstance;
    ATMO_UI_ICONLINES_SetMainText(config.templateInstance, 0, ATMO_PROPERTY(CompasDisplay, line1Text));
    ATMO_UI_ICONLINES_SetMainText(config.templateInstance, 1, ATMO_PROPERTY(CompasDisplay, line2Text));
    ATMO_UI_ICONLINES_SetMainText(config.templateInstance, 2, ATMO_PROPERTY(CompasDisplay, line3Text));
    ATMO_UI_ICONLINES_SetMainText(config.templateInstance, 3, ATMO_PROPERTY(CompasDisplay, line4Text));
    ATMO_UI_ICONLINES_SetIconLabel(config.templateInstance, ATMO_PROPERTY(CompasDisplay, iconLabel));
    ATMO_UI_ICONLINES_RegisterButtonAbilityHandle(ATMO_VARIABLE(CompasDisplay,pageHandle), 1, ATMO_ABILITY(CompasDisplay, topRightButtonPressed));
	ATMO_UI_ICONLINES_RegisterButtonAbilityHandle(ATMO_VARIABLE(CompasDisplay,pageHandle), 2, ATMO_ABILITY(CompasDisplay, bottomRightButtonPressed));
	ATMO_UI_ICONLINES_RegisterButtonAbilityHandle(ATMO_VARIABLE(CompasDisplay,pageHandle), 3, ATMO_ABILITY(CompasDisplay, topLeftButtonPressed));
    ATMO_UI_ICONLINES_RegisterButtonAbilityHandle(ATMO_VARIABLE(CompasDisplay,pageHandle), 4, ATMO_ABILITY(CompasDisplay, bottomLeftButtonPressed));
    ATMO_UI_ICONLINES_SetIcon(config.templateInstance, ATMO_PROPERTY(CompasDisplay, icon));
    ATMO_UI_ICONLINES_RegisterOnDisplayedAbilityHandle(ATMO_VARIABLE(CompasDisplay,pageHandle), ATMO_ABILITY(CompasDisplay, onDisplayed));
    ATMO_UI_ICONLINES_RegisterOnLeaveAbilityHandle(config.templateInstance, ATMO_ABILITY(CompasDisplay, onLeave));
    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_setLine1Text(ATMO_Value_t *in, ATMO_Value_t *out) {

    char label[32];
    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)
    {
        ATMO_UI_ICONLINES_SetMainText(ATMO_VARIABLE(CompasDisplay,pageHandle), 0, label);
    }
    else
    {
        return ATMO_Status_Fail;
    }

    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_setLine2Text(ATMO_Value_t *in, ATMO_Value_t *out) {

    char label[32];
    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)
    {
        ATMO_UI_ICONLINES_SetMainText(ATMO_VARIABLE(CompasDisplay,pageHandle), 1, label);
    }
    else
    {
        return ATMO_Status_Fail;
    }

    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_setLine3Text(ATMO_Value_t *in, ATMO_Value_t *out) {

    char label[32];
    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)
    {
        ATMO_UI_ICONLINES_SetMainText(ATMO_VARIABLE(CompasDisplay,pageHandle), 2, label);
    }
    else
    {
        return ATMO_Status_Fail;
    }

    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_setLine4Text(ATMO_Value_t *in, ATMO_Value_t *out) {

    char label[32];
    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)
    {
        ATMO_UI_ICONLINES_SetMainText(ATMO_VARIABLE(CompasDisplay,pageHandle), 3, label);
    }
    else
    {
        return ATMO_Status_Fail;
    }

    return ATMO_Status_Success;
    
}


ATMO_Status_t CompasDisplay_topRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t CompasDisplay_bottomRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t CompasDisplay_topLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t CompasDisplay_bottomLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t CompassAngle_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
// Get the vector of values.
ATMO_3dFloatVector_t values; ATMO_Get3dVectorFloat(in, &values);

// Update the x and y centers
ATMO_Value_t atmox, atmoy;
ATMO_CreateValueFloat (&atmox, values.x); MagCenterX_trigger (&atmox, 0);
ATMO_CreateValueFloat (&atmoy, values.y); MagCenterY_trigger (&atmoy, 0);

// Get the MagCenterX and MagCenterY
MagCenterX_trigger (0, &atmox); float xcenter; ATMO_GetFloat (&atmox, &xcenter);
MagCenterY_trigger (0, &atmoy); float ycenter; ATMO_GetFloat (&atmoy, &ycenter);



//char testStr[64];
double x = values.x - xcenter; // 61.875;
double y = values.y - ycenter; // + 89.75;
double z = values.z - 77;
double angle = atan2 (x, y) * 180.0 / 3.141592;
char direction[32];
sprintf (direction, "   %.0f", angle);


//sprintf(testStr, "X: %.2f\r\nY:%.2f\nZ:%.2f\nang:%.2f", x, y, z, angle);
ATMO_CreateValueString(out, direction);
    	return ATMO_Status_Success;
	return ATMO_Status_Success;
}


ATMO_Status_t EmbeddedNxpRpkBacklight_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t EmbeddedNxpRpkBacklight_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

    Backlight_SetLevel(ATMO_PROPERTY(EmbeddedNxpRpkBacklight, initialSetting));
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedNxpRpkBacklight_setBacklightOff(ATMO_Value_t *in, ATMO_Value_t *out) {

    Backlight_SetLevel(BLIGHT_LEVEL_OFF);
	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBacklight_setBacklightLow(ATMO_Value_t *in, ATMO_Value_t *out) {

    Backlight_SetLevel(BLIGHT_LEVEL_LOW);
	return ATMO_Status_Success;
	
}


ATMO_Status_t EmbeddedNxpRpkBacklight_setBacklightMedium(ATMO_Value_t *in, ATMO_Value_t *out) {

    Backlight_SetLevel(BLIGHT_LEVEL_MEDIUM);
	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBacklight_setBacklightHigh(ATMO_Value_t *in, ATMO_Value_t *out) {

    Backlight_SetLevel(BLIGHT_LEVEL_HIGH);
	return ATMO_Status_Success;
	
}


ATMO_Status_t ReturnCourse_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
static double xtotal = 0.0;
static double ytotal = 0.0;
static double count = 0.0;

    	ATMO_3dFloatVector_t values;
ATMO_Get3dVectorFloat(in, &values);
//char testStr[64];
double x = values.x + 61.875;
double y = values.y + 89.75;
double z = values.z - 77;
double angle = atan2 (x, y);

double xcurrent = sin (angle);
double ycurrent = cos (angle);

//Exponentially Weighted Moving Average
// Will be converted to straight average.
count += 1;
//xtotal = xtotal * 0.9 + xcurrent * 0.1;
//ytotal = ytotal * 0.9 + ycurrent * 0.1;

// Real totals
xtotal = xtotal + xcurrent;
ytotal = ytotal + ycurrent;

double returnangle = atan2 (xtotal, ytotal) * 180 / 3.14159265359;
//returnangle = returnangle + 180.0;
//if (returnangle > 180) returnangle -= 360.0;
char direction[32];
sprintf (direction, "%.2f", returnangle);


//sprintf(testStr, "X: %.2f\r\nY:%.2f\nZ:%.2f\nang:%.2f", x, y, z, angle);
ATMO_CreateValueString(out, direction);
    	return ATMO_Status_Success;
}


ATMO_Status_t MagCenterX_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
    static float minValue = 99999.0;
    static float maxValue = -99999.0;
    if (in != 0)
    {
        float value;
        ATMO_GetFloat (in, &value);
        if (value < minValue) minValue = value;
        if (value > maxValue) maxValue = value;
        if (value == 99999.0) 
        {
            minValue = 99999.0;
            maxValue = -99999.0;
        }
    }
    if (out != 0)
    {
        float av = (minValue + maxValue) / 2.0;
        ATMO_CreateValueFloat (out, av);
    }
	return ATMO_Status_Success;
}


ATMO_Status_t MagCenterY_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
    static float minValue = 99999.0;
    static float maxValue = -99999.0;
    if (in != 0)
    {
        float value;
        ATMO_GetFloat (in, &value);
        if (value < minValue) minValue = value;
        if (value > maxValue) maxValue = value;
        if (value == 99999.0) 
        {
            minValue = 99999.0;
            maxValue = -99999.0;
        }
    }
    if (out != 0)
    {
        float av = (minValue + maxValue) / 2.0;
        ATMO_CreateValueFloat (out, av);
    }
	return ATMO_Status_Success;
}


ATMO_Status_t SetupMenu_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t SetupMenu_displayPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(SetupMenu, x), ATMO_PROPERTY(SetupMenu, y), false);
	return ATMO_Status_Success;
	
}


ATMO_Status_t SetupMenu_topRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t SetupMenu_bottomRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t SetupMenu_topLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t SetupMenu_bottomLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

...

This file has been truncated, please download it to see its full contents.

Credits

Peter Smith

Peter Smith

2 projects • 3 followers
C# Programmer for many years, and a lover of all things IOT and Bluetooth.

Comments