Automatically add code to main.c
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build & Publish / build (push) Successful in 10m5s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build & Publish / build (push) Successful in 10m5s
				
			This commit is contained in:
		@@ -8,4 +8,6 @@ COPY snippets /opt/snippets
 | 
			
		||||
 | 
			
		||||
RUN sudo chmod +x /opt/script.sh
 | 
			
		||||
 | 
			
		||||
WORKDIR /opt
 | 
			
		||||
 | 
			
		||||
ENTRYPOINT /opt/script.sh
 | 
			
		||||
							
								
								
									
										27
									
								
								script.sh
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								script.sh
									
									
									
									
									
								
							@@ -20,19 +20,6 @@ display_result() {
 | 
			
		||||
    --msgbox "$2" -1 -1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
display_code() {
 | 
			
		||||
    string="----- Imports -----
 | 
			
		||||
${2}
 | 
			
		||||
 | 
			
		||||
----- Code -----
 | 
			
		||||
${3}"
 | 
			
		||||
    
 | 
			
		||||
    dialog --title "$1" \
 | 
			
		||||
    --backtitle "Configure Zephyr RTOS" \
 | 
			
		||||
    --no-collapse \
 | 
			
		||||
    --msgbox "$string" -1 -1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main_dialog() {
 | 
			
		||||
    selection=$(dialog --stdout \
 | 
			
		||||
        --backtitle "Configure Zephyr RTOS" \
 | 
			
		||||
@@ -201,10 +188,13 @@ sensors_dialog() {
 | 
			
		||||
    
 | 
			
		||||
    case $sensors in
 | 
			
		||||
        1 ) # Button
 | 
			
		||||
            imports=$(cat snippets/button/imports.txt)
 | 
			
		||||
            code=$(cat snippets/led/code.txt)
 | 
			
		||||
            echo $code >> /workdir/app/src/main.c
 | 
			
		||||
 | 
			
		||||
            display_code "Use this code snippet" "$imports" "$code"
 | 
			
		||||
            config=$(cat snippets/led/config.txt)
 | 
			
		||||
            echo $config >> /workdir/app/prj.conf
 | 
			
		||||
 | 
			
		||||
            display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
 | 
			
		||||
        ;;
 | 
			
		||||
        2 )
 | 
			
		||||
            # TODO
 | 
			
		||||
@@ -227,10 +217,13 @@ actuators_dialog() {
 | 
			
		||||
    
 | 
			
		||||
    case $actuators in
 | 
			
		||||
        1 ) # LED
 | 
			
		||||
            imports=$(cat snippets/led/imports.txt)
 | 
			
		||||
            code=$(cat snippets/led/code.txt)
 | 
			
		||||
            echo "$code" >> /workdir/app/src/main.c
 | 
			
		||||
 | 
			
		||||
            display_code "Use this code snippet" "$imports" "$code"
 | 
			
		||||
            config=$(cat snippets/led/config.txt)
 | 
			
		||||
            echo "$config" >> /workdir/app/prj.conf
 | 
			
		||||
 | 
			
		||||
            display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
 | 
			
		||||
        ;;
 | 
			
		||||
        2 )
 | 
			
		||||
            # TODO
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,10 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* --------------------------- */
 | 
			
		||||
/*            Buttons          */
 | 
			
		||||
/* --------------------------- */
 | 
			
		||||
 | 
			
		||||
/* Imports / Declarations */
 | 
			
		||||
#include <zephyr/device.h>
 | 
			
		||||
#include <zephyr/drivers/gpio.h>
 | 
			
		||||
#include <zephyr/sys/util.h>
 | 
			
		||||
@@ -25,6 +32,7 @@ static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
 | 
			
		||||
						     {0});
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Functions */
 | 
			
		||||
void button_pressed(const struct device *dev, struct gpio_callback *cb,
 | 
			
		||||
		    uint32_t pins)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								snippets/button/config.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								snippets/button/config.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
CONFIG_GPIO=y
 | 
			
		||||
@@ -1,13 +1,25 @@
 | 
			
		||||
/* --------- */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* --------------------------- */
 | 
			
		||||
/*              LED            */
 | 
			
		||||
/* --------- */
 | 
			
		||||
/* --------------------------- */
 | 
			
		||||
 | 
			
		||||
/* Imports / Declarations */
 | 
			
		||||
#include <zephyr/kernel.h>
 | 
			
		||||
#include <zephyr/drivers/gpio.h>
 | 
			
		||||
 | 
			
		||||
/* The devicetree node identifier for the "led0" alias. */
 | 
			
		||||
#define LED0_NODE DT_ALIAS(led0)
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * A build error on this line means your board is unsupported.
 | 
			
		||||
 * See the sample documentation for information on how to fix this.
 | 
			
		||||
 */
 | 
			
		||||
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Functions */
 | 
			
		||||
int blink_led(void) {
 | 
			
		||||
int initialize_led(void) {
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
	if (!gpio_is_ready_dt(&led)) {
 | 
			
		||||
@@ -18,13 +30,17 @@ int blink_led(void) {
 | 
			
		||||
	if (ret < 0) {
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int blink_led(int blink_delay) {
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
	while (1) {
 | 
			
		||||
		ret = gpio_pin_toggle_dt(&led);
 | 
			
		||||
		if (ret < 0) {
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
        k_msleep(1000);
 | 
			
		||||
		k_msleep(blink_delay);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -34,7 +50,8 @@ Example:
 | 
			
		||||
 | 
			
		||||
int main(void)
 | 
			
		||||
{
 | 
			
		||||
	blink_led();
 | 
			
		||||
	initialize_led();
 | 
			
		||||
	blink_led(10000); # Millis
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								snippets/led/config.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								snippets/led/config.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
CONFIG_GPIO=y
 | 
			
		||||
		Reference in New Issue
	
	Block a user