Skip to content

Commit

Permalink
adding Zig examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubberazer committed Jun 28, 2024
1 parent a469f19 commit 63ec18a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 37 deletions.
5 changes: 2 additions & 3 deletions EXAMPLES_C++/jetgpio_PWM_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ int main(int argc, char *argv[])
/* PWM frequency set up okay*/
printf("PWM frequency set up okay at pin 32. Return code: %d\n", PWMstat);
}
/* Set up PWM duty cycle to approx 50% (0=0% to 256=100%) @ pin 32*/

/* Set up PWM duty cycle to approx 50% (0=0% to 256=100%) @ pin 32*/
int PWMstat2 = gpioPWM(32, 127);

if (PWMstat2 < 0)
Expand All @@ -61,7 +60,7 @@ int main(int argc, char *argv[])
sleep(2);
x++;
}
// Terminating library
// Terminating library
gpioTerminate();
printf("PWM stopped, bye!\n");
exit(0);
Expand Down
6 changes: 3 additions & 3 deletions EXAMPLES_C++/jetgpio_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char *argv[])
printf("gpio setting up okay. Return code: %d\n", stat);
}

// Now setting up pin 3 to detect edges, rising & falling edge with a 1000 useconds debouncing and when event is detected calling func "calling"
// Now setting up pin 3 to detect edges, rising & falling edge with a 1000 useconds debouncing and when event is detected calling func "calling"
int stat2 = gpioSetISRFunc(3, EITHER_EDGE, 1000, &timestamp, &calling);
if (stat2 < 0)
{
Expand All @@ -77,13 +77,13 @@ int main(int argc, char *argv[])
printf("gpio edge setting up okay. Return code: %d\n", stat2);
}

/* Now wait for the edge to be detected */
/* Now wait for the edge to be detected */
printf("Capturing edges, press Ctrl-c to terminate\n");
while (interrupt) {
// Do some stuff
sleep(1);
}
// Terminating library
// Terminating library
gpioTerminate();
exit(0);
}
Expand Down
8 changes: 3 additions & 5 deletions EXAMPLES_C++/jetgpio_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ int main(int argc, char *argv[])
printf("Jetgpio initialisation OK. Return code: %d\n", Init);
}

// Setting up pin 3 as OUTPUT and 7 as INPUT

// Setting up pin 3 as OUTPUT and 7 as INPUT
int stat1 = gpioSetMode(3, JET_OUTPUT);
if (stat1 < 0)
{
Expand All @@ -52,8 +51,7 @@ int main(int argc, char *argv[])
printf("gpio setting up okay. Return code: %d\n", stat2);
}

// Writing 1 and 0 to pin 3 at 1 second intervals while reading pin 7

// Writing 1 and 0 to pin 3 at 1 second intervals while reading pin 7
int x =0;
int level = 0;
while (x<5) {
Expand All @@ -70,7 +68,7 @@ int main(int argc, char *argv[])
x++;
}

// Terminating library
// Terminating library
gpioTerminate();

exit(0);
Expand Down
12 changes: 6 additions & 6 deletions EXAMPLES_C++/jetgpio_i2c_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char *argv[])
printf("Jetgpio initialisation OK. Return code: %d\n", Init);
}

/* Opening the connection to the I2C slave MPU6050 */
/* Opening the connection to the I2C slave MPU6050 */
int MPU6050 = i2cOpen(0,0);

if (MPU6050 >= 0)
Expand All @@ -61,17 +61,17 @@ int main(int argc, char *argv[])
printf("Open I2C port failed. Quitting MPU6050 Error code: %d\n", MPU6050);
}

/* Wake up the MPU-6050 with slave address 0x68 since it starts in sleep mode */
/* Wake up the MPU-6050 with slave address 0x68 since it starts in sleep mode */
int writestat = i2cWriteByteData(MPU6050, MPU6050_SLAVE_ADDRESS, PWR_MGMT_1, 0x00);
printf("write return: %d\n",writestat);
usleep(100000);

/* Now set up the accelerator range to 4G */
/* Now set up the accelerator range to 4G */
writestat = i2cWriteByteData(MPU6050, MPU6050_SLAVE_ADDRESS, ACCEL_CONFIG, ACCEL_RANGE_4G);
printf("write return: %d\n",writestat);
usleep(100000);

/* Now set up the gyroscope range to 250 deg/second */
/* Now set up the gyroscope range to 250 deg/second */
writestat = i2cWriteByteData(MPU6050, MPU6050_SLAVE_ADDRESS, GYRO_CONFIG, GYRO_RANGE_250DEG);
printf("write return: %d\n",writestat);
usleep(100000);
Expand Down Expand Up @@ -117,7 +117,7 @@ int main(int argc, char *argv[])
x++;
}

/* Closing i2c connection */
/* Closing i2c connection */
int i2cstat = i2cClose(MPU6050);

if (i2cstat >= 0)
Expand All @@ -131,7 +131,7 @@ int main(int argc, char *argv[])
printf("Closing I2C port failed. Quitting MPU6050 thread Error code: %d\n", i2cstat);
}

/* Terminating library */
/* Terminating library */
gpioTerminate();
exit(0);

Expand Down
2 changes: 0 additions & 2 deletions EXAMPLES_C++/lcd_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ int main(int argc, char *argv[]){
}

// Closing i2c connection

i2cClose(lcd);

// Terminating library

gpioTerminate();

exit(0);
Expand Down
20 changes: 9 additions & 11 deletions EXAMPLES_C++/spi_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ int main(int argc, char *argv[])
printf("Jetgpio initialisation OK. Return code: %d\n", Init);
}

/* Port SPI2 pins: 37, 22, 13 & 18
to perform a simple loop test, pins 22: SPI2_MISO & 37:SPI2_MOSI should be connected
with a short jumper cable, when the cable is disconnected the output on screen will show
all the rx values as zeros
spiOpen() parameters go as follows: spiOpen(port number, speed in Hz, mode, cs pin delay in us,
bits per word, least significant bit first, cs change)
*/
/* Port SPI2 pins: 37, 22, 13 & 18
to perform a simple loop test, pins 22: SPI2_MISO & 37:SPI2_MOSI should be connected
with a short jumper cable, when the cable is disconnected the output on screen will show all the rx values as zeros
spiOpen() parameters go as follows: spiOpen(port number, speed in Hz, mode, cs pin delay in us,
bits per word, least significant bit first, cs change)
*/

SPI_init = spiOpen(1, 5000000, 0, 0, 8, 1, 1);
if (SPI_init < 0)
Expand All @@ -57,8 +56,7 @@ int main(int argc, char *argv[])
tx[5] = 0xFF;
tx[6] = 0x11;

//Transfer data through register numbers for x, y & z axis

//Transfer data through register numbers for x, y & z axis
int i = 0;
while (i<20){

Expand Down Expand Up @@ -96,10 +94,10 @@ int main(int argc, char *argv[])
sleep(1);
}

// Closing spi port
// Closing spi port
spiClose(SPI_init);

// Terminating library
// Terminating library
gpioTerminate();

exit(0);
Expand Down
5 changes: 2 additions & 3 deletions EXAMPLES_C++/test_PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ int main(int argc, char *argv[])

int level = 0;

// Increase brightness

// Increase brightness
while (x<=256) {

usleep(100000);
Expand All @@ -67,8 +66,8 @@ int main(int argc, char *argv[])
}

x = 256;
// Decrease brightness

// Decrease brightness
while (x>=0) {

usleep(100000);
Expand Down
3 changes: 1 addition & 2 deletions EXAMPLES_C/jetgpio_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ int main(int argc, char *argv[])
printf("gpio setting up okay. Return code: %d\n", stat2);
}

// Writing 1 and 0 to pin 3 a 1 second intervals while reading pin 7

// Writing 1 and 0 to pin 3 a 1 second intervals while reading pin 7
int x =0;
int level = 0;
while (x<5) {
Expand Down
3 changes: 1 addition & 2 deletions EXAMPLES_C/test_PWM.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ int main(int argc, char *argv[])
int level = 0;

// Increase brightness

while (x<=256) {

usleep(100000);
Expand All @@ -69,8 +68,8 @@ int main(int argc, char *argv[])
}

x = 256;

// Decrease brightness

while (x>=0) {

usleep(100000);
Expand Down

0 comments on commit 63ec18a

Please sign in to comment.