<commit_before>/*  Copyright 2013, <NAME>
    Author email:  <<EMAIL>>
    Project home:  <https://github.com/galaktor/gorf24>
    Licensed under The MIT License (see README and LICENSE files)

    Updated to RF24 v.13
    2017, <NAME>, <NAME>
    Authors email:  <<EMAIL>>, <<EMAIL>>
    Project home:  <https://github.com/mariusstaicu/gorf24>
*/
package gorf24

/*
  #cgo LDFLAGS: -L./RF24_c
  #cgo LDFLAGS: -lrf24_c
  #cgo CFLAGS: -I./RF24_c
  #include "RF24_c.h"
  #include <stdio.h>
*/
import "C"
import (
	// "encoding/binary"
	// "fmt"
	"unsafe"
)

type LibRF24 interface {
	Delete()
	Begin()
	IsChipConnected() bool
	StartListening()
	StopListening()
	Available() bool
	Read(length uint8) ([]byte, bool)
	OpenWritingPipeDeprecated(address uint64)
	OpenReadingPipeDeprecated(pipe uint8, address uint64)
	OpenWritingPipe(address *uint8)
	OpenReadingPipe(pipe uint8, address *uint8)
	Write(data []byte, length uint8) bool
	PrintDetails()
	AvailablePipe() (bool, uint8)
	IsRxFifoFull() bool
	PowerDown()
	PowerUp()
	WriteMulticast(data []byte, length uint8, multicast bool) bool
	WriteFast(data []byte, length uint8) bool
	WriteFastMulticast(data []byte, length uint8, multicast bool) bool
	WriteBlocking(data []byte, length uint8, timeout uint32) bool
	IsTxStandBy() bool
	IsTxStandByExtended(timeout uint32, startTx bool) bool
	WriteAckPayload(pipe uint8, data []byte, length uint8)
	IsAckPayloadAvailable() bool
	WhatHappened() (tx_ok, tx_fail, rx_ready bool)
	StartWrite(data []byte, length uint8, multicast bool)
	StartFastWrite(data []byte, length uint8, multicast bool, startTx bool)
	ReUseTx()
	FlushTx() uint8
	TestCarrier() bool
	TestRPD() bool
	CloseReadingPipe(pipe uint8)
	SetAddressWidth(width uint8)
	SetRetries(delay uint8, count uint8)
	SetChannel(channel uint8)
	GetChannel(channel uint8) uint8
	SetPayloadSize(size uint8)
	GetPayloadSize() uint8
	GetDynamicPayloadSize() uint8
	EnableAckPayload()
	EnableDynamicPayloads()
	DisableDynamicPayloads()
	EnableDynamicAck()
	IsPVariant() bool
	SetAutoAck(enable bool)
	SetAutoAckPipe(pipe uint8, enable bool)
	SetPALevel(level PA_DBM)
	GetPALevel() PA_DBM
	SetDataRate(rate DATARATE)
	GetDataRate() DATARATE
	SetCRCLength(length CRCLENGTH)
	GetCRCLength() CRCLENGTH
	DisableCRC()
	MaskIRQ(txOk, txFail, rxReady bool)
}

// TODO: more idiomatic:
//   error handling
//   Read/Write interfaces
//   possibly more conventional byte slice passing
//   more type safety?
//   channel for available data, like time.Tick? r.Available() <-chan []byte  or so?
type RF24 struct {
	cptr        C.RF24Handle
	buffer_size uint8
	buffer      []byte
}

/*
func main() {
	var pipe uint64 = 0xF0F0F0F0E1
	r := New(25, 8, 32)
	defer r.Delete()
	r.Begin()
	r.SetRetries(15, 15)
	r.SetAutoAck(true)
	r.OpenReadingPipe(1, pipe)
	r.StartListening()
	r.PrintDetails()
	for {
		if r.Available() {
			data, _ := r.Read(4)
//			fmt.Printf("data: %v\n", data)
			payload := binary.LittleEndian.Uint32(data)
			fmt.Printf("Received %v\n", payload)
		} else {
			//
		}
	}
}
*/
func New(cepin uint8, cspin uint8, spispeed uint32) *RF24 {
	var r RF24
	r.cptr = C.new_rf24(C.uint8_t(cepin), C.uint8_t(cspin), C.uint32_t(spispeed))
	r.buffer = make([]byte, 128) // max payload length according to nrf24 spec
	return &r
}

func (r *RF24) Delete() {
	C.rf24_delete(r.cptr)
	r.cptr = nil
}
func (r *RF24) Begin() {
	C.rf24_begin(r.cptr)
}

func (r *RF24) IsChipConnected() bool {
	return gobool(C.rf24_isChipConnected(r.cptr))
}

func (r *RF24) StartListening() {
	C.rf24_startListening(r.cptr)
}

func (r *RF24) StopListening() {
	C.rf24_stopListening(r.cptr)
}

func (r *RF24) Available() bool {
	return gobool(C.rf24_available(r.cptr))
}

func (r *RF24) Read(length uint8) ([]byte, bool) {
	ok := gobool(C.rf24_read(r.cptr, unsafe.Pointer(&r.buffer[0]), C.uint8_t(length)))
	return r.buffer[:length], ok
}

func (r *RF24) OpenWritingPipe(address *uint8) {
	C.rf24_openWritingPipe(r.cptr, address)
}

func (r *RF24) OpenWritingPipeDeprecated(address uint64) {
	C.rf24_openWritingPipeDeprecated(r.cptr, C.uint64_t(address))
}

func (r *RF24) OpenReadingPipe(pipe uint8, address *uint8) {
	C.rf24_openReadingPipe(r.cptr, C.uint8_t(pipe), address)
}

func (r *RF24) OpenReadingPipeDeprecated(pipe uint8, address uint64) {
	C.rf24_openReadingPipeDeprecated(r.cptr, C.uint8_t(pipe), C.uint64_t(address))
}<commit_msg>trying to fix compiling issue 2<commit_after>/*  Copyright 2013, <NAME>
    Author email:  <<EMAIL>>
    Project home:  <https://github.com/galaktor/gorf24>
    Licensed under The MIT License (see README and LICENSE files)

    Updated to RF24 v.13
    2017, <NAME>, <NAME>
    Authors email:  <<EMAIL>>, <<EMAIL>>
    Project home:  <https://github.com/mariusstaicu/gorf24>
*/
package gorf24

/*
  #cgo LDFLAGS: -L./RF24_c
  #cgo LDFLAGS: -lrf24_c
  #cgo CFLAGS: -I./RF24_c
  #include "RF24_c.h"
  #include <stdio.h>
*/
import "C"
import (
	// "encoding/binary"
	// "fmt"
	"unsafe"
)

type LibRF24 interface {
	Delete()
	Begin()
	IsChipConnected() bool
	StartListening()
	StopListening()
	Available() bool
	Read(length uint8) ([]byte, bool)
	OpenWritingPipeDeprecated(address uint64)
	OpenReadingPipeDeprecated(pipe uint8, address uint64)
	OpenWritingPipe(address []uint8)
	OpenReadingPipe(pipe uint8, address []uint8)
	Write(data []byte, length uint8) bool
	PrintDetails()
	AvailablePipe() (bool, uint8)
	IsRxFifoFull() bool
	PowerDown()
	PowerUp()
	WriteMulticast(data []byte, length uint8, multicast bool) bool
	WriteFast(data []byte, length uint8) bool
	WriteFastMulticast(data []byte, length uint8, multicast bool) bool
	WriteBlocking(data []byte, length uint8, timeout uint32) bool
	IsTxStandBy() bool
	IsTxStandByExtended(timeout uint32, startTx bool) bool
	WriteAckPayload(pipe uint8, data []byte, length uint8)
	IsAckPayloadAvailable() bool
	WhatHappened() (tx_ok, tx_fail, rx_ready bool)
	StartWrite(data []byte, length uint8, multicast bool)
	StartFastWrite(data []byte, length uint8, multicast bool, startTx bool)
	ReUseTx()
	FlushTx() uint8
	TestCarrier() bool
	TestRPD() bool
	CloseReadingPipe(pipe uint8)
	SetAddressWidth(width uint8)
	SetRetries(delay uint8, count uint8)
	SetChannel(channel uint8)
	GetChannel(channel uint8) uint8
	SetPayloadSize(size uint8)
	GetPayloadSize() uint8
	GetDynamicPayloadSize() uint8
	EnableAckPayload()
	EnableDynamicPayloads()
	DisableDynamicPayloads()
	EnableDynamicAck()
	IsPVariant() bool
	SetAutoAck(enable bool)
	SetAutoAckPipe(pipe uint8, enable bool)
	SetPALevel(level PA_DBM)
	GetPALevel() PA_DBM
	SetDataRate(rate DATARATE)
	GetDataRate() DATARATE
	SetCRCLength(length CRCLENGTH)
	GetCRCLength() CRCLENGTH
	DisableCRC()
	MaskIRQ(txOk, txFail, rxReady bool)
}

// TODO: more idiomatic:
//   error handling
//   Read/Write interfaces
//   possibly more conventional byte slice passing
//   more type safety?
//   channel for available data, like time.Tick? r.Available() <-chan []byte  or so?
type RF24 struct {
	cptr        C.RF24Handle
	buffer_size uint8
	buffer      []byte
}

/*
func main() {
	var pipe uint64 = 0xF0F0F0F0E1
	r := New(25, 8, 32)
	defer r.Delete()
	r.Begin()
	r.SetRetries(15, 15)
	r.SetAutoAck(true)
	r.OpenReadingPipe(1, pipe)
	r.StartListening()
	r.PrintDetails()
	for {
		if r.Available() {
			data, _ := r.Read(4)
//			fmt.Printf("data: %v\n", data)
			payload := binary.LittleEndian.Uint32(data)
			fmt.Printf("Received %v\n", payload)
		} else {
			//
		}
	}
}
*/
func New(cepin uint8, cspin uint8, spispeed uint32) *RF24 {
	var r RF24
	r.cptr = C.new_rf24(C.uint8_t(cepin), C.uint8_t(cspin), C.uint32_t(spispeed))
	r.buffer = make([]byte, 128) // max payload length according to nrf24 spec
	return &r
}

func (r *RF24) Delete() {
	C.rf24_delete(r.cptr)
	r.cptr = nil
}
func (r *RF24) Begin() {
	C.rf24_begin(r.cptr)
}

func (r *RF24) IsChipConnected() bool {
	return gobool(C.rf24_isChipConnected(r.cptr))
}

func (r *RF24) StartListening() {
	C.rf24_startListening(r.cptr)
}

func (r *RF24) StopListening() {
	C.rf24_stopListening(r.cptr)
}

func (r *RF24) Available() bool {
	return gobool(C.rf24_available(r.cptr))
}

func (r *RF24) Read(length uint8) ([]byte, bool) {
	ok := gobool(C.rf24_read(r.cptr, unsafe.Pointer(&r.buffer[0]), C.uint8_t(length)))
	return r.buffer[:length], ok
}

func (r *RF24) OpenWritingPipe(address []uint8) {
	C.rf24_openWritingPipe(r.cptr, unsafe.Pointer(&address[0]))
}

func (r *RF24) OpenWritingPipeDeprecated(address uint64) {
	C.rf24_openWritingPipeDeprecated(r.cptr, C.uint64_t(address))
}

func (r *RF24) OpenReadingPipe(pipe uint8, address []uint8) {
	C.rf24_openReadingPipe(r.cptr, C.uint8_t(pipe),unsafe.Pointer(&address[0]))
}


func (r *RF24) OpenReadingPipeDeprecated(pipe uint8, address uint64) {
	C.rf24_openReadingPipeDeprecated(r.cptr, C.uint8_t(pipe), C.uint64_t(address))
}
{'fraction_non_alphanumeric': 0.13342472012794152, 'fraction_numerical': 0.03895362120173635, 'mean_word_length': 4.8134130146082335, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6209432', 'n_tokens_mistral': 3661, 'n_tokens_neox': 3425, 'n_words': 786}