Author Topic: SB π  (Read 56306 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #180 on: April 18, 2019, 08:12:10 PM »
I have no idea how to pull the cleanup into a new local directory. My searches for this info just made me more confused. I don't want to screw up the repo.

This seemed to work.

jrs@jrs-laptop:~/repo/sb-dev-cleanup$ git remote add -t cleanup -f origin https://sandbox.allbasic.info:8181/scriptbasic/sb-dev.git
Updating origin
remote: Enumerating objects: 4082, done.
remote: Counting objects: 100% (4082/4082), done.
remote: Compressing objects: 100% (2236/2236), done.
remote: Total 4082 (delta 1743), reused 4051 (delta 1727)
Receiving objects: 100% (4082/4082), 10.27 MiB | 8.80 MiB/s, done.
Resolving deltas: 100% (1743/1743), done.
From https://sandbox.allbasic.info:8181/scriptbasic/sb-dev
 * [new branch]      cleanup    -> origin/cleanup
jrs@jrs-laptop:~/repo/sb-dev-cleanup$ ls -l
total 0
jrs@jrs-laptop:~/repo/sb-dev-cleanup$ git pull

Now I keep getting errors trying to push my changes. Why does this have to be so cryptic?

I just used the Gitlab web UI to delete the old files and upload the new ones for SDBG.  :o


« Last Edit: April 18, 2019, 09:19:16 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: SB π
« Reply #181 on: April 19, 2019, 03:39:06 PM »
All you do is the following (first step is assuming you haven't cloned the repository previously):


Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #182 on: April 19, 2019, 06:51:18 PM »
I started over with a clean directory.

jrs@jrs-laptop:~/sb/examples/test$ cd ~/repo/sb-dev-cleanup
jrs@jrs-laptop:~/repo/sb-dev-cleanup$ git init
Initialized empty Git repository in /home/jrs/repo/sb-dev-cleanup/.git/
jrs@jrs-laptop:~/repo/sb-dev-cleanup$ git clone https://sandbox.allbasic.info:8181/scriptbasic/sb-dev.git
Cloning into 'sb-dev'...
remote: Enumerating objects: 4127, done.
remote: Counting objects: 100% (4127/4127), done.
remote: Compressing objects: 100% (2262/2262), done.
remote: Total 4127 (delta 1773), reused 4091 (delta 1746)
Receiving objects: 100% (4127/4127), 10.28 MiB | 2.99 MiB/s, done.
Resolving deltas: 100% (1773/1773), done.
jrs@jrs-laptop:~/repo/sb-dev-cleanup$ git checkout cleanup
error: pathspec 'cleanup' did not match any file(s) known to git
jjrs@jrs-laptop:~/repo/sb-dev-cleanup$ git branch
jrs@jrs-laptop:~/repo/sb-dev-cleanup$

It seems to create a sb-dev sub-directory in my new sb-dev-cleanup repo. I changed directory to sb-dev and tried the last two commands again.

jrs@jrs-laptop:~/repo/sb-dev-cleanup$ ls -l
total 12
drwxr-xr-x 16 jrs jrs 12288 Apr 19 18:48 sb-dev
jrs@jrs-laptop:~/repo/sb-dev-cleanup$ cd sb-dev
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git checkout cleanup
Branch 'cleanup' set up to track remote branch 'cleanup' from 'origin'.
Switched to a new branch 'cleanup'
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git branch
* cleanup
  master
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git pull
Already up to date.
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git add .
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git commit -m "SDBG - dbgcon.sb remote debugger"
On branch cleanup
Your branch is up to date with 'origin/cleanup'.

nothing to commit, working tree clean
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git add extensions/sdbg/dbgcon.sb
The following paths are ignored by one of your .gitignore files:
extensions/sdbg/dbgcon.sb
Use -f if you really want to add them.
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ ls -l extensions/sdbg/dbgcon.sb
-rw-rw-r-- 1 jrs jrs 1612 Apr 18 17:49 extensions/sdbg/dbgcon.sb
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git add -f extensions/sdbg/dbgcon.sb
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git commit -m "SDBG - dbgcon.sb remote debugger"
[cleanup c35b2c9] SDBG - dbgcon.sb remote debugger
 1 file changed, 65 insertions(+)
 create mode 100644 extensions/sdbg/dbgcon.sb
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$ git push
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.14 KiB | 1.14 MiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote:
remote: To create a merge request for cleanup, visit:
remote:   https://sandbox.allbasic.info/scriptbasic/sb-dev/merge_requests/new?merge_request%5Bsource_branch%5D=cleanup
remote:
To https://sandbox.allbasic.info:8181/scriptbasic/sb-dev.git
   7160bfd..c35b2c9  cleanup -> cleanup
jrs@jrs-laptop:~/repo/sb-dev-cleanup/sb-dev$

My push of dbgcon.sb showed up in the cleanup branch as expected. Sure was a long road getting there.  :-\

Thanks for the help with this!

« Last Edit: April 19, 2019, 09:04:41 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: SB π
« Reply #183 on: April 19, 2019, 09:36:57 PM »
You made it much harder than it needed to be.

you could have done:

git clone https://sandbox.allbasic.info:8181/scriptbasic/sb-dev.git sb-dev-cleanup

No creation of the folder required, and no git init required.

Then git checkout cleanup

Make your changes/additions

git add:  NEVER do '.'  That can add a bunch of additional files that may not be excluded via .gitignore.  Also, don't use the "-f" switch. That will add files that normally are excluded via the .gitignore file.

git commit -m:  ALWAYS be descriptive.  In other worlds, describe WHY you're committing, not just what.  You'll thank me in a year when you try to remember why a particular commit was made.

Also, if you modify several files, add and commit each separately with a full description.  If you ever need to revert a commit, you won't inadvertently undo other changes that are good.

In the end, all you really needed to do was run git checkout cleanup in your sb-dev folder and it would have switched that to the cleanup branch where all development has been happening for the last couple of months.

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #184 on: April 20, 2019, 08:03:33 PM »
It would be great if the ScriptBasic build system would create the bin/mod/object directory for a new extension module being built. Does a new module have to be 'registered' to have everything done by the build script?

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: SB π
« Reply #185 on: April 20, 2019, 08:57:45 PM »
How long have you been using SB?   ;D

Let's say your creating a new module called 'opengl'.

Run the setup script like this:  setup --module=opengl

Now if you look in the extensions folder, you'll have a new folder called 'opengl'.  In it, you'll find the typical items like the interface.c file, a .bas file, etc.

You'll edit the interface.c file, setting it up like the build script expects.  Which means that if you do that correctly you won't need to manually create the .bas file.

You may want to add some additional support files; for an example, look at the lxml or slre modules to see what I mean.

If you have those in there, the build script will add the source files (.c) to the build process so they will be compiled along with the interface.c file into the final lib.

When you're ready, run setup or setup --module=opengl (example) and you'll find the lib added to the bin/mod/dll folder.

At this point, if you run the mkdist.sh script I wrote, feeding it a target folder, it will create the expected file structure at that location with everything where it is supposed to be, ready for testing.  If you then copy the AppRun script from the appimage_files folder into the target folder you used previously, you can execute it (AppRun, NOT scriba!) feeding it the name of a script.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #186 on: April 20, 2019, 10:43:05 PM »
It just seemed in the past I always had to create the bin/mod/obj/ext_mod folder as it would error out running. /setup --module=ext_mod.

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: SB π
« Reply #187 on: April 20, 2019, 11:36:27 PM »
You need to run ./setup at least one time to create the folder structure.  After that, you can use --module=

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #188 on: April 21, 2019, 12:20:26 AM »
Unexpected guest. Cot comes out of the closet.

Makes sense.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #189 on: April 21, 2019, 09:57:28 AM »
Quote
How long have you been using SB?   

Since 2005.

I'm still unwrapping the present.  ;)

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #190 on: April 25, 2019, 12:42:44 PM »
AIR,

I'm going to create a new repo in the SciptBasic project for non-distribution extension modules. The branch approach doesn't seem appropriate here.

Please join us on the https://RaspberyBASIC.org/forum for RPi ScriptBasic focused activity.
« Last Edit: April 25, 2019, 01:50:57 PM by John »

Offline jalih

  • Advocate
  • Posts: 109
Re: SB π
« Reply #191 on: April 26, 2019, 09:50:26 AM »
John,

Do you have some short C code to do something simple (like control LED or get temperature) things with Sense HAT? I would like to try porting it to 8th as it got support for GPIO and I2C. Problem is I know nothing about GPIO or I2C, but would like to learn as my ROCK64 is waiting for delivery.

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #192 on: April 26, 2019, 11:01:17 AM »
I'm waiting to hear from hippy about the gpio extension module I wrote and posted the code in the sandbox under the extensions project.

I found a i2c based Raspberry Pi Sense HAT library written in C that works. (except the LED part) I'm getting this strange runtime error when I try to call functions with arguments.

@AIR - I wonder if I need to do the SB lval stuff rather than how it worked in straight C.


pi@RPi3B:~/sbrpi/examples $ scriba testhat.sb
scriba: symbol lookup error: /home/pi/sbrpi/modules/shat.so: undefined symbol: __aeabi_idiv
pi@RPi3B:~/sbrpi/examples $ scriba testhat.sb
Temp: 0
Humidity: 0
pi@RPi3B:~/sbrpi/examples $


Code: ScriptBasic
  1. IMPORT shat.bas
  2.  
  3. SHAT::Init(1)
  4. temp = 0
  5. humid = 0
  6. ' SHAT::GetTempHumid(temp, humid)
  7. PRINT "Temp: ", temp, "\n"
  8. PRINT "Humidity: ", humid, "\n"
  9. SHAT::Shutdown
  10.  

shat.bas
Code: ScriptBasic
  1. ' Raspberry Pi Sense HAT
  2.  
  3. MODULE SHAT
  4.  
  5. DECLARE SUB  ::Init          ALIAS  "shInit"          LIB  "shat"
  6. DECLARE SUB  ::GetAccel      ALIAS  "shGetAccel"      LIB  "shat"
  7. DECLARE SUB  ::GetGyro       ALIAS  "shGetGyro"       LIB  "shat"
  8. DECLARE SUB  ::GetMagneto    ALIAS  "shGetMagneto"    LIB  "shat"
  9. DECLARE SUB  ::GetTempHumid  ALIAS  "shGetTempHumid"  LIB  "shat"
  10. DECLARE SUB  ::Shutdown      ALIAS  "shShutdown"      LIB  "shat"
  11. DECLARE SUB  ::ReadJoystick  ALIAS  "shReadJoystick"  LIB  "shat"
  12.  
  13. END MODULE
  14.  

interface.c
Code: C
  1. /* Raspberry Pi Sense HAT
  2. UXLIBS: -lpthread -lm -lc
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <fcntl.h>
  11. #include <sys/ioctl.h>
  12. #include <linux/i2c-dev.h>
  13. #include "../../basext.h"
  14.  
  15.  
  16. /***************************
  17.  Extension Module Functions
  18. ***************************/
  19.  
  20. typedef struct _ModuleObject {
  21.   void *HandleArray;
  22. }ModuleObject,*pModuleObject;
  23.  
  24.  
  25. besVERSION_NEGOTIATE
  26.   return (int)INTERFACE_VERSION;
  27. besEND
  28.  
  29.  
  30. besSUB_START
  31.   pModuleObject p;
  32.  
  33.   besMODULEPOINTER = besALLOC(sizeof(ModuleObject));
  34.   if( besMODULEPOINTER == NULL )return 0;
  35.  
  36.   p = (pModuleObject)besMODULEPOINTER;
  37.   return 0;
  38. besEND
  39.  
  40.  
  41. besSUB_FINISH
  42.   pModuleObject p;
  43.  
  44.   p = (pModuleObject)besMODULEPOINTER;
  45.   if( p == NULL )return 0;
  46.   return 0;
  47. besEND
  48.  
  49.  
  50. /***************
  51.  GPIO Functions
  52. ***************/
  53.  
  54.  
  55. static unsigned char LEDArray[192];
  56.  
  57. // I2C file handles
  58. static int file_led = -1; // LED array
  59. static int file_hum = -1; // humidity/temp sensor
  60. static int file_pres = -1; // pressure sensor
  61. static int file_acc = -1; // accelerometer/gyro
  62. static int file_mag = -1; // magnetometer
  63.  
  64. static int i2cRead(int iHandle, unsigned char ucAddr, unsigned char *buf, int iLen);
  65. static int i2cWrite(int iHandle, unsigned char ucAddr, unsigned char *buf, int iLen);
  66. // humidity/temp calibration values
  67. static int H0_rH_x2, H1_rH_x2, T0_degC_x8;
  68. static int T1_degC_x8, H0_T0_OUT;
  69. static int H1_T0_OUT, T0_OUT, T1_OUT;
  70.  
  71. static int i2cRead(int iHandle, unsigned char ucAddr, unsigned char *buf, int iLen)
  72. {
  73. int rc;
  74.  
  75.         rc = write(iHandle, &ucAddr, 1);
  76.         if (rc == 1)
  77.         {
  78.                 rc = read(iHandle, buf, iLen);
  79.         }
  80.         return rc;
  81. } /* i2cRead() */
  82.  
  83. static int i2cWrite(int iHandle, unsigned char ucAddr, unsigned char *buf, int iLen)
  84. {
  85. unsigned char ucTemp[512];
  86. int rc;
  87.  
  88.         if (iLen > 511 || iLen < 1 || buf == NULL)
  89.                 return -1; // invalid write
  90.  
  91.         ucTemp[0] = ucAddr; // send the register number first
  92.         memcpy(&ucTemp[1], buf, iLen); // followed by the data
  93.         rc = write(iHandle, ucTemp, iLen+1);
  94.         return rc-1;
  95.  
  96. } /* i2cWrite() */
  97.  
  98.  
  99. besFUNCTION(shInit)
  100.   int iChannel;
  101.  
  102.   besARGUMENTS("i")
  103.     &iChannel
  104.   besARGEND
  105.  
  106.   unsigned char ucTemp[32];
  107.   char filename[32];
  108.  
  109.         sprintf(filename, "/dev/i2c-%d", iChannel);
  110.         if ((file_led = open(filename, O_RDWR)) < 0)
  111.         {
  112.                 // fprintf(stderr, "Failed to open the i2c bus; need to run as sudo?\n");
  113.                 besRETURN_LONG(-1);
  114.         }
  115.  
  116. /* TODO
  117.         if (ioctl(file_led, I2C_SLAVE, 0x46) < 0)
  118.         {
  119.                 fprintf(stderr, "Failed to acquire bus for LED matrix\n");
  120.                 goto badexit;
  121.         }
  122. */
  123.  
  124.         file_acc = open(filename, O_RDWR);
  125.         if (ioctl(file_acc, I2C_SLAVE, 0x6a) < 0)
  126.         {
  127.                 fprintf(stderr, "Failed to acquire bus for accelerometer\n");
  128.                 goto badexit;
  129.         }
  130.         file_mag = open(filename, O_RDWR);
  131.         if (ioctl(file_mag, I2C_SLAVE, 0x1c) < 0)
  132.         {
  133.                 fprintf(stderr, "Failed to acquire bus for magnetometer\n");
  134.                 goto badexit;
  135.         }
  136.  
  137. /* TODO
  138.         // Fill the LED with black
  139.         memset(LEDArray, 0, sizeof(LEDArray));
  140.         i2cWrite(file_led, 0, LEDArray, sizeof(LEDArray));
  141. */
  142.  
  143.         file_hum = open(filename, O_RDWR);
  144.         if (ioctl(file_hum, I2C_SLAVE, 0x5f) < 0)
  145.         {
  146.                 fprintf(stderr, "Failed to acquire bus for Humidity sensor\n");
  147.                 goto badexit;
  148.         }
  149.         file_pres = open(filename, O_RDWR);
  150.         if (ioctl(file_pres, I2C_SLAVE, 0x5C) < 0)
  151.         {
  152.                 fprintf(stderr, "Failed to aquire bus for Pressure sensor\n");
  153.                 goto badexit;
  154.         }
  155.         // Prepare humidity sensor
  156.         i2cRead(file_hum, 0x10, ucTemp, 1); // AV_CONF
  157.         ucTemp[0] &= 0xc0;
  158.         ucTemp[0] |= 0x1b; // avgt=16, avgh=32
  159.         i2cWrite(file_hum, 0x10, ucTemp, 1);
  160.  
  161.         i2cRead(file_hum, 0x20+0x80, ucTemp, 3); // get CTRL_REG 1-3
  162.         ucTemp[0] &= 0x78; // keep reserved bits
  163.         ucTemp[0] |= 0x81; // turn on + 1Hz sample rate
  164.         ucTemp[1] &= 0x7c; // turn off heater + boot + one shot
  165.         i2cWrite(file_hum, 0x20+0x80, ucTemp, 3); // turn on + set sample rate
  166.  
  167.         // Get the H/T calibration values
  168.         i2cRead(file_hum, 0x30+0x80, ucTemp, 16);
  169.         H0_rH_x2 = ucTemp[0];
  170.         H1_rH_x2 = ucTemp[1];
  171.         T0_degC_x8 = ucTemp[2];
  172.         T1_degC_x8 = ucTemp[3];
  173.         T0_degC_x8 |= ((ucTemp[5] & 0x3) << 8); // 2 msb bits
  174.         T1_degC_x8 |= ((ucTemp[5] & 0xc) << 6);
  175.         H0_T0_OUT = ucTemp[6] | (ucTemp[7] << 8);
  176.         H1_T0_OUT = ucTemp[10] | (ucTemp[11] << 8);
  177.         T0_OUT = ucTemp[12] | (ucTemp[13] << 8);
  178.         T1_OUT = ucTemp[14] | (ucTemp[15] << 8);
  179.         if (H0_T0_OUT > 32767) H0_T0_OUT -= 65536; // signed
  180.         if (H1_T0_OUT > 32767) H1_T0_OUT -= 65536;
  181.         if (T0_OUT > 32767) T0_OUT -= 65536;
  182.         if (T1_OUT > 32767) T1_OUT -= 65536;
  183.  
  184.         // prepare pressure sensor
  185.         ucTemp[0] = 0x90; // turn on and set 1Hz update
  186.         i2cWrite(file_pres, 0x20, ucTemp, 1);
  187.        
  188.         // Init magnetometer
  189.         ucTemp[0] = 0x48; // output data rate/power mode
  190.         ucTemp[1] = 0x00; // default scale
  191.         ucTemp[2] = 0x00; // continuous conversion
  192.         ucTemp[3] = 0x08; // high performance mode
  193.         i2cWrite(file_mag, 0x20+0x80, ucTemp, 4);
  194.  
  195.         // Init accelerometer/gyroscope
  196.         ucTemp[0] = 0x60; // 119hz accel
  197.         i2cWrite(file_acc, 0x20, ucTemp, 1);
  198.         ucTemp[0] = 0x38; // enable gyro on all axes
  199.         i2cWrite(file_acc, 0x1e, ucTemp, 1);
  200.         ucTemp[0] = 0x28; // data rate + full scale + bw selection
  201. // bits:        ODR_G2 | ODR_G1 | ODR_G0 | FS_G1 | FS_G0 | 0 | BW_G1 | BW_G0
  202. // 0x28 = 14.9hz, 500dps
  203.         i2cWrite(file_acc, 0x10, ucTemp, 1); // gyro ctrl_reg1
  204.  
  205.         besRETURN_LONG(1);
  206.  
  207. // problems opening the I2C handles/addresses
  208. badexit:
  209. /* TODO
  210.         if (file_led != -1)
  211.         {
  212.                 close(file_led);
  213.                 file_led = -1;
  214.         }
  215. */
  216.         if (file_hum != -1)
  217.         {
  218.                 close(file_hum);
  219.                 file_hum = -1;
  220.         }
  221.         if (file_pres != -1)
  222.         {
  223.                 close(file_pres);
  224.                 file_pres = -1;
  225.         }
  226.         if (file_acc != -1)
  227.         {
  228.                 close(file_acc);
  229.                 file_acc = -1;
  230.         }
  231.         if (file_mag != -1)
  232.         {
  233.                 close(file_mag);
  234.                 file_mag = -1;
  235.         }
  236.   besRETURN_LONG(0);
  237. besEND
  238.  
  239.  
  240. besFUNCTION(shGetAccel)
  241.   int *Ax, *Ay, *Az;
  242.  
  243.   besARGUMENTS("iii")
  244.     &Ax, &Ay, &Az
  245.   besARGEND
  246.  
  247.   unsigned char ucTemp[8];
  248.   int rc;
  249.  
  250.         rc = i2cRead(file_acc, 0x28+0x80, ucTemp, 6);
  251.         if (rc == 6)
  252.         {
  253.                 int x, y, z;
  254.  
  255.                 x = ucTemp[0] + (ucTemp[1] << 8);
  256.                 y = ucTemp[2] + (ucTemp[3] << 8);
  257.                 z = ucTemp[4] + (ucTemp[5] << 8);
  258.                 // fix the signed values
  259.                 if (x > 32767) x -= 65536;
  260.                 if (y > 32767) y -= 65536;
  261.                 if (z > 32767) z -= 65536;
  262.                 *Ax = x; *Ay = y; *Az = z;
  263.                 besRETURN_LONG(1);
  264.         }
  265.         besRETURN_LONG(0);
  266. besEND
  267.  
  268.  
  269. besFUNCTION(shGetGyro)
  270.   int *Gx, *Gy, *Gz;
  271.  
  272.   besARGUMENTS("iii")
  273.     &Gx, &Gy, &Gz
  274.   besARGEND
  275.  
  276.   unsigned char ucTemp[8];
  277.   int rc;
  278.  
  279.         rc = i2cRead(file_acc, 0x18+0x80, ucTemp, 6);
  280.         if (rc == 6)
  281.         {
  282.                 *Gx = ucTemp[0] + (ucTemp[1] << 8);
  283.                 *Gy = ucTemp[2] + (ucTemp[3] << 8);
  284.                 *Gz = ucTemp[4] + (ucTemp[5] << 8);
  285.                 besRETURN_LONG(1);
  286.         }
  287.         besRETURN_LONG(0);
  288. besEND
  289.  
  290.  
  291. besFUNCTION(shGetMagneto)
  292.   int *Mx, *My, *Mz;
  293.  
  294.   besARGUMENTS("iii")
  295.     &Mx, &My, &Mz
  296.   besARGEND
  297.  
  298.   unsigned char ucTemp[8];
  299.   int rc;
  300.  
  301.         rc = i2cRead(file_mag, 0x28+0x80, ucTemp, 6);
  302.         if (rc == 6)
  303.         {
  304.                 int x, y, z;
  305.                 x = ucTemp[0] + (ucTemp[1] << 8);
  306.                 y = ucTemp[2] + (ucTemp[3] << 8);
  307.                 z = ucTemp[4] + (ucTemp[5] << 8);
  308.                 // fix signed values
  309.                 if (x > 32767) x -= 65536;
  310.                 if (y > 32767) y -= 65536;
  311.                 if (z > 32767) z -= 65536;
  312.                 *Mx = z; *My = y; *Mz = z;
  313.                 besRETURN_LONG(1);
  314.         }
  315.         besRETURN_LONG(0);
  316. besEND
  317.  
  318.  
  319. besFUNCTION(shGetTempHumid)
  320.   int *Temp, *Humid;
  321.  
  322.   besARGUMENTS("ii")
  323.     &Temp, &Humid
  324.   besARGEND
  325.  
  326.   unsigned char ucTemp[4];
  327.   int rc;
  328.   int H_T_out, T_out, T0_degC, T1_degC;
  329.   int H0_rh, H1_rh;
  330.   int tmp;
  331.  
  332.         rc = i2cRead(file_hum, 0x28+0x80, ucTemp, 4);
  333.         if (rc == 4)
  334.         {
  335.                 H_T_out = ucTemp[0] + (ucTemp[1] << 8);
  336.                 T_out = ucTemp[2] + (ucTemp[3] << 8);
  337.                 if (H_T_out > 32767) H_T_out -=65536;
  338.                 if (T_out > 32767) T_out -= 65536;
  339.                 T0_degC = T0_degC_x8 / 8;
  340.                 T1_degC = T1_degC_x8 / 8;
  341.                 H0_rh = H0_rH_x2 / 2;
  342.                 H1_rh = H1_rH_x2 / 2;
  343.                 tmp = (H_T_out - H0_T0_OUT) * (H1_rh - H0_rh)*10;
  344.                 *Humid = tmp / (H1_T0_OUT - H0_T0_OUT) + H0_rh*10;
  345.                 tmp = (T_out - T0_OUT) * (T1_degC - T0_degC)*10;
  346.                 *Temp = tmp / (T1_OUT - T0_OUT) + T0_degC*10;
  347.                 besRETURN_LONG(1);
  348.         }
  349.         besRETURN_LONG(0); // not ready
  350. besEND
  351.  
  352.  
  353. besFUNCTION(shShutdown)
  354.         /* TODO Blank the LED array
  355.         memset(LEDArray, 0, sizeof(LEDArray));
  356.         i2cWrite(file_led, 0, LEDArray, 192);
  357.   */
  358.  
  359.         // Close all I2C file handles
  360. // TODO if (file_led != -1) close(file_led);
  361.         if (file_hum != -1) close(file_hum);
  362.         if (file_pres != -1) close(file_pres);
  363.         if (file_acc != -1) close(file_acc);
  364.         if (file_mag != -1) close(file_mag);
  365.         file_led = file_hum = file_pres = file_acc = file_mag = -1;
  366. besEND
  367.  
  368.  
  369. besFUNCTION(shReadJoystick)
  370.   unsigned char ucBuf[2];
  371.   int rc;
  372.  
  373.         if (file_led != -1)
  374.         {
  375.                 rc = i2cRead(file_led, 0xf2, ucBuf, 1);
  376.                 if (rc == 1)
  377.                         besRETURN_STRING(ucBuf[0]);
  378.         }
  379.   besRETURN_LONG(0);
  380. besEND
  381.  

Here is library I'm using.

Sense HAT Unchained

Here is the results I get using the demo script.

pi@RPi3B:~/sbrpi/shat/sense_hat_unchained-master $ ./sensedemo
keys = 00
T=367, H=278
P=1023, T=359
accX=-722, accY=3044, accZ=-722

« Last Edit: April 26, 2019, 12:07:39 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3512
    • ScriptBasic Open Source Project
Re: SB π
« Reply #193 on: April 26, 2019, 01:36:00 PM »
AIR,

I tried the lval method but no luck and still getting the same error.

Code: C
  1. besFUNCTION(shGetTempHumid)
  2.   VARIABLE Argument1;
  3.   VARIABLE Argument2;
  4.   unsigned long __refcount_;
  5.   LEFTVALUE Lval1;
  6.   LEFTVALUE Lval2;
  7.  
  8. //  int *Temp, *Humid;
  9. //  besARGUMENTS("ii")
  10. //    &Temp, &Humid
  11. //  besARGEND
  12.  
  13.   Argument1 = besARGUMENT(1);
  14.   besLEFTVALUE(Argument1,Lval1);
  15.   besRELEASE(*Lval1);
  16.   *Lval1 = NULL;
  17.  
  18.   Argument2 = besARGUMENT(2);
  19.   besLEFTVALUE(Argument2,Lval2);
  20.   besRELEASE(*Lval2);
  21.   *Lval2 = NULL;
  22.  
  23.   unsigned char ucTemp[4];
  24.   int rc;
  25.   int H_T_out, T_out, T0_degC, T1_degC;
  26.   int H0_rh, H1_rh;
  27.   int tmp;
  28.  
  29.         rc = i2cRead(file_hum, 0x28+0x80, ucTemp, 4);
  30.         if (rc == 4)
  31.         {
  32.                 H_T_out = ucTemp[0] + (ucTemp[1] << 8);
  33.                 T_out = ucTemp[2] + (ucTemp[3] << 8);
  34.                 if (H_T_out > 32767) H_T_out -=65536;
  35.                 if (T_out > 32767) T_out -= 65536;
  36.                 T0_degC = T0_degC_x8 / 8;
  37.                 T1_degC = T1_degC_x8 / 8;
  38.                 H0_rh = H0_rH_x2 / 2;
  39.                 H1_rh = H1_rH_x2 / 2;
  40.                 tmp = (H_T_out - H0_T0_OUT) * (H1_rh - H0_rh)*10;
  41. //  *Humid = tmp / (H1_T0_OUT - H0_T0_OUT) + H0_rh*10;
  42.     LONGVALUE(*Lval2) = tmp / (H1_T0_OUT - H0_T0_OUT) + H0_rh*10;
  43.                 tmp = (T_out - T0_OUT) * (T1_degC - T0_degC)*10;
  44. //  *Temp = tmp / (T1_OUT - T0_OUT) + T0_degC*10;
  45.     LONGVALUE(*Lval1) = tmp / (T1_OUT - T0_OUT) + T0_degC*10;
  46.                 besRETURN_LONG(1);
  47.         }
  48.         besRETURN_LONG(0); // not ready
  49. besEND
  50.  


pi@RPi3B:~/sbrpi/examples $ scriba testhat.sb
scriba: symbol lookup error: /home/pi/sbrpi/modules/shat.so: undefined symbol: __aeabi_idiv
pi@RPi3B:~/sbrpi/examples $

« Last Edit: April 26, 2019, 01:37:33 PM by John »

Offline AIR

  • BASIC Developer
  • Posts: 932
  • Coder
Re: SB π
« Reply #194 on: April 26, 2019, 01:38:28 PM »


pi@RPi3B:~/sbrpi/examples
scriba: symbol lookup error: /home/pi/sbrpi/modules/shat.so: undefined symbol: __aeabi_idiv

IF this path exists:  /usr/lib/gcc/arm-linux-gnueabihf/6/libgcc.a
Try linking that file.