Skip to content

Commit

Permalink
Add arc time counter sampling periodically 1 second with red LED blin…
Browse files Browse the repository at this point in the history
…k, and send data every 5 minute.
  • Loading branch information
Anol Paisal committed Mar 29, 2022
1 parent f81b8da commit 3b1e44a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
40 changes: 23 additions & 17 deletions src/apps/LoRaMac/periodic-uplink-lpp-counter/SKiM980A/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ int main( void )
TimerSetValue( &Led4Timer, 25 );

TimerInit( &Led2Timer, OnLed2TimerEvent );
TimerSetValue( &Led2Timer, 500 );
TimerSetValue( &Led2Timer, 1000 );
TimerStart(&Led2Timer);

TimerInit( &LedBeaconTimer, OnLedBeaconTimerEvent );
Expand Down Expand Up @@ -379,9 +379,9 @@ int main( void )
BoardLowPowerHandler( );

}



CRITICAL_SECTION_END( );

}
}

Expand Down Expand Up @@ -535,7 +535,7 @@ static void PrepareTxFrame( void )
// AppData.BufferSize = CayenneLppGetSize( );

/* Test uplink WKUP and IO2 */

uplink_buffer[0U] = in_cnt >> 24U;
uplink_buffer[1U] = in_cnt >> 16U;
uplink_buffer[2U] = in_cnt >> 8U;
Expand All @@ -560,7 +560,7 @@ static void PrepareTxFrame( void )
{
NvmmWrite(uplink_buffer, APP_SIZE, 0x0FF8);
}

in_out_cnt = 0;
}
}

Expand Down Expand Up @@ -646,6 +646,7 @@ static void OnLed4TimerEvent( void* context )
* Function executed on Led 2 Timeout event
*/
bool IsArc = false;

static void OnLed2TimerEvent( void* context )
{
TimerStop( &Led2Timer );
Expand All @@ -654,18 +655,23 @@ static void OnLed2TimerEvent( void* context )

uint8_t potiLevel = BoardGetPotiLevel();

if(potiLevel < 50 && !IsArc)
if(potiLevel < 75)
{
IsArc = true;
OnIO2Event(NULL);
printf("Arc lvl: %d\n", potiLevel);
} else if (potiLevel > 50 && IsArc)

//TODO: TOGGLE LED BLINK
GpioToggle(&Io1);

} else if (potiLevel > 75 && IsArc)
{
IsArc = false;
printf("Arc lvl: %d\n", potiLevel);
//TODO: LED OFF
GpioWrite( &Io1, 0 );
}



TimerStart( &Led2Timer );
}

Expand Down Expand Up @@ -698,22 +704,22 @@ void OnWKUPEvent(void *context)

CRITICAL_SECTION_BEGIN( );

TimerStop( &TxTimer );
// TimerStop( &TxTimer );
IsStopMode = 1U;

while (--timeout > 0x0);

in_cnt++;

IsTxFramePending = 1;
// IsTxFramePending = 1;

CRITICAL_SECTION_END( ) ;

printf("In : %ld\n", in_cnt);

// Schedule next transmission
TimerSetValue( &TxTimer, TxPeriodicity );
TimerStart( &TxTimer );
// TimerSetValue( &TxTimer, TxPeriodicity );
// TimerStart( &TxTimer );
}

/*!
Expand All @@ -733,21 +739,21 @@ void OnIO2Event(void *context)

CRITICAL_SECTION_BEGIN( );

TimerStop( &TxTimer );
// TimerStop( &TxTimer );
IsStopMode = 2U;

// while (--timeout > 0);

in_out_cnt++;

// read/write input/output
IsTxFramePending = 1;
// IsTxFramePending = 1;

CRITICAL_SECTION_END( ) ;

printf("In Out: %ld\n", in_out_cnt);

// Schedule next transmission
TimerSetValue( &TxTimer, TxPeriodicity );
TimerStart( &TxTimer );
// TimerSetValue( &TxTimer, TxPeriodicity );
// TimerStart( &TxTimer );
}
14 changes: 13 additions & 1 deletion src/apps/LoRaMac/periodic-uplink-lpp/NucleoL152/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,26 @@ static void PrepareTxFrame( void )
uint8_t channel = 0;

AppData.Port = LORAWAN_APP_PORT;

#if 0
CayenneLppReset( );
CayenneLppAddDigitalInput( channel++, AppLedStateOn );
CayenneLppAddAnalogInput( channel++, BoardGetBatteryLevel( ) * 100 / 254 );

CayenneLppCopy( AppData.Buffer );
AppData.BufferSize = CayenneLppGetSize( );
#else

AppData.Buffer[0] = 0x0;
AppData.Buffer[1] = 0x0;
AppData.Buffer[2] = 0x0;
AppData.Buffer[3] = 0x01;
AppData.Buffer[4] = 0x0;
AppData.Buffer[5] = 0x0;
AppData.Buffer[6] = 0x0;
AppData.Buffer[7] = 0x01;
AppData.Buffer[8] = BoardGetBatteryLevel( ) * 100 / 254;
AppData.BufferSize = 9;
#endif
if( LmHandlerSend( &AppData, LmHandlerParams.IsTxConfirmed ) == LORAMAC_HANDLER_SUCCESS )
{
// Switch LED 1 ON
Expand Down
2 changes: 1 addition & 1 deletion src/boards/NucleoL152/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ list(APPEND ${PROJECT_NAME}_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_rtc.c"
"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_rtc_ex.c"
"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_spi.c"
"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_spi_ex.c"
#"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_spi_ex.c"
"${CMAKE_CURRENT_SOURCE_DIR}/../mcu/stm32/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_uart.c"
)

Expand Down
2 changes: 1 addition & 1 deletion src/boards/SKiM980A/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void BoardGetUniqueId( uint8_t *id )
/*!
* Potentiometer max and min levels definition
*/
#define POTI_MAX_LEVEL 900
#define POTI_MAX_LEVEL 3000
#define POTI_MIN_LEVEL 10

uint8_t BoardGetPotiLevel( void )
Expand Down

0 comments on commit 3b1e44a

Please sign in to comment.