<commit_before>//
// Created by sokkalf on 3/6/16.
//

#include "oled-control.h"
#include <ruby.h>


static VALUE set_cursor(VALUE self, VALUE col, VALUE row) {
    uint8_t c = NUM2UINT(col);
    uint8_t r = NUM2UINT(row);

    if(!set_cursor_position(c, r))
        rb_raise(rb_eRuntimeError, "unable to set cursor position");

    return Qtrue;
}

static VALUE write_string(VALUE self, VALUE str) {
    VALUE the_string = StringValue(str);
    const char *s = RSTRING_PTR(the_string);
    if(!i2c_write_bytes(DATA, s))
        rb_raise(rb_eRuntimeError, "unable to write string to display");

    return Qtrue;
}

static VALUE init(VALUE self, VALUE i2cbus, VALUE i2caddress) {
    VALUE the_string = StringValue(i2cbus);
    const char *bus = RSTRING_PTR(the_string);
    uint8_t a = NUM2UINT(i2caddress);

    if(!configure_display(bus, a))
        rb_raise(rb_eRuntimeError, "can't detect display! Bus/address wrong?");

    if(!init_display())
        rb_raise(rb_eRuntimeError, "failure initializing display");

    return Qtrue;
}

void Init_oled_control(void) {
    VALUE klass = rb_define_class("OLED", rb_cObject);

    rb_define_method(klass, "set_cursor", set_cursor, 2);
    rb_define_protected_method(klass, "write_string", write_string, 1);
    rb_define_protected_method(klass, "init", init, 2);
}<commit_msg>Expose clear_display in rubygem<commit_after>//
// Created by sokkalf on 3/6/16.
//

#include "oled-control.h"
#include <ruby.h>


static VALUE set_cursor(VALUE self, VALUE col, VALUE row) {
    uint8_t c = NUM2UINT(col);
    uint8_t r = NUM2UINT(row);

    if(!set_cursor_position(c, r))
        rb_raise(rb_eRuntimeError, "unable to set cursor position");

    return Qtrue;
}

static VALUE write_string(VALUE self, VALUE str) {
    VALUE the_string = StringValue(str);
    const char *s = RSTRING_PTR(the_string);
    if(!i2c_write_bytes(DATA, s))
        rb_raise(rb_eRuntimeError, "unable to write string to display");

    return Qtrue;
}

static VALUE init(VALUE self, VALUE i2cbus, VALUE i2caddress) {
    VALUE the_string = StringValue(i2cbus);
    const char *bus = RSTRING_PTR(the_string);
    uint8_t a = NUM2UINT(i2caddress);

    if(!configure_display(bus, a))
        rb_raise(rb_eRuntimeError, "can't detect display! Bus/address wrong?");

    if(!init_display())
        rb_raise(rb_eRuntimeError, "failure initializing display");

    return Qtrue;
}

static VALUE clear(VALUE self) {
    if(!clear_display())
        rb_raise(rb_eRuntimeError, "failure clearing display");

    return Qtrue;
}

void Init_oled_control(void) {
    VALUE klass = rb_define_class("OLED", rb_cObject);

    rb_define_method(klass, "set_cursor", set_cursor, 2);
    rb_define_method(klass, "clear", clear, 0);
    rb_define_protected_method(klass, "write_string", write_string, 1);
    rb_define_protected_method(klass, "init", init, 2);
}
{'fraction_non_alphanumeric': 0.11809923130677848, 'fraction_numerical': 0.012928022361984625, 'mean_word_length': 4.158558558558559, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '347350', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1011, 'n_words': 236}